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
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.
176 177 178 179 |
# File 'lib/geometry/square.rb', line 176 def initialize(origin, size) @origin = Point[origin] @size = size end |
Instance Attribute Details
#center ⇒ Object
184 185 186 |
# File 'lib/geometry/square.rb', line 184 def center origin + size/2 end |
#origin ⇒ Point (readonly)
Returns The lower left corner.
200 201 202 |
# File 'lib/geometry/square.rb', line 200 def origin @origin end |
#points ⇒ Array<Point> (readonly)
Returns The Geometry::Square‘s four points (counterclockwise).
206 207 208 209 210 211 212 213 |
# File 'lib/geometry/square.rb', line 206 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.
172 173 174 |
# File 'lib/geometry/square.rb', line 172 def size @size end |
Instance Method Details
#height ⇒ Number
Returns The size of the Geometry::Square along the y-axis.
216 217 218 |
# File 'lib/geometry/square.rb', line 216 def height @size end |
#max ⇒ Point
Returns The upper right corner of the bounding Rectangle.
189 190 191 |
# File 'lib/geometry/square.rb', line 189 def max origin + size end |
#min ⇒ Point
Returns The lower left corner of the bounding Rectangle.
194 195 196 |
# File 'lib/geometry/square.rb', line 194 def min origin end |
#width ⇒ Number
Returns The size of the Geometry::Square along the x-axis.
221 222 223 |
# File 'lib/geometry/square.rb', line 221 def width @size end |