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

Instance Method Details

#_copy_state_from(obj_) ⇒ Object

:nodoc:


124
125
126
127
128
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 124

def _copy_state_from(obj_)  # :nodoc:
  super
  @exterior_ring = obj_.exterior_ring
  @interior_rings = obj_.interior_rings
end

#boundaryObject


97
98
99
100
101
102
103
104
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 97

def boundary
  array_ = []
  unless @exterior_ring.is_empty?
    array_ << @exterior_ring
  end
  array_.concat(@interior_rings)
  factory.multi_line_string(array_)
end

#dimensionObject


82
83
84
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 82

def dimension
  2
end

#exterior_ringObject


62
63
64
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 62

def exterior_ring
  @exterior_ring
end

#geometry_typeObject


87
88
89
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 87

def geometry_type
  Feature::Polygon
end

#hashObject


116
117
118
119
120
121
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 116

def hash
  @hash ||= begin
    hash_ = [geometry_type, @exterior_ring].hash
    @interior_rings.inject(hash_){ |h_, r_| (1664525 * h_ + r_.hash).hash }
  end
end

#initialize(factory_, exterior_ring_, interior_rings_) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 45

def initialize(factory_, exterior_ring_, interior_rings_)
  _set_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


72
73
74
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 72

def interior_ring_n(n_)
  n_ < 0 ? nil : @interior_rings[n_]
end

#interior_ringsObject


77
78
79
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 77

def interior_rings
  @interior_rings.dup
end

#is_empty?Boolean


92
93
94
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 92

def is_empty?
  @exterior_ring.is_empty?
end

#num_interior_ringsObject


67
68
69
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 67

def num_interior_rings
  @interior_rings.size
end

#rep_equals?(rhs_) ⇒ Boolean


107
108
109
110
111
112
113
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 107

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