Method: Geometry::Rectangle#initialize

Defined in:
lib/geometry/rectangle.rb

#initialize(point0, point1) ⇒ Rectangle

Creates a Geometry::Rectangle using the given Points

@param [Point]	point0	A corner (ie. bottom-left)
@param [Point]	point1	The other corner (ie. top-right)

Raises:

  • (ArgumentError)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/geometry/rectangle.rb', line 91

def initialize(point0, point1)
    point0 = Point[point0]
    point1 = Point[point1]
    raise(ArgumentError, "Point sizes must match") unless point0.size == point1.size

    # Reorder the points to get lower-left and upper-right
    if (point0.x > point1.x) && (point0.y > point1.y)
	point0, point1 = point1, point0
    else
	p0x, p1x = [point0.x, point1.x].minmax
	p0y, p1y = [point0.y, point1.y].minmax
	point0 = Point[p0x, p0y]
	point1 = Point[p1x, p1y]
    end
    @points = [point0, point1]
end