-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
update turf #91
update turf #91
Changes from all commits
0088046
0242a01
8ad4e66
4cbdf30
9e3c7a9
aa7b8be
b1eb01c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -600,16 +600,19 @@ | |
let minimumZoomLevel: Float = 14.5 | ||
|
||
let shaftLength = max(min(30 * metersPerPoint(atLatitude: maneuverCoordinate.latitude), 30), 10) | ||
let polyline = Polyline(routeCoordinates) | ||
let shaftCoordinates = Array(polyline.trimmed(from: maneuverCoordinate, distance: -shaftLength).coordinates.reversed() | ||
+ polyline.trimmed(from: maneuverCoordinate, distance: shaftLength).coordinates.suffix(from: 1)) | ||
let polyline = LineString(routeCoordinates) | ||
guard let beforeTrimmedPolyline = polyline.trimmed(from: maneuverCoordinate, distance: -shaftLength), | ||
let afterTrimmedPolyline = polyline.trimmed(from: maneuverCoordinate, distance: shaftLength) else { | ||
return | ||
} | ||
let shaftCoordinates = Array(beforeTrimmedPolyline.coordinates.reversed() + afterTrimmedPolyline.coordinates.suffix(from: 1)) | ||
if shaftCoordinates.count > 1 { | ||
var shaftStrokeCoordinates = shaftCoordinates | ||
let shaftStrokePolyline = ArrowStrokePolyline(coordinates: &shaftStrokeCoordinates, count: UInt(shaftStrokeCoordinates.count)) | ||
let shaftDirection = shaftStrokeCoordinates[shaftStrokeCoordinates.count - 2].direction(to: shaftStrokeCoordinates.last!) | ||
let maneuverArrowStrokePolylines = [shaftStrokePolyline] | ||
let shaftPolyline = ArrowFillPolyline(coordinates: shaftCoordinates, count: UInt(shaftCoordinates.count)) | ||
|
||
let arrowShape = MLNShapeCollection(shapes: [shaftPolyline]) | ||
let arrowStrokeShape = MLNShapeCollection(shapes: maneuverArrowStrokePolylines) | ||
|
||
|
@@ -748,7 +751,7 @@ | |
} | ||
} | ||
|
||
// TODO: Change to point-based distance calculation | ||
private func waypoints(on routes: [Route], closeTo point: CGPoint) -> [Waypoint]? { | ||
let tapCoordinate = convert(point, toCoordinateFrom: self) | ||
let multipointRoutes = routes.filter { $0.routeOptions.waypoints.count >= 3 } | ||
|
@@ -781,17 +784,17 @@ | |
let closest = routes.sorted { left, right -> Bool in | ||
|
||
// existance has been assured through use of filter. | ||
let leftLine = Polyline(left.coordinates!) | ||
let rightLine = Polyline(right.coordinates!) | ||
let leftDistance = leftLine.closestCoordinate(to: tapCoordinate)!.distance | ||
let rightDistance = rightLine.closestCoordinate(to: tapCoordinate)!.distance | ||
let leftLine = LineString(left.coordinates!) | ||
let rightLine = LineString(right.coordinates!) | ||
let leftDistance = leftLine.closestCoordinate(to: tapCoordinate)!.coordinate.distance(to: tapCoordinate) | ||
let rightDistance = rightLine.closestCoordinate(to: tapCoordinate)!.coordinate.distance(to: tapCoordinate) | ||
|
||
return leftDistance < rightDistance | ||
} | ||
|
||
// filter closest coordinates by which ones are under threshold. | ||
let candidates = closest.filter { | ||
let closestCoordinate = Polyline($0.coordinates!).closestCoordinate(to: tapCoordinate)!.coordinate | ||
let closestCoordinate = LineString($0.coordinates!).closestCoordinate(to: tapCoordinate)!.coordinate | ||
let closestPoint = self.convert(closestCoordinate, toPointTo: self) | ||
|
||
return closestPoint.distance(to: point) < self.tapGestureDistanceThreshold | ||
|
@@ -1037,7 +1040,7 @@ | |
for (stepIndex, step) in leg.steps.enumerated() { | ||
for instruction in step.instructionsSpokenAlongStep! { | ||
let feature = MLNPointFeature() | ||
feature.coordinate = Polyline(route.legs[legIndex].steps[stepIndex].coordinates!.reversed()).coordinateFromStart(distance: instruction.distanceAlongStep)! | ||
feature.coordinate = LineString(route.legs[legIndex].steps[stepIndex].coordinates!.reversed()).coordinateFromStart(distance: instruction.distanceAlongStep)! | ||
feature.attributes = ["instruction": instruction.text] | ||
features.append(feature) | ||
} | ||
|
@@ -1075,8 +1078,12 @@ | |
Sets the camera directly over a series of coordinates. | ||
*/ | ||
@objc public func setOverheadCameraView(from userLocation: CLLocationCoordinate2D, along coordinates: [CLLocationCoordinate2D], for bounds: UIEdgeInsets) { | ||
assert(!coordinates.isEmpty, "must specify coordinates when setting overhead camera view") | ||
|
||
self.isAnimatingToOverheadMode = true | ||
let slicedLine = Polyline(coordinates).sliced(from: userLocation).coordinates | ||
guard let slicedLine = LineString(coordinates).sliced(from: userLocation)?.coordinates else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In which cases does LineString.sliced return nil in this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same cause as my previous comment - The implications of this one are trickier though — it's possible that this might result in some change in behavior. My wager is that it's OK, since passing empty coordinates seems ill formed in the first place. And in that case, our response is a no-op, rather than exploding or something scary. I've just now added a debug assert to build confidence that we're not inadvertently hitting that code path. What do you think? |
||
return | ||
} | ||
let line = MLNPolyline(coordinates: slicedLine, count: UInt(slicedLine.count)) | ||
|
||
self.tracksUserCourse = false | ||
|
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.
Why was returning nil here not needed before?
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.
A good question!
The proximate answer is that the
sliced
method signature changed. Previously, if you had a LineString with 0 coordinates, if you tried to slice it, it would return another LineString with 0 coordinates. Now it returnsnil
.Before:
mapbox/turf-swift@b05b465...v2.8.0#diff-809e6d4a01e9482c2a2ac457a5394236ec89bd5355c5ab09fddb69f686225aa2L175
After:
mapbox/turf-swift@b05b465...v2.8.0#diff-9de11b3a56fd1de998fe9ec9a4b133b503af0298afe0008984076e5adb200ca9R276
Seems a little arbitrary, but whatever. 🤷
In any case, could this conceivably affect behavior?
Well, a few lines below your comment is another line:
This method in turn ultimately calls:
This is true for both the old and the new version of turf.
So to summarize, the difference only applies in the degenerate case of getting an empty LineString as input. And in that case, the only difference is we'd now return
nil
a few lines earlier than we would have returnednil
before, but we'll still ultimately returnnil
.Bottom line: I don't think there could be an observable change in behavior from this.