Class: Nimo::Intersection
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #collistion_side_for(obj) ⇒ Object
-
#initialize(x, y, width, height) ⇒ Intersection
constructor
A new instance of Intersection.
Constructor Details
#initialize(x, y, width, height) ⇒ Intersection
Returns a new instance of Intersection.
6 7 8 9 10 11 |
# File 'lib/nimo/utils/intersection.rb', line 6 def initialize(x, y, width, height) @x = x @y = y @width = width @height = height end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
4 5 6 |
# File 'lib/nimo/utils/intersection.rb', line 4 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
4 5 6 |
# File 'lib/nimo/utils/intersection.rb', line 4 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
4 5 6 |
# File 'lib/nimo/utils/intersection.rb', line 4 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
4 5 6 |
# File 'lib/nimo/utils/intersection.rb', line 4 def y @y end |
Class Method Details
.between(obj1, obj2) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/nimo/utils/intersection.rb', line 13 def self.between(obj1, obj2) x = [obj1.x, obj2.x].max y = [obj1.y, obj2.y].max width = [obj1.x + obj1.width, obj2.x + obj2.width].min - x height = [obj1.y + obj1.height, obj2.y + obj2.height].min - y return Intersection.new(x, y, width, height) end |
Instance Method Details
#collistion_side_for(obj) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/nimo/utils/intersection.rb', line 21 def collistion_side_for(obj) if @width >= @height return obj.center.y > (@y + (@height/2)) ? :top : :bottom else return obj.center.x > (@x + (@width/2)) ? :left : :right end end |