Created
December 7, 2015 23:27
-
-
Save mikekavouras/f0e120c598e765bf8502 to your computer and use it in GitHub Desktop.
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
| //: Playground - noun: a place where people can play | |
| import UIKit | |
| print("hello") | |
| func generateRoute(coords: [(Double, Double)]) -> [(Double, Double)] { | |
| var route = [(Double, Double)]() | |
| for (i, coord) in coords.enumerate() { | |
| guard i > 0 else { continue } | |
| let prevCoord = coords[i-1] | |
| let m = (prevCoord.1 - coord.1) / (prevCoord.0 - coord.0) | |
| let b = coord.1 / (m * coord.0) | |
| let dir = m > 0 ? 1 : -1 | |
| var lowLat = coord.0 < prevCoord.0 ? coord.0 : prevCoord.0 | |
| let highLat = coord.0 < prevCoord.0 ? prevCoord.0 : coord.0 | |
| // | |
| // while lowLat <= highLat { | |
| // let lng = m * lowLat + b | |
| // lowLat = dir < 0 ? lowLat + 0.001 : lowLat - 0.001 | |
| // | |
| // route.append((lowLat, lng)) | |
| // } | |
| } | |
| return route | |
| } | |
| let toTrain = [ | |
| (40.74255874, -73.9358747), | |
| (40.74498105, -73.93550992), | |
| (40.74525741, -73.93780589), | |
| (40.74676927, -73.94415736) | |
| ] | |
| print(generateRoute(toTrain)) | |
| let toHome = [ | |
| (40.66636956, -73.98037523), | |
| (40.66689853, -73.98160368), | |
| (40.66267074, -73.98516297), | |
| (40.66381011, -73.9874804), | |
| (40.66291489, -73.98831725) | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment