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.
198 199 200 201 |
# File 'lib/geometry/square.rb', line 198 def initialize(origin, size) @origin = Point[origin] @size = size end |
Instance Attribute Details
#center ⇒ Object
206 207 208 |
# File 'lib/geometry/square.rb', line 206 def center origin + size/2 end |
#origin ⇒ Point (readonly)
Returns The lower left corner.
222 223 224 |
# File 'lib/geometry/square.rb', line 222 def origin @origin end |
#points ⇒ Array<Point> (readonly)
Returns The Geometry::Square‘s four points (counterclockwise).
228 229 230 231 232 233 234 235 |
# File 'lib/geometry/square.rb', line 228 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.
194 195 196 |
# File 'lib/geometry/square.rb', line 194 def size @size end |
Instance Method Details
#height ⇒ Number
Returns The size of the Geometry::Square along the y-axis.
238 239 240 |
# File 'lib/geometry/square.rb', line 238 def height @size end |
#max ⇒ Point
Returns The upper right corner of the bounding Rectangle.
211 212 213 |
# File 'lib/geometry/square.rb', line 211 def max origin + size end |
#min ⇒ Point
Returns The lower left corner of the bounding Rectangle.
216 217 218 |
# File 'lib/geometry/square.rb', line 216 def min origin end |
#width ⇒ Number
Returns The size of the Geometry::Square along the x-axis.
243 244 245 |
# File 'lib/geometry/square.rb', line 243 def width @size end |