Class: GpxRuby::Gpx::Track::Segment
- Inherits:
-
Object
- Object
- GpxRuby::Gpx::Track::Segment
- Defined in:
- lib/gpx_ruby/gpx/track.rb
Instance Attribute Summary collapse
-
#points ⇒ Object
Returns the value of attribute points.
Instance Method Summary collapse
- #center_of_gravity ⇒ Object
- #distance ⇒ Object
-
#initialize(points) ⇒ Segment
constructor
A new instance of Segment.
- #total_time ⇒ Object
Constructor Details
#initialize(points) ⇒ Segment
Returns a new instance of Segment.
67 68 69 |
# File 'lib/gpx_ruby/gpx/track.rb', line 67 def initialize(points) @points = points || [] end |
Instance Attribute Details
#points ⇒ Object
Returns the value of attribute points.
65 66 67 |
# File 'lib/gpx_ruby/gpx/track.rb', line 65 def points @points end |
Instance Method Details
#center_of_gravity ⇒ Object
86 87 88 89 90 91 |
# File 'lib/gpx_ruby/gpx/track.rb', line 86 def center_of_gravity track_points = points len = track_points.size center = track_points.reduce(:+) center / len end |
#distance ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/gpx_ruby/gpx/track.rb', line 71 def distance if @distance @distance else zipped_points = @points[0...-1].zip(@points[1..-1]) distances = zipped_points.map {|(p,q)| p.distance(q) } @distance = distances.reduce(:+) end end |
#total_time ⇒ Object
81 82 83 84 |
# File 'lib/gpx_ruby/gpx/track.rb', line 81 def total_time start_time, end_time = @points.first.time, @points.last.time end_time - start_time rescue 0 end |