Class: ActiveRecordPolyline::Compaction::SimpleCompressor
- Defined in:
- lib/active_record_polyline/compaction/simple_compressor.rb
Direct Known Subclasses
Instance Method Summary collapse
- #addable?(location) ⇒ Boolean
- #distant?(point1, point2) ⇒ Boolean
-
#initialize(distance: 100) ⇒ SimpleCompressor
constructor
A new instance of SimpleCompressor.
Methods inherited from Base
#apply, compress_after_push, compress_before_push, #push
Constructor Details
#initialize(distance: 100) ⇒ SimpleCompressor
Returns a new instance of SimpleCompressor.
8 9 10 11 |
# File 'lib/active_record_polyline/compaction/simple_compressor.rb', line 8 def initialize(distance: 100) @distance = distance @factory = RGeo::Geographic.spherical_factory end |
Instance Method Details
#addable?(location) ⇒ Boolean
13 14 15 16 17 |
# File 'lib/active_record_polyline/compaction/simple_compressor.rb', line 13 def addable?(location) return true if @polyline.points.empty? distant?(@polyline.points.last, location) end |
#distant?(point1, point2) ⇒ Boolean
19 20 21 22 23 |
# File 'lib/active_record_polyline/compaction/simple_compressor.rb', line 19 def distant?(point1, point2) pt1 = @factory.point(point1[:longitude], point1[:latitude]) pt2 = @factory.point(point2[:longitude], point2[:latitude]) pt2.distance(pt1) > @distance end |