Created
April 28, 2015 17:02
-
-
Save skyksandr/acc66ac9d8db30a1a84a to your computer and use it in GitHub Desktop.
Skydive comp range finder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module SkydiveCompRange | |
| class RangeFinder | |
| def initialize(track_points, range_from, range_to) | |
| @track_points = track_points.trimmed | |
| @range_from = range_from | |
| @range_to = range_to | |
| end | |
| def process | |
| JumpRange.new(start_point, end_point) | |
| end | |
| private | |
| def start_point | |
| pair = | |
| @track_points.each_cons(2).detect do |pair| | |
| @range_from.between? pair.last[:elevation], pair.first[:elevation] | |
| end | |
| return nil unless pair | |
| PointsInterpolation.find_between(pair.first, pair.last, | |
| coeff(pair.first, pair.last, @range_from)) | |
| end | |
| def end_point | |
| pair = | |
| @track_points.each_cons(2).detect do |pair| | |
| @range_to.between? pair.last[:elevation], pair.first[:elevation] | |
| end | |
| return nil unless pair | |
| PointsInterpolation.find_between(pair.first, pair.last, | |
| coeff(pair.first, pair.last, @range_to)) | |
| end | |
| def coeff(first, last, altitude) | |
| (first[:elevation] - altitude) / (first[:elevation] - last[:elevation]) | |
| end | |
| end | |
| def self.for(track, range_from, range_to) | |
| RangeFinder.new(track, range_from, range_to).process | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment