Class: Quadtree::AxisAlignedBoundingBox
- Inherits:
-
Object
- Object
- Quadtree::AxisAlignedBoundingBox
- Defined in:
- lib/quadtree/axis_aligned_bounding_box.rb
Overview
Axis-aligned bounding box with half dimension and center.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#bottom ⇒ Float
Get the Y coordinate of the bottom edge of this AABB.
- #contains_point?(point) ⇒ Boolean
- #height ⇒ Float
-
#initialize(center, half_dimension) ⇒ AxisAlignedBoundingBox
constructor
A new instance of AxisAlignedBoundingBox.
- #intersects?(other) ⇒ Boolean
- #left ⇒ Float
- #right ⇒ Float
-
#top ⇒ Float
Get the Y coordinate of the top edge of this AABB.
- #width ⇒ Float
Constructor Details
#initialize(center, half_dimension) ⇒ AxisAlignedBoundingBox
Returns a new instance of AxisAlignedBoundingBox.
12 13 14 15 |
# File 'lib/quadtree/axis_aligned_bounding_box.rb', line 12 def initialize(center, half_dimension) @center = center @half_dimension = half_dimension.to_f end |
Instance Attribute Details
#center ⇒ Point
6 7 8 |
# File 'lib/quadtree/axis_aligned_bounding_box.rb', line 6 def center @center end |
#half_dimension ⇒ Float
8 9 10 |
# File 'lib/quadtree/axis_aligned_bounding_box.rb', line 8 def half_dimension @half_dimension end |
Instance Method Details
#bottom ⇒ Float
Get the Y coordinate of the bottom edge of this AABB.
62 63 64 |
# File 'lib/quadtree/axis_aligned_bounding_box.rb', line 62 def bottom @center.y - @half_dimension end |
#contains_point?(point) ⇒ Boolean
19 20 21 22 23 24 25 26 |
# File 'lib/quadtree/axis_aligned_bounding_box.rb', line 19 def contains_point?(point) if point.x >= self.center.x - self.half_dimension and point.x <= self.center.x + self.half_dimension if point.y >= self.center.y - self.half_dimension and point.y <= self.center.y + self.half_dimension return true end end false end |
#height ⇒ Float
72 73 74 |
# File 'lib/quadtree/axis_aligned_bounding_box.rb', line 72 def height span end |
#intersects?(other) ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/quadtree/axis_aligned_bounding_box.rb', line 30 def intersects?(other) other_lt_corner = Point.new(other.left, other.top) other_rt_corner = Point.new(other.right, other.top) other_lb_corner = Point.new(other.left, other.bottom) other_rb_corner = Point.new(other.right, other.bottom) [other_lt_corner, other_rt_corner, other_lb_corner, other_rb_corner].each do |corner| return true if self.contains_point?(corner) end false end |
#left ⇒ Float
43 44 45 |
# File 'lib/quadtree/axis_aligned_bounding_box.rb', line 43 def left @center.x - @half_dimension end |
#right ⇒ Float
48 49 50 |
# File 'lib/quadtree/axis_aligned_bounding_box.rb', line 48 def right @center.x + @half_dimension end |
#top ⇒ Float
Get the Y coordinate of the top edge of this AABB.
55 56 57 |
# File 'lib/quadtree/axis_aligned_bounding_box.rb', line 55 def top @center.y + @half_dimension end |
#width ⇒ Float
67 68 69 |
# File 'lib/quadtree/axis_aligned_bounding_box.rb', line 67 def width span end |