Class: GeoGraf::Polygon

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_graf/polygon.rb

Instance Method Summary collapse

Constructor Details

#initialize(coordinates, factory) ⇒ Polygon

Returns a new instance of Polygon.



3
4
5
6
7
# File 'lib/geo_graf/polygon.rb', line 3

def initialize(coordinates, factory)
  @rgeo_polygons = [create_polygon(coordinates, factory)]

  create_shadow_polygon_if_required(coordinates, factory)
end

Instance Method Details

#areaObject



21
22
23
# File 'lib/geo_graf/polygon.rb', line 21

def area
  rgeo_polygons.first.area
end

#intersection_area(other) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/geo_graf/polygon.rb', line 9

def intersection_area(other)
  intersection = intersection(other)

  if intersection.respond_to?(:area)
    intersection.area
  elsif intersection.respond_to?(:map)
    sum_of_areas_in(intersection)
  else
    0.0
  end
end