Class: Geometry::SizedSquare
Overview
A Square created with an origin point and a size
Accessors collapse
- #center ⇒ Object
-
#origin ⇒ Point
readonly
The lower left corner.
-
#points ⇒ Array<Point>
readonly
The Square‘s four points (counterclockwise).
Instance Attribute Summary collapse
Attributes inherited from Square
Accessors collapse
-
#height ⇒ Number
The size of the Square along the y-axis.
-
#max ⇒ Point
The upper right corner of the bounding Rectangle.
-
#min ⇒ Point
The lower left corner of the bounding Rectangle.
-
#width ⇒ Number
The size of the Square along the x-axis.
Instance Method Summary collapse
-
#initialize(origin, size) ⇒ SizedSquare
constructor
A new instance of SizedSquare.
Methods inherited from Square
Methods included from ClusterFactory
Constructor Details
#initialize(origin, size) ⇒ SizedSquare
Returns a new instance of SizedSquare.
182 183 184 185 |
# File 'lib/geometry/square.rb', line 182 def initialize(origin, size) @origin = Point[origin] @size = size end |
Instance Attribute Details
#center ⇒ Object
190 191 192 |
# File 'lib/geometry/square.rb', line 190 def center origin + size/2 end |
#origin ⇒ Point (readonly)
Returns The lower left corner.
206 207 208 |
# File 'lib/geometry/square.rb', line 206 def origin @origin end |
#points ⇒ Array<Point> (readonly)
Returns The Geometry::Square‘s four points (counterclockwise).
212 213 214 215 216 217 218 219 |
# File 'lib/geometry/square.rb', line 212 def points minx = origin.x maxx = origin.x + size miny = origin.y maxy = origin.y + size [origin, Point[maxx, miny], Point[maxx, maxy], Point[minx,maxy]] end |
#size ⇒ Size
Returns The Geometry::Size of the Geometry::Square.
178 179 180 |
# File 'lib/geometry/square.rb', line 178 def size @size end |
Instance Method Details
#height ⇒ Number
Returns The size of the Geometry::Square along the y-axis.
222 223 224 |
# File 'lib/geometry/square.rb', line 222 def height @size end |
#max ⇒ Point
Returns The upper right corner of the bounding Rectangle.
195 196 197 |
# File 'lib/geometry/square.rb', line 195 def max origin + size end |
#min ⇒ Point
Returns The lower left corner of the bounding Rectangle.
200 201 202 |
# File 'lib/geometry/square.rb', line 200 def min origin end |
#width ⇒ Number
Returns The size of the Geometry::Square along the x-axis.
227 228 229 |
# File 'lib/geometry/square.rb', line 227 def width @size end |