class Geom2D::BoundingBox
Represents an axis aligned bounding box.
An empty bounding box contains just the point at origin.
Attributes
max_x[R]
The maximum x-coordinate.
max_y[R]
The maximum y-coordinate.
min_x[R]
The minimum x-coordinate.
min_y[R]
The minimum y-coordinate.
Public Class Methods
new(min_x = 0, min_y = 0, max_x = 0, max_y = 0)
click to toggle source
Creates a new BoundingBox
.
# File lib/geom2d/bounding_box.rb, line 30 def initialize(min_x = 0, min_y = 0, max_x = 0, max_y = 0) @min_x = min_x @min_y = min_y @max_x = max_x @max_y = max_y end
Public Instance Methods
add(other)
click to toggle source
Returns a bounding box containing this bounding box and the argument.
# File lib/geom2d/bounding_box.rb, line 67 def add(other) dup.add!(other) end
Also aliased as: +
add!(other)
click to toggle source
Updates this bounding box to also contain the given bounding box or point.
# File lib/geom2d/bounding_box.rb, line 38 def add!(other) case other when BoundingBox @min_x = [min_x, other.min_x].min @min_y = [min_y, other.min_y].min @max_x = [max_x, other.max_x].max @max_y = [max_y, other.max_y].max when Point @min_x = [min_x, other.x].min @min_y = [min_y, other.y].min @max_x = [max_x, other.x].max @max_y = [max_y, other.y].max else raise ArgumentError, "Can only use another BoundingBox or Point" end self end
height()
click to toggle source
Returns the height of the bounding box.
# File lib/geom2d/bounding_box.rb, line 62 def height @max_y - @min_y end
to_a()
click to toggle source
width()
click to toggle source
Returns the width of the bounding box.
# File lib/geom2d/bounding_box.rb, line 57 def width @max_x - @min_x end