Class: RGeo::Geos::FFILineStringMethods::PointLocator
- Inherits:
-
Object
- Object
- RGeo::Geos::FFILineStringMethods::PointLocator
- Includes:
- Math
- Defined in:
- lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb
Instance Attribute Summary collapse
-
#factory ⇒ Object
readonly
Returns the value of attribute factory.
-
#segment ⇒ Object
readonly
Returns the value of attribute segment.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #distance_from_segment ⇒ Object
- #distance_on_segment ⇒ Object
-
#initialize(target, segment_or_departure, arrival = nil) ⇒ PointLocator
constructor
A new instance of PointLocator.
- #target_distance_from_departure ⇒ Object
- #target_distance_from_segment ⇒ Object
Constructor Details
#initialize(target, segment_or_departure, arrival = nil) ⇒ PointLocator
Returns a new instance of PointLocator.
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 165 def initialize(target, segment_or_departure, arrival = nil) @segment = if arrival Segment.new(segment_or_departure, arrival) else segment_or_departure end @target = target @factory = departure.factory raise "Target is not defined" unless target end |
Instance Attribute Details
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
162 163 164 |
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 162 def factory @factory end |
#segment ⇒ Object (readonly)
Returns the value of attribute segment.
162 163 164 |
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 162 def segment @segment end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
162 163 164 |
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 162 def target @target end |
Instance Method Details
#distance_from_segment ⇒ Object
181 182 183 184 |
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 181 def distance_from_segment return 0 if [segment.departure, segment.arrival].include?(target) target_distance_from_segment end |
#distance_on_segment ⇒ Object
177 178 179 |
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 177 def distance_on_segment Math.sqrt( target_distance_from_departure**2 - target_distance_from_segment**2 ) end |
#target_distance_from_departure ⇒ Object
186 187 188 |
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 186 def target_distance_from_departure departure.distance target end |
#target_distance_from_segment ⇒ Object
190 191 192 |
# File 'lib/georuby-ext/rgeo/geos/ffi_feature_methods.rb', line 190 def target_distance_from_segment target.distance(factory.line_string([segment.departure, segment.arrival])) end |