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 (clockwise).
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
#minmax, new, #path, #vertices
Methods included from ClusterFactory
Constructor Details
#initialize(origin, size) ⇒ SizedSquare
Returns a new instance of SizedSquare.
200 201 202 203 |
# File 'lib/geometry/square.rb', line 200 def initialize(origin, size) @origin = Point[origin] @size = size end |
Instance Attribute Details
#center ⇒ Object
208 209 210 |
# File 'lib/geometry/square.rb', line 208 def center origin + size/2 end |
#origin ⇒ Point (readonly)
Returns The lower left corner.
224 225 226 |
# File 'lib/geometry/square.rb', line 224 def origin @origin end |
#points ⇒ Array<Point> (readonly)
Returns The Geometry::Square‘s four points (clockwise).
230 231 232 233 234 235 236 237 |
# File 'lib/geometry/square.rb', line 230 def points minx = origin.x maxx = origin.x + size miny = origin.y maxy = origin.y + size [origin, Point[minx, maxy], Point[maxx, maxy], Point[maxx,miny]] end |
#size ⇒ Size
Returns The Geometry::Size of the Geometry::Square.
196 197 198 |
# File 'lib/geometry/square.rb', line 196 def size @size end |
Instance Method Details
#height ⇒ Number
Returns The size of the Geometry::Square along the y-axis.
240 241 242 |
# File 'lib/geometry/square.rb', line 240 def height @size end |
#max ⇒ Point
Returns The upper right corner of the bounding Rectangle.
213 214 215 |
# File 'lib/geometry/square.rb', line 213 def max origin + size end |
#min ⇒ Point
Returns The lower left corner of the bounding Rectangle.
218 219 220 |
# File 'lib/geometry/square.rb', line 218 def min origin end |
#width ⇒ Number
Returns The size of the Geometry::Square along the x-axis.
245 246 247 |
# File 'lib/geometry/square.rb', line 245 def width @size end |