Class: Geometry::CenteredSquare
- Defined in:
- lib/aurora-geometry/square.rb
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.
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.
70 71 72 73 |
# File 'lib/aurora-geometry/square.rb', line 70 def initialize(center, size) @center = Point[center] @size = size end |
Instance Attribute Details
#center ⇒ Point (readonly)
Returns The center of the Square.
66 67 68 |
# File 'lib/aurora-geometry/square.rb', line 66 def center @center end |
#origin ⇒ Point (readonly)
Returns The lower left corner.
78 79 80 |
# File 'lib/aurora-geometry/square.rb', line 78 def origin Point[@center.x - size/2, @center.y - size/2] end |
#points ⇒ Array<Point> (readonly)
Returns The Square‘s four points (counterclockwise).
84 85 86 87 88 89 90 91 92 |
# File 'lib/aurora-geometry/square.rb', line 84 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
94 95 96 |
# File 'lib/aurora-geometry/square.rb', line 94 def height @size end |
#width ⇒ Object
98 99 100 |
# File 'lib/aurora-geometry/square.rb', line 98 def width @size end |