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:



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

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

#boundaryObject



54
55
56
57
58
59
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 54

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

#coordinatesObject



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

def coordinates
  ([@exterior_ring] + @interior_rings).map(&:coordinates)
end

#dimensionObject



42
43
44
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 42

def dimension
  2
end

#exterior_ringObject



26
27
28
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 26

def exterior_ring
  @exterior_ring
end

#geometry_typeObject



46
47
48
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 46

def geometry_type
  Feature::Polygon
end

#hashObject



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

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 10

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



34
35
36
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 34

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

#interior_ringsObject



38
39
40
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 38

def interior_rings
  @interior_rings.dup
end

#is_empty?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 50

def is_empty?
  @exterior_ring.is_empty?
end

#num_interior_ringsObject



30
31
32
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 30

def num_interior_rings
  @interior_rings.size
end

#rep_equals?(rhs_) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 61

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