Created
June 21, 2011 00:19
-
-
Save kingcu/1036943 to your computer and use it in GitHub Desktop.
Ugh, ghetto
This file contains 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
def potentially_convert_pois_to_coursepoints_if_necessary(track) | |
return if track[:pois].nil? or track[:pois].length == 0 | |
#if we have both POI and coursepoints, we can assume the POI | |
#are legitimate, else they would have been parsed as coursepoints | |
return if track[:course_points] && tracl[:course_points].length > 0 | |
eps = 0.0001 #11 feet | |
to_keep = [] | |
track[:pois].each do |poi| | |
next if poi[:n].blank? && poi[:d].blank? | |
next if poi[:n] =~ /(turn left|right)|(continue on)/i | |
closest = nil | |
closest_dist = 999999 | |
track[:track].each do |pt| | |
next unless (pt[:x] - poi[:x] < eps) && (pt[:y] - poi[:y] < eps) | |
dist = (pt[:x] - poi[:x])**2 + (pt[:y] - poi[:y])**2 | |
#dist = Trip.haversine_distance(pt[:y], pt[:x], poi[:y], poi[:x]) | |
if dist < closest_dist | |
closest_dist = dist | |
closest = pt | |
end | |
end | |
next if closest.nil? or closest < eps | |
to_keep << poi | |
end | |
track[:pois] = to_keep | |
return track | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment