Method: Geometry::Square#initialize
- Defined in:
- lib/geometry/square.rb
#initialize(options = {}) ⇒ Square
Creates a Geometry::Square given two Points
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/geometry/square.rb', line 53 def initialize(={}) origin = [:from] || [:origin] origin = origin ? Point[origin] : PointZero.new if .has_key? :to point1 = [:to] end point1 = Point[point1] raise(ArgumentError, "Point sizes must match (#{origin.size} != #{point1.size})") unless origin.is_a?(PointZero) || (origin.size == point1.size) # Reorder the points to get lower-left and upper-right minx, maxx = [origin.x, point1.x].minmax miny, maxy = [origin.y, point1.y].minmax @points = [Point[minx, miny], Point[maxx, maxy]] raise(NotSquareError) if height != width end |