Class: SimplePolygons::Polygon

Inherits:
Object
  • Object
show all
Defined in:
lib/simple-polygons.rb

Overview

Basic polygon class.

Direct Known Subclasses

Line, Rectangle, Triangle

Instance Method Summary collapse

Constructor Details

#initialize(point_array = []) ⇒ Polygon

point_array should be an array of Location objects.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/simple-polygons.rb', line 24

def initialize(point_array=[])
  pts_found = []
  point_array.each() do |p|
    if pts_found.include?(p)
      raise EquivalentLocationsError.new("Multiple locations of the same place found in SimplePolygons::Polygon#initialize")
    end
    pts_found << p
  end

  @points = point_array
end

Instance Method Details

#number_of_pointsObject

Returns the number of points.



37
38
39
# File 'lib/simple-polygons.rb', line 37

def number_of_points()
  return @points.length()
end