-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ported the turf-boolean-point-in-polygon function to Turf Swift.
Uses the identical algorithm as used in Turf.js. https://github.com/Turfjs/turf/blob/e53677b0931da9e38bb947da448ee7404adc369d/packages/turf-boolean-point-in-polygon/index.ts
- Loading branch information
Showing
6 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Foundation | ||
#if !os(Linux) | ||
import CoreLocation | ||
#endif | ||
|
||
public class BoundingBox { | ||
|
||
public init?(points: [CLLocationCoordinate2D]?) { | ||
guard points?.count ?? 0 > 0 else { | ||
return nil | ||
} | ||
(minLat, maxLat, minLon, maxLon) = points! | ||
.reduce((minLat: 0, maxLat: 0, minLon: 0, maxLon: 0)) { (result, coordinate) -> (minLat: Double, maxLat: Double, minLon: Double, maxLon: Double) in | ||
let minLat = min(coordinate.latitude, result.0) | ||
let maxLat = max(coordinate.latitude, result.1) | ||
let minLon = min(coordinate.longitude, result.2) | ||
let maxLon = max(coordinate.longitude, result.3) | ||
return (minLat: minLat, maxLat: maxLat, minLon: minLon, maxLon: maxLon) | ||
} | ||
} | ||
|
||
public func contains(point: CLLocationCoordinate2D) -> Bool { | ||
return minLat < point.latitude && maxLat > point.latitude && minLon < point.longitude && maxLon > point.longitude | ||
} | ||
|
||
// MARK: - Private | ||
|
||
let minLat: Double | ||
let maxLat: Double | ||
let minLon: Double | ||
let maxLon: Double | ||
} |
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
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
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
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