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.
- #size ⇒ Size
Attributes inherited from Square
Accessors collapse
- #height ⇒ Object
-
#max ⇒ Point
The upper right corner of the bounding Rectangle.
-
#min ⇒ Point
The lower left corner of the bounding Rectangle.
-
#minmax ⇒ Array<Point>
The lower left and upper right corners of the bounding Rectangle.
- #width ⇒ Object
Instance Method Summary collapse
-
#initialize(center, size) ⇒ CenteredSquare
constructor
A new instance of CenteredSquare.
Methods inherited from Square
Methods included from ClusterFactory
Constructor Details
#initialize(center, size) ⇒ CenteredSquare
Returns a new instance of CenteredSquare.
123 124 125 126 |
# File 'lib/geometry/square.rb', line 123 def initialize(center, size) @center = Point[center] @size = size end |
Instance Attribute Details
#center ⇒ Point (readonly)
Returns The center of the Square.
115 116 117 |
# File 'lib/geometry/square.rb', line 115 def center @center end |
#origin ⇒ Point (readonly)
Returns The lower left corner.
148 149 150 |
# File 'lib/geometry/square.rb', line 148 def origin Point[@center.x - size/2, @center.y - size/2] end |
#points ⇒ Array<Point> (readonly)
Returns The Square‘s four points (counterclockwise).
154 155 156 157 158 159 160 161 162 |
# File 'lib/geometry/square.rb', line 154 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
164 165 166 |
# File 'lib/geometry/square.rb', line 164 def height @size end |
#max ⇒ Point
Returns The upper right corner of the bounding Rectangle.
130 131 132 133 |
# File 'lib/geometry/square.rb', line 130 def max half_size = @size/2 Point[@center.x + half_size, @center.y + half_size] end |
#min ⇒ Point
Returns The lower left corner of the bounding Rectangle.
136 137 138 139 |
# File 'lib/geometry/square.rb', line 136 def min half_size = @size/2 Point[@center.x - half_size, @center.y - half_size] end |
#minmax ⇒ Array<Point>
Returns The lower left and upper right corners of the bounding Rectangle.
142 143 144 |
# File 'lib/geometry/square.rb', line 142 def minmax [self.min, self.max] end |
#width ⇒ Object
168 169 170 |
# File 'lib/geometry/square.rb', line 168 def width @size end |