Module: GitFit::Elevation::TerrainCoeff::Lookup
- Defined in:
- lib/git_fit/elevation/terrain_lookup.rb
Class Method Summary collapse
- .hysteresis_threshold(model_pav_h, m_val) ⇒ Object
- .nearest_neighbor_spacing(model_lookup, gain_per_km, range_per_km, seg_density) ⇒ Object
Class Method Details
.hysteresis_threshold(model_pav_h, m_val) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/git_fit/elevation/terrain_lookup.rb', line 24 def hysteresis_threshold(model_pav_h, m_val) return 2.0 if m_val <= 0 return 2.0 if m_val <= model_pav_h[0][0] return model_pav_h[-1][1] if m_val >= model_pav_h[-1][0] model_pav_h.each_with_index do |(_xk, yk), i| next unless i + 1 < model_pav_h.size return yk if m_val <= model_pav_h[i + 1][0] end model_pav_h[-1][1] end |
.nearest_neighbor_spacing(model_lookup, gain_per_km, range_per_km, seg_density) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/git_fit/elevation/terrain_lookup.rb', line 8 def nearest_neighbor_spacing(model_lookup, gain_per_km, range_per_km, seg_density) best = nil best_dist = Float::INFINITY model_lookup.each do |ref| d = Math.sqrt( (gain_per_km.to_f - ref['gk'])**2 + (range_per_km.to_f - ref['rk'])**2 + (seg_density.to_f - ref['sd'])**2, ) next unless d < best_dist best_dist = d best = ref end best ? best['sp'] : 181 end |