Module: RGeo::ImplHelper::BasicLineStringMethods

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#_copy_state_from(obj_) ⇒ Object

:nodoc:


144
145
146
147
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 144

def _copy_state_from(obj_)  # :nodoc:
  super
  @points = obj_.points
end

#_validate_geometryObject


58
59
60
61
62
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 58

def _validate_geometry
  if @points.size == 1
    raise Error::InvalidGeometry, 'LineString cannot have 1 point'
  end
end

#boundaryObject


95
96
97
98
99
100
101
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 95

def boundary
  array_ = []
  if !is_empty? && !is_closed?
    array_ << @points.first << @points.last
  end
  factory.multi_point([array_])
end

#dimensionObject


80
81
82
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 80

def dimension
  1
end

#end_pointObject


109
110
111
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 109

def end_point
  @points.last
end

#geometry_typeObject


85
86
87
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 85

def geometry_type
  Feature::LineString
end

#hashObject


136
137
138
139
140
141
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 136

def hash
  @hash ||= begin
    hash_ = [factory, geometry_type].hash
    @points.inject(hash_){ |h_, p_| (1664525 * h_ + p_.hash).hash }
  end
end

#initialize(factory_, points_) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 45

def initialize(factory_, points_)
  _set_factory(factory_)
  @points = points_.map do |elem_|
    elem_ = Feature.cast(elem_, factory_, Feature::Point)
    unless elem_
      raise Error::InvalidGeometry, "Could not cast #{elem_}"
    end
    elem_
  end
  _validate_geometry
end

#is_closed?Boolean

Returns:

  • (Boolean)

114
115
116
117
118
119
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 114

def is_closed?
  unless defined?(@is_closed)
    @is_closed = @points.size > 2 && @points.first == @points.last
  end
  @is_closed
end

#is_empty?Boolean

Returns:

  • (Boolean)

90
91
92
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 90

def is_empty?
  @points.size == 0
end

#is_ring?Boolean

Returns:

  • (Boolean)

122
123
124
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 122

def is_ring?
  is_closed? && is_simple?
end

#num_pointsObject


65
66
67
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 65

def num_points
  @points.size
end

#point_n(n_) ⇒ Object


70
71
72
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 70

def point_n(n_)
  n_ < 0 ? nil : @points[n_]
end

#pointsObject


75
76
77
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 75

def points
  @points.dup
end

#rep_equals?(rhs_) ⇒ Boolean

Returns:

  • (Boolean)

127
128
129
130
131
132
133
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 127

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_pointObject


104
105
106
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 104

def start_point
  @points.first
end