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.
139 140 141 142 |
# File 'lib/geometry/square.rb', line 139 def initialize(center, size) @center = Point[center] @size = size end |
Instance Attribute Details
#center ⇒ Point (readonly)
Returns The center of the Square.
131 132 133 |
# File 'lib/geometry/square.rb', line 131 def center @center end |
#origin ⇒ Point (readonly)
Returns The lower left corner.
164 165 166 |
# File 'lib/geometry/square.rb', line 164 def origin Point[@center.x - size/2, @center.y - size/2] end |
#points ⇒ Array<Point> (readonly)
Returns The Square‘s four points (counterclockwise).
170 171 172 173 174 175 176 177 178 |
# File 'lib/geometry/square.rb', line 170 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
180 181 182 |
# File 'lib/geometry/square.rb', line 180 def height @size end |
#max ⇒ Point
Returns The upper right corner of the bounding Rectangle.
146 147 148 149 |
# File 'lib/geometry/square.rb', line 146 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.
152 153 154 155 |
# File 'lib/geometry/square.rb', line 152 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.
158 159 160 |
# File 'lib/geometry/square.rb', line 158 def minmax [self.min, self.max] end |
#width ⇒ Object
184 185 186 |
# File 'lib/geometry/square.rb', line 184 def width @size end |