Class: Hillpace::TrackPoint
- Inherits:
-
Object
- Object
- Hillpace::TrackPoint
- Defined in:
- lib/hillpace/track_point.rb
Overview
Represents a geographic track point in the Earth.
Constant Summary collapse
- MINIMUM_LONGITUDE =
-180- MAXIMUM_LONGITUDE =
180- MINIMUM_LATITUDE =
-90- MAXIMUM_LATITUDE =
90- METERS_PER_KILOMETER =
1000
Instance Attribute Summary collapse
-
#elevation ⇒ Object
Returns the value of attribute elevation.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
-
#==(other) ⇒ boolean
Overwrites the #== operator to be able to use custom getters.
-
#climb_to(other) ⇒ Number
Measures the elevation difference to other track point, in meters.
-
#distance_meters_to(other) ⇒ Number
Measures the distance to other track point, in meters.
-
#get_linear_interpolation_with(other, bias = 0.5) ⇒ Number
Returns a linear interpolation between self and the one provided.
-
#incline_to(other) ⇒ Number
Measures the elevation difference to other track point relative to the distance to it.
-
#initialize(longitude, latitude, elevation, time = nil) ⇒ TrackPoint
constructor
Initializes a TrackPoint object.
Constructor Details
#initialize(longitude, latitude, elevation, time = nil) ⇒ TrackPoint
Initializes a TrackPoint object.
20 21 22 23 24 25 |
# File 'lib/hillpace/track_point.rb', line 20 def initialize(longitude, latitude, elevation, time = nil) self.longitude = longitude self.latitude = latitude self.elevation = elevation self.time = time end |
Instance Attribute Details
#elevation ⇒ Object
Returns the value of attribute elevation.
6 7 8 |
# File 'lib/hillpace/track_point.rb', line 6 def elevation @elevation end |
#latitude ⇒ Object
Returns the value of attribute latitude.
6 7 8 |
# File 'lib/hillpace/track_point.rb', line 6 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
6 7 8 |
# File 'lib/hillpace/track_point.rb', line 6 def longitude @longitude end |
#time ⇒ Object
Returns the value of attribute time.
6 7 8 |
# File 'lib/hillpace/track_point.rb', line 6 def time @time end |
Instance Method Details
#==(other) ⇒ boolean
Overwrites the #== operator to be able to use custom getters.
30 31 32 33 34 35 36 |
# File 'lib/hillpace/track_point.rb', line 30 def ==(other) self.class == other.class && longitude == other.longitude && latitude == other.latitude && elevation == other.elevation && time == other.time end |
#climb_to(other) ⇒ Number
Measures the elevation difference to other track point, in meters.
91 92 93 94 |
# File 'lib/hillpace/track_point.rb', line 91 def climb_to(other) raise 'Invalid track point' unless other.is_a? TrackPoint other.elevation - elevation end |
#distance_meters_to(other) ⇒ Number
Measures the distance to other track point, in meters.
80 81 82 83 84 85 |
# File 'lib/hillpace/track_point.rb', line 80 def distance_meters_to(other) raise 'Invalid track point' unless other.is_a? TrackPoint a = Geokit::GeoLoc.new({:lat => latitude, :lng => longitude}) b = Geokit::GeoLoc.new({:lat => other.latitude, :lng => other.longitude}) METERS_PER_KILOMETER * (a.distance_to b, {:units => :kms}) end |
#get_linear_interpolation_with(other, bias = 0.5) ⇒ Number
For small distances between track points, a linear interpolation should be accurate enough.
Returns a linear interpolation between self and the one provided.
115 116 117 118 119 120 121 |
# File 'lib/hillpace/track_point.rb', line 115 def get_linear_interpolation_with(other, bias = 0.5) raise 'Invalid track point' unless other.is_a? TrackPoint TrackPoint.new longitude * (1.0 - bias) + other.longitude * bias, latitude * (1.0 - bias) + other.latitude * bias, elevation * (1.0 - bias) + other.elevation * bias, time.nil? || other.time.nil? ? nil : Time.at(time.to_f * (1.0 - bias) + other.time.to_f * bias) end |
#incline_to(other) ⇒ Number
Measures the elevation difference to other track point relative to the distance to it.
100 101 102 103 104 105 106 |
# File 'lib/hillpace/track_point.rb', line 100 def incline_to(other) raise 'Invalid track point' unless other.is_a? TrackPoint distance_meters = self.distance_meters_to other return 0 if distance_meters == 0 (self.climb_to other) / distance_meters end |