Class: Geometry::CenteredSquare
Overview
A Square created with a center point and a size
Accessors collapse
-
#origin ⇒ Point
readonly
The lower left corner.
-
#points ⇒ Array<Point>
readonly
The Square‘s four points (counterclockwise).
Instance Attribute Summary collapse
-
#center ⇒ Point
readonly
The center of the Square.
Attributes inherited from Square
Accessors collapse
Instance Method Summary collapse
-
#initialize(center, size) ⇒ CenteredSquare
constructor
A new instance of CenteredSquare.
Constructor Details
#initialize(center, size) ⇒ CenteredSquare
Returns a new instance of CenteredSquare.
75 76 77 78 |
# File 'lib/geometry/square.rb', line 75 def initialize(center, size) @center = Point[center] @size = size end |
Instance Attribute Details
#center ⇒ Point (readonly)
Returns The center of the Square.
71 72 73 |
# File 'lib/geometry/square.rb', line 71 def center @center end |
#origin ⇒ Point (readonly)
Returns The lower left corner.
83 84 85 |
# File 'lib/geometry/square.rb', line 83 def origin Point[@center.x - size/2, @center.y - size/2] end |
#points ⇒ Array<Point> (readonly)
Returns The Square‘s four points (counterclockwise).
89 90 91 92 93 94 95 96 97 |
# File 'lib/geometry/square.rb', line 89 def points half_size = @size/2 minx = @center.x - half_size maxx = @center.x + half_size miny = @center.y - half_size maxy = @center.y + half_size [Point[minx,miny], Point[maxx, miny], Point[maxx, maxy], Point[minx,maxy]] end |
Instance Method Details
#height ⇒ Object
99 100 101 |
# File 'lib/geometry/square.rb', line 99 def height @size end |
#width ⇒ Object
103 104 105 |
# File 'lib/geometry/square.rb', line 103 def width @size end |