Module: RGeo::ImplHelper::BasicLineStringMethods
- Included in:
- Cartesian::LineImpl, Cartesian::LineStringImpl, Cartesian::LinearRingImpl, Geographic::ProjectedLineImpl, Geographic::ProjectedLineStringImpl, Geographic::ProjectedLinearRingImpl, Geographic::SphericalLineImpl, Geographic::SphericalLineStringImpl, Geographic::SphericalLinearRingImpl
- Defined in:
- lib/rgeo/impl_helper/basic_line_string_methods.rb
Overview
:nodoc:
Instance Method Summary collapse
- #boundary ⇒ Object
- #contains?(rhs) ⇒ Boolean
- #coordinates ⇒ Object
- #dimension ⇒ Object
- #end_point ⇒ Object
- #geometry_type ⇒ Object
- #hash ⇒ Object
- #initialize(factory, points) ⇒ Object
- #is_closed? ⇒ Boolean
- #is_empty? ⇒ Boolean
- #is_ring? ⇒ Boolean
- #num_points ⇒ Object
- #point_n(n) ⇒ Object
- #points ⇒ Object
- #rep_equals?(rhs) ⇒ Boolean
- #start_point ⇒ Object
Instance Method Details
#boundary ⇒ Object
46 47 48 49 50 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 46 def boundary array = [] array << @points.first << @points.last if !is_empty? && !is_closed? factory.multipoint([array]) end |
#contains?(rhs) ⇒ Boolean
90 91 92 93 94 95 96 97 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 90 def contains?(rhs) if Feature::Point === rhs contains_point?(rhs) else raise(Error::UnsupportedOperation, "Method LineString#contains? is only defined for Point") end end |
#coordinates ⇒ Object
86 87 88 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 86 def coordinates @points.map(&:coordinates) end |
#dimension ⇒ Object
34 35 36 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 34 def dimension 1 end |
#end_point ⇒ Object
56 57 58 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 56 def end_point @points.last end |
#geometry_type ⇒ Object
38 39 40 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 38 def geometry_type Feature::LineString end |
#hash ⇒ Object
79 80 81 82 83 84 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 79 def hash @hash ||= begin hash = [factory, geometry_type].hash @points.inject(hash) { |h, p| (1_664_525 * h + p.hash).hash } end end |
#initialize(factory, points) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 12 def initialize(factory, points) self.factory = factory @points = points.map do |elem| elem = Feature.cast(elem, factory, Feature::Point) raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem elem end validate_geometry end |
#is_closed? ⇒ Boolean
60 61 62 63 64 65 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 60 def is_closed? unless defined?(@is_closed) @is_closed = @points.size > 2 && @points.first == @points.last end @is_closed end |
#is_empty? ⇒ Boolean
42 43 44 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 42 def is_empty? @points.size == 0 end |
#is_ring? ⇒ Boolean
67 68 69 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 67 def is_ring? is_closed? && is_simple? end |
#num_points ⇒ Object
22 23 24 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 22 def num_points @points.size end |
#point_n(n) ⇒ Object
26 27 28 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 26 def point_n(n) n < 0 ? nil : @points[n] end |
#points ⇒ Object
30 31 32 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 30 def points @points.dup end |
#rep_equals?(rhs) ⇒ Boolean
71 72 73 74 75 76 77 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 71 def rep_equals?(rhs) if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @points.size == rhs.num_points rhs.points.each_with_index { |p, i| return false unless @points[i].rep_equals?(p) } else false end end |
#start_point ⇒ Object
52 53 54 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 52 def start_point @points.first end |