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

#is_simple?Boolean

Returns:

  • (Boolean)

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

def is_simple?
  len = segments.length
  return false if segments.any?(&:degenerate?)
  return true if len == 1
  return segments[0].s != segments[1].e if len == 2
  segments.each_with_index do |seg, index|
    nindex = index + 1
    nindex = nil if nindex == len
    return false if nindex && seg.contains_point?(segments[nindex].e)
    pindex = index - 1
    pindex = nil if pindex < 0
    return false if pindex && seg.contains_point?(segments[pindex].s)
    next unless nindex
    oindex = nindex + 1
    while oindex < len
      oseg = segments[oindex]
      return false if !(index == 0 && oindex == len - 1 && seg.s == oseg.e) && seg.intersects_segment?(oseg)
      oindex += 1
    end
  end
  true
end

#lengthObject


75
76
77
# File 'lib/rgeo/cartesian/feature_methods.rb', line 75

def length
  segments.inject(0.0) { |sum, seg| sum + seg.length }
end

#segmentsObject


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

def segments
  @segments ||= (0..num_points - 2).map do |i|
    Segment.new(point_n(i), point_n(i + 1))
  end
end