Module: RGeo::ImplHelper::BasicLineStringMethods
- Included in:
- Cartesian::LineImpl, Cartesian::LineStringImpl, Cartesian::LinearRingImpl, Geographic::ProjectedLineImpl, Geographic::ProjectedLineStringImpl, Geographic::ProjectedLinearRingImpl, Geographic::SphericalLineImpl, Geographic::SphericalLineStringImpl, Geographic::SphericalLinearRingImpl
- Defined in:
- lib/rgeo/impl_helper/basic_line_string_methods.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#_copy_state_from(obj_) ⇒ Object
:nodoc:.
- #_validate_geometry ⇒ Object
- #boundary ⇒ Object
- #coordinates ⇒ Object
- #dimension ⇒ Object
- #end_point ⇒ Object
- #geometry_type ⇒ Object
- #hash ⇒ Object
- #initialize(factory_, points_) ⇒ Object
- #is_closed? ⇒ Boolean
- #is_empty? ⇒ Boolean
- #is_ring? ⇒ Boolean
- #num_points ⇒ Object
- #point_n(n_) ⇒ Object
- #points ⇒ Object
- #rep_equals?(rhs_) ⇒ Boolean
- #start_point ⇒ Object
Instance Method Details
#_copy_state_from(obj_) ⇒ Object
:nodoc:
90 91 92 93 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 90 def _copy_state_from(obj_) # :nodoc: super @points = obj_.points end |
#_validate_geometry ⇒ Object
20 21 22 23 24 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 20 def _validate_geometry if @points.size == 1 raise Error::InvalidGeometry, "LineString cannot have 1 point" end end |
#boundary ⇒ Object
50 51 52 53 54 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 50 def boundary array_ = [] array_ << @points.first << @points.last if !is_empty? && !is_closed? factory.multi_point([array_]) end |
#coordinates ⇒ Object
95 96 97 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 95 def coordinates @points.map(&:coordinates) end |
#dimension ⇒ Object
38 39 40 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 38 def dimension 1 end |
#end_point ⇒ Object
60 61 62 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 60 def end_point @points.last end |
#geometry_type ⇒ Object
42 43 44 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 42 def geometry_type Feature::LineString end |
#hash ⇒ Object
83 84 85 86 87 88 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 83 def hash @hash ||= begin hash_ = [factory, geometry_type].hash @points.inject(hash_) { |h_, p_| (1_664_525 * h_ + p_.hash).hash } end end |
#initialize(factory_, points_) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 10 def initialize(factory_, points_) _set_factory(factory_) @points = points_.map do |elem_| elem_ = Feature.cast(elem_, factory_, Feature::Point) raise Error::InvalidGeometry, "Could not cast #{elem_}" unless elem_ elem_ end _validate_geometry end |
#is_closed? ⇒ Boolean
64 65 66 67 68 69 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 64 def is_closed? unless defined?(@is_closed) @is_closed = @points.size > 2 && @points.first == @points.last end @is_closed end |
#is_empty? ⇒ Boolean
46 47 48 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 46 def is_empty? @points.size == 0 end |
#is_ring? ⇒ Boolean
71 72 73 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 71 def is_ring? is_closed? && is_simple? end |
#num_points ⇒ Object
26 27 28 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 26 def num_points @points.size end |
#point_n(n_) ⇒ Object
30 31 32 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 30 def point_n(n_) n_ < 0 ? nil : @points[n_] end |
#points ⇒ Object
34 35 36 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 34 def points @points.dup end |
#rep_equals?(rhs_) ⇒ Boolean
75 76 77 78 79 80 81 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 75 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_point ⇒ Object
56 57 58 |
# File 'lib/rgeo/impl_helper/basic_line_string_methods.rb', line 56 def start_point @points.first end |