Module: RGeo::ImplHelper::BasicPolygonMethods
- Included in:
- Cartesian::PolygonImpl, Geographic::ProjectedPolygonImpl, Geographic::SphericalPolygonImpl
- Defined in:
- lib/rgeo/impl_helper/basic_polygon_methods.rb
Overview
:nodoc:
Instance Method Summary collapse
- #boundary ⇒ Object
- #contains?(rhs) ⇒ Boolean
- #coordinates ⇒ Object
- #dimension ⇒ Object
- #exterior_ring ⇒ Object
- #geometry_type ⇒ Object
- #hash ⇒ Object
- #initialize(factory, exterior_ring, interior_rings) ⇒ Object
- #interior_ring_n(n) ⇒ Object
- #interior_rings ⇒ Object
- #is_empty? ⇒ Boolean
- #num_interior_rings ⇒ Object
- #rep_equals?(rhs) ⇒ Boolean
Instance Method Details
#boundary ⇒ Object
56 57 58 59 60 61 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 56 def boundary array = [] array << @exterior_ring unless @exterior_ring.is_empty? array.concat(@interior_rings) factory.multi_line_string(array) end |
#contains?(rhs) ⇒ Boolean
82 83 84 85 86 87 88 89 90 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 82 def contains?(rhs) if Feature::Point === rhs contains_point?(rhs) else raise(Error::UnsupportedOperation, "Method Polygon#contains? is only defined for Point" ) end end |
#coordinates ⇒ Object
78 79 80 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 78 def coordinates ([@exterior_ring] + @interior_rings).map(&:coordinates) end |
#dimension ⇒ Object
44 45 46 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 44 def dimension 2 end |
#exterior_ring ⇒ Object
28 29 30 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 28 def exterior_ring @exterior_ring end |
#geometry_type ⇒ Object
48 49 50 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 48 def geometry_type Feature::Polygon end |
#hash ⇒ Object
71 72 73 74 75 76 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 71 def hash @hash ||= begin hash = [geometry_type, @exterior_ring].hash @interior_rings.inject(hash) { |h, r| (1_664_525 * h + r.hash).hash } end end |
#initialize(factory, exterior_ring, interior_rings) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 12 def initialize(factory, exterior_ring, interior_rings) self.factory = factory @exterior_ring = Feature.cast(exterior_ring, factory, Feature::LinearRing) unless @exterior_ring raise Error::InvalidGeometry, "Failed to cast exterior ring #{exterior_ring}" end @interior_rings = (interior_rings || []).map do |elem| elem = Feature.cast(elem, factory, Feature::LinearRing) unless elem raise Error::InvalidGeometry, "Could not cast interior ring #{elem}" end elem end validate_geometry end |
#interior_ring_n(n) ⇒ Object
36 37 38 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 36 def interior_ring_n(n) n < 0 ? nil : @interior_rings[n] end |
#interior_rings ⇒ Object
40 41 42 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 40 def interior_rings @interior_rings.dup end |
#is_empty? ⇒ Boolean
52 53 54 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 52 def is_empty? @exterior_ring.is_empty? end |
#num_interior_rings ⇒ Object
32 33 34 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 32 def num_interior_rings @interior_rings.size end |
#rep_equals?(rhs) ⇒ Boolean
63 64 65 66 67 68 69 |
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 63 def rep_equals?(rhs) if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @exterior_ring.rep_equals?(rhs.exterior_ring) && @interior_rings.size == rhs.num_interior_rings rhs.interior_rings.each_with_index { |r, i| return false unless @interior_rings[i].rep_equals?(r) } else false end end |