Method: Geometry::Square#initialize
- Defined in:
- lib/geometry/square.rb
#initialize(options = {}) ⇒ Square
Creates a Geometry::Square given two Points
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/geometry/square.rb', line 22 def initialize(={}) origin = [:from] || [:origin] origin = origin ? Point[origin] : PointZero.new if .has_key? :to point1 = [:to] elsif .has_key? :size point1 = origin + [:size] 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 |