A Polygon object is valid if
- it has a minimum of three points
- each Point object in the points collection is valid
Included modules
- Validation
Attributes
| points | [R] | Collection of Point objects. |
Public class methods
new
( attributes = {})
[show source]
# File lib/rcap/cap_1_2/polygon.rb, line 19 def initialize( attributes = {}) @points = Array( attributes[ :points ]) end
Public instance methods
==
( other )
Two polygons are equivalent if their collection of points is equivalent.
[show source]
# File lib/rcap/cap_1_2/polygon.rb, line 49 def ==( other ) self.points == other.points end
add_point
( point_attributes = {})
Creates a new Point object and adds it to the points array. The poitn_attributes are passed as a parameter to Point.new.
[show source]
# File lib/rcap/cap_1_2/polygon.rb, line 25 def add_point( point_attributes = {}) point = Point.new( point_attributes ) self.points << point point end
to_s
()
Returns a string representation of the polygon of the form
points[0] points[1] points[2] ... points[n-1] points[0]
where each point is formatted with Point#to_s
[show source]
# File lib/rcap/cap_1_2/polygon.rb, line 34 def to_s @points.join( ' ' ) end