-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ported the turf-boolean-point-in-polygon function to Turf Swift. #64
Conversation
Uses the identical algorithm as used in Turf.js. https://github.com/Turfjs/turf/blob/e53677b0931da9e38bb947da448ee7404adc369d/packages/turf-boolean-point-in-polygon/index.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for porting this feature.
Almost there, just a few nits.
Sources/Turf/BoundingBox.swift
Outdated
import CoreLocation | ||
#endif | ||
|
||
public class BoundingBox { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All other geometries and GeoJSON features are structs, let's stick with that since we don't provide support for Obj-C for now. This bounding box should also conform to Codable
.
Sources/Turf/BoundingBox.swift
Outdated
|
||
// MARK: - Private | ||
|
||
let minLat: Double |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we consolidate these 4 min/max properties into a northWest
southEast
CLLocationCoordinate2D for concistency with many of Mapbox’s libraries?
Sources/Turf/BoundingBox.swift
Outdated
|
||
public class BoundingBox { | ||
|
||
public init?(points: [CLLocationCoordinate2D]?) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: public init?(from coordinates: [CLLocationCoordinate2D]?)
perhaps an additional initializer:
public init(_ northWest: CLLocationCoordinate2D, _ southEast: CLLocationCoordinate2D)
?
Sources/Turf/Polygon.swift
Outdated
* | ||
* Ported from: https://github.com/Turfjs/turf/blob/e53677b0931da9e38bb947da448ee7404adc369d/packages/turf-boolean-point-in-polygon/index.ts#L31-L75 | ||
*/ | ||
public func contains(point: CLLocationCoordinate2D, ignoreBoundary: Bool = false) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: contains(_ coordinate: CLLocationCoordinate2D
Sources/Turf/Polygon.swift
Outdated
* Ported from: https://github.com/Turfjs/turf/blob/e53677b0931da9e38bb947da448ee7404adc369d/packages/turf-boolean-point-in-polygon/index.ts#L31-L75 | ||
*/ | ||
public func contains(point: CLLocationCoordinate2D, ignoreBoundary: Bool = false) -> Bool { | ||
let bbox = BoundingBox(points: self.coordinates.first) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: self is inferred and can be dropped. (×2)
Sources/Turf/Ring.swift
Outdated
* | ||
* Ported from: https://github.com/Turfjs/turf/blob/e53677b0931da9e38bb947da448ee7404adc369d/packages/turf-boolean-point-in-polygon/index.ts#L77-L108 | ||
*/ | ||
public func contains(point: CLLocationCoordinate2D, ignoreBoundary: Bool = false) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: contains(_ coordinate: CLLocationCoordinate2D
Sources/Turf/BoundingBox.swift
Outdated
} | ||
} | ||
|
||
public func contains(point: CLLocationCoordinate2D) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: contains(_ coordinate:
Renamed several methods to use identifier `coordinate` instead of `point`. Made `BoundingBox` a `Codable` `struct`. Removed several instances of an explict usage of `self`.
@frederoni : I believe all your feedback has been addressed. Can you please re-review and let me know if there are additional changes requested? |
Uses the identical algorithm as used in Turf.js.
https://github.com/Turfjs/turf/blob/e53677b0931da9e38bb947da448ee7404adc369d/packages/turf-boolean-point-in-polygon/index.ts