Module: RGeo::Cartesian::LineStringMethods

Included in:
LineImpl, LineStringImpl, LinearRingImpl
Defined in:
lib/rgeo/cartesian/feature_methods.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#_segmentsObject


91
92
93
94
95
96
97
98
# File 'lib/rgeo/cartesian/feature_methods.rb', line 91

def _segments
  unless defined?(@segments)
    @segments = (0..num_points-2).map do |i_|
      Segment.new(point_n(i_), point_n(i_+1))
    end
  end
  @segments
end

#is_simple?Boolean


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/rgeo/cartesian/feature_methods.rb', line 101

def is_simple?
  segs_ = _segments
  len_ = segs_.length
  return false if segs_.any?{ |a_| a_.degenerate? }
  return true if len_ == 1
  return segs_[0].s != segs_[1].e if len_ == 2
  segs_.each_with_index do |seg_, index_|
    nindex_ = index_ + 1
    nindex_ = nil if nindex_ == len_
    return false if nindex_ && seg_.contains_point?(segs_[nindex_].e)
    pindex_ = index_ - 1
    pindex_ = nil if pindex_ < 0
    return false if pindex_ && seg_.contains_point?(segs_[pindex_].s)
    if nindex_
      oindex_ = nindex_ + 1
      while oindex_ < len_
        oseg_ = segs_[oindex_]
        return false if !(index_ == 0 && oindex_ == len_-1 && seg_.s == oseg_.e) && seg_.intersects_segment?(oseg_)
        oindex_ += 1
      end
    end
  end
  true
end

#lengthObject


127
128
129
# File 'lib/rgeo/cartesian/feature_methods.rb', line 127

def length
  _segments.inject(0.0){ |sum_, seg_| sum_ + seg_.length }
end