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_1/polygon.rb, line 18 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_1/polygon.rb, line 48 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_1/polygon.rb, line 24 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_1/polygon.rb, line 33 def to_s (@points + [ @points.first ]).join( ' ' ) end