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
func sortConvex(input: [CLLocationCoordinate2D]) -> [CLLocationCoordinate2D] { | |
// X = longitude | |
// Y = latitudeß | |
// 2D cross product of OA and OB vectors, i.e. z-component of their 3D cross product. | |
// Returns a positive value, if OAB makes a counter-clockwise turn, | |
// negative for clockwise turn, and zero if the points are collinear. | |
func cross(P: CLLocationCoordinate2D, A: CLLocationCoordinate2D, B: CLLocationCoordinate2D) -> Double { | |
let part1 = (A.longitude - P.longitude) * (B.latitude - P.latitude) |