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



61
62
63
64
65
66
67
68
# File 'lib/rgeo/cartesian/feature_methods.rb', line 61

def _segments
  unless @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

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rgeo/cartesian/feature_methods.rb', line 71

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



97
98
99
# File 'lib/rgeo/cartesian/feature_methods.rb', line 97

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