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



44
45
46
47
48
49
50
51
# File 'lib/rgeo/cartesian/feature_methods.rb', line 44

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

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rgeo/cartesian/feature_methods.rb', line 53

def is_simple?
  segs_ = _segments
  len_ = segs_.length
  return false if segs_.any?(&: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)
    next unless 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
  true
end

#lengthObject



77
78
79
# File 'lib/rgeo/cartesian/feature_methods.rb', line 77

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