Skip to content
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 v0.5.0 #2393

Merged
merged 15 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
binary "https://www.mapbox.com/ios-sdk/MapboxAccounts.json" ~> 2.2
binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" ~> 5.6
binary "https://www.mapbox.com/ios-sdk/MapboxNavigationNative.json" == 9.0.4
github "mapbox/mapbox-directions-swift" ~> 0.31
github "mapbox/turf-swift" ~> 0.3
github "mapbox/mapbox-directions-swift" ~> 0.32
github "mapbox/turf-swift" ~> 0.5
github "mapbox/mapbox-events-ios" ~> 0.10
github "ceeK/Solar" ~> 2.1.0
github "mapbox/mapbox-speech-swift" ~> 0.3.0
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ github "Udumft/SnappyShrimp" "66f3e3ba70370ad5e889ac8ed72a8730ca79958e"
github "ceeK/Solar" "2.1.0"
github "linksmt/OHHTTPStubs" "563f48d3fab84ef04639649c770b00f4fa502cca"
github "mapbox/MapboxGeocoder.swift" "v0.10.2"
github "mapbox/mapbox-directions-swift" "v0.31.0"
github "mapbox/mapbox-directions-swift" "v0.32.0"
github "mapbox/mapbox-events-ios" "v0.10.2"
github "mapbox/mapbox-speech-swift" "v0.3.0"
github "mapbox/turf-swift" "v0.3.0"
github "mapbox/turf-swift" "v0.5.0"
github "raphaelmor/Polyline" "v4.2.1"
github "uber/ios-snapshot-test-case" "5.0.2"
3 changes: 2 additions & 1 deletion Example/OfflineViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit
import Mapbox
import Turf
import MapboxDirections
import MapboxCoreNavigation

Expand Down Expand Up @@ -47,7 +48,7 @@ class OfflineViewController: UIViewController, MGLMapViewDelegate {

@objc func downloadRegion() {
let mapCoordinateBounds = mapView.convert(resizableView.frame, toCoordinateBoundsFrom: nil)
let coordinateBounds = CoordinateBounds(coordinates: [mapCoordinateBounds.sw, mapCoordinateBounds.ne])
let coordinateBounds = BoundingBox(mapCoordinateBounds.sw, mapCoordinateBounds.ne)

disableUserInterface()

Expand Down
4 changes: 2 additions & 2 deletions MapboxCoreNavigation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ Pod::Spec.new do |s|

s.dependency "MapboxNavigationNative", "= 9.0.4"
s.dependency "MapboxAccounts", "~> 2.2.0"
s.dependency "MapboxDirections", "~> 0.31.0"
s.dependency "MapboxDirections", "~> 0.32.0"
s.dependency "MapboxMobileEvents", "~> 0.10.2" # Always pin to a patch release if pre-1.0
s.dependency "Turf", "~> 0.3.0" # Always pin to a patch release if pre-1.0
s.dependency "Turf", "~> 0.5.0" # Always pin to a patch release if pre-1.0

s.swift_version = "5.0"

Expand Down
19 changes: 11 additions & 8 deletions MapboxCoreNavigation/CLLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension CLLocation {
guard let shape = routeStep.shape, let closestCoordinate = shape.closestCoordinate(to: coordinate) else {
return false
}
return closestCoordinate.distance < maximumDistance
return closestCoordinate.coordinate.distance(to: coordinate) < maximumDistance
}

//MARK: - Route Snapping
Expand All @@ -67,7 +67,7 @@ extension CLLocation {
/**
Calculates the proper coordinates to use when calculating a snapped location.
*/
func snappingPolyline(for routeProgress: RouteProgress) -> Polyline {
func snappingPolyline(for routeProgress: RouteProgress) -> LineString {
let legProgress = routeProgress.currentLegProgress
let nearbyPolyline = routeProgress.nearbyShape
let stepPolyline = legProgress.currentStep.shape!
Expand Down Expand Up @@ -97,12 +97,12 @@ extension CLLocation {
/**
Given a location and a series of coordinates, compute what the course should be for a the location.
*/
func interpolatedCourse(along polyline: Polyline) -> CLLocationDirection? {
func interpolatedCourse(along polyline: LineString) -> CLLocationDirection? {
guard let closest = polyline.closestCoordinate(to: coordinate) else { return nil }

let reversedPolyline = Polyline(polyline.coordinates.reversed())
let slicedLineBehind = reversedPolyline.sliced(from: closest.coordinate, to: reversedPolyline.coordinates.last)
let slicedLineInFront = polyline.sliced(from: closest.coordinate, to: polyline.coordinates.last)
let reversedPolyline = LineString(polyline.coordinates.reversed())
let slicedLineBehind = reversedPolyline.sliced(from: closest.coordinate, to: reversedPolyline.coordinates.last)!
let slicedLineInFront = polyline.sliced(from: closest.coordinate, to: polyline.coordinates.last)!
let userDistanceBuffer: CLLocationDistance = max(speed * RouteControllerDeadReckoningTimeInterval / 2, RouteControllerUserLocationSnappingDistance / 2)

guard let pointBehind = slicedLineBehind.coordinateFromStart(distance: userDistanceBuffer) else { return nil }
Expand All @@ -119,12 +119,15 @@ extension CLLocation {
let relativeAnglepointBehind = (wrappedPointBehind - wrappedCourse).wrap(min: -180, max: 180)
let relativeAnglepointAhead = (wrappedPointAhead - wrappedCourse).wrap(min: -180, max: 180)

let distanceBehindClosest = pointBehindClosest.coordinate.distance(to: pointBehind)
let distanceAheadClosest = pointAheadClosest.coordinate.distance(to: pointAhead)

let averageRelativeAngle: Double
// User is at the beginning of the route, there is no closest point behind the user.
if pointBehindClosest.distance <= 0 && pointAheadClosest.distance > 0 {
if distanceBehindClosest <= 0 && distanceAheadClosest > 0 {
averageRelativeAngle = relativeAnglepointAhead
// User is at the end of the route, there is no closest point in front of the user.
} else if pointAheadClosest.distance <= 0 && pointBehindClosest.distance > 0 {
} else if distanceAheadClosest <= 0 && distanceBehindClosest > 0 {
averageRelativeAngle = relativeAnglepointBehind
} else {
averageRelativeAngle = (relativeAnglepointBehind + relativeAnglepointAhead) / 2
Expand Down
4 changes: 2 additions & 2 deletions MapboxCoreNavigation/LegacyRouteController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ open class LegacyRouteController: NSObject, Router, InternalRouter, CLLocationMa
}

if let closestCoordinate = polyline.closestCoordinate(to: rawLocation.coordinate) {
let remainingDistance = polyline.distance(from: closestCoordinate.coordinate)
let remainingDistance = polyline.distance(from: closestCoordinate.coordinate)!
let distanceTraveled = step.distance - remainingDistance
stepProgress.distanceTraveled = distanceTraveled

Expand Down Expand Up @@ -529,7 +529,7 @@ open class LegacyRouteController: NSObject, Router, InternalRouter, CLLocationMa

func updateIntersectionDistances() {
if let shape = routeProgress.currentLegProgress.currentStep.shape, let intersections = routeProgress.currentLegProgress.currentStep.intersections {
let distances: [CLLocationDistance] = intersections.map { shape.distance(from: shape.coordinates.first, to: $0.location) }
let distances: [CLLocationDistance] = intersections.compactMap { shape.distance(from: shape.coordinates.first, to: $0.location) }
routeProgress.currentLegProgress.currentStepProgress.intersectionDistances = distances
}
}
Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigation/RouteController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ open class RouteController: NSObject {
preconditionFailure("Route steps used for navigation must have shape data")
}
if let closestCoordinate = polyline.closestCoordinate(to: rawLocation.coordinate) {
let remainingDistance = polyline.distance(from: closestCoordinate.coordinate)
let remainingDistance = polyline.distance(from: closestCoordinate.coordinate)!
let distanceTraveled = step.distance - remainingDistance
stepProgress.distanceTraveled = distanceTraveled

Expand Down
13 changes: 5 additions & 8 deletions MapboxCoreNavigation/RouteProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,17 @@ open class RouteLegProgress {
for (currentStepIndex, step) in remainingSteps.enumerated() {
guard let shape = step.shape else { continue }
guard let closestCoordOnStep = shape.closestCoordinate(to: coordinate) else { continue }
let closesCoordOnStepDistance = closestCoordOnStep.coordinate.distance(to: coordinate)
let foundIndex = currentStepIndex + stepIndex

// First time around, currentClosest will be `nil`.
guard let currentClosestDistance = currentClosest?.distance else {
currentClosest = (index: foundIndex, distance: closestCoordOnStep.distance)
currentClosest = (index: foundIndex, distance: closesCoordOnStepDistance)
continue
}

if closestCoordOnStep.distance < currentClosestDistance {
currentClosest = (index: foundIndex, distance: closestCoordOnStep.distance)
if closesCoordOnStepDistance < currentClosestDistance {
currentClosest = (index: foundIndex, distance: closesCoordOnStepDistance)
}
}

Expand All @@ -469,11 +470,7 @@ open class RouteLegProgress {
var slice = legPolyline
var accumulatedCoordinates = 0
return Array(waypoints.drop { (waypoint) -> Bool in
var newSlice = slice.sliced(from: waypoint.coordinate)
// Work around <https://github.com/mapbox/turf-swift/pull/79>.
if newSlice.coordinates.count > 2 && newSlice.coordinates.last == newSlice.coordinates.dropLast().last {
Udumft marked this conversation as resolved.
Show resolved Hide resolved
newSlice.coordinates.removeLast()
}
let newSlice = slice.sliced(from: waypoint.coordinate)!
accumulatedCoordinates += slice.coordinates.count - newSlice.coordinates.count
slice = newSlice
return accumulatedCoordinates <= userCoordinateIndex
Expand Down
4 changes: 2 additions & 2 deletions MapboxCoreNavigation/SimulatedLocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ open class SimulatedLocationManager: NavigationLocationManager {
fileprivate var timer: DispatchTimer!

fileprivate var locations: [SimulatedLocation]!
fileprivate var routeShape: Polyline!
fileprivate var routeShape: LineString!

/**
Specify the multiplier to use when calculating speed based on the RouteLeg’s `expectedSegmentTravelTimes`.
Expand Down Expand Up @@ -157,7 +157,7 @@ open class SimulatedLocationManager: NavigationLocationManager {
let distanceToClosest = closestLocation.distance(from: CLLocation(newCoordinate))

let distance = min(max(distanceToClosest, 10), safeDistance)
let coordinatesNearby = polyline.trimmed(from: newCoordinate, distance: 100).coordinates
let coordinatesNearby = polyline.trimmed(from: newCoordinate, distance: 100)!.coordinates
Udumft marked this conversation as resolved.
Show resolved Hide resolved

// Simulate speed based on expected segment travel time
if let expectedSegmentTravelTimes = routeProgress?.currentLeg.expectedSegmentTravelTimes,
Expand Down
20 changes: 10 additions & 10 deletions MapboxCoreNavigationTests/CocoaPodsTest/PodInstall/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ PODS:
- MapboxAccounts (2.2.0)
- MapboxCoreNavigation (0.40.0):
- MapboxAccounts (~> 2.2.0)
- MapboxDirections (~> 0.31.0)
- MapboxDirections (~> 0.32.0)
- MapboxMobileEvents (~> 0.10.2)
- MapboxNavigationNative (= 9.0.4)
- Turf (~> 0.3.0)
- MapboxDirections (0.31.0):
- Turf (~> 0.5.0)
- MapboxDirections (0.32.0):
- Polyline (~> 4.2)
- Turf (~> 0.3)
- Turf (~> 0.5)
- MapboxMobileEvents (0.10.2)
- MapboxNavigation (0.40.0):
- Mapbox-iOS-SDK (~> 5.6)
Expand All @@ -22,14 +22,14 @@ PODS:
- MapboxSpeech (0.3.0)
- Polyline (4.2.1)
- Solar (2.1.0)
- Turf (0.3.0)
- Turf (0.5.0)

DEPENDENCIES:
- MapboxCoreNavigation (from `../../../`)
- MapboxNavigation (from `../../../`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
https://github.com/cocoapods/specs.git:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this has been a longstanding annoyance for us. To keep the trunk repo from being a problem in the future, we’d need to ensure that the CI bots are all running a newer version of CocoaPods that can handle trunk. Some of the older-Xcode CI bots are on images that come with older CocoaPods versions. We could either manually upgrade CocoaPods on those bots as part of the build process, or we could upgrade those bots to a newer-Xcode image.

- Mapbox-iOS-SDK
- MapboxAccounts
- MapboxDirections
Expand All @@ -49,16 +49,16 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Mapbox-iOS-SDK: a5915700ec84bc1a7f8b3e746d474789e35b7956
MapboxAccounts: 3c04a1df56c1ac4ff714619296fb47310cf70ad0
MapboxCoreNavigation: 79d1b2e201be2aed7edd188f90de54c03a59606d
MapboxDirections: 0b97aa320d7cddbe72d6513becc07dd747935240
MapboxCoreNavigation: e172e4407f69e4dbef19c20bce2045347ea6dc34
MapboxDirections: 7f36b3e9ef6a53fc997c114a341ab4da721756bd
MapboxMobileEvents: 2bc0ca2eedb627b73cf403258dce2b2fa98074a6
MapboxNavigation: 42bae50b0381dce317c85884ba0de38fc68a4814
MapboxNavigationNative: 50436c659f40d7f67ed8a60652c9d344f0e10e27
MapboxSpeech: 403415e932e084cf290b9d55c49ab7ea210b9595
Polyline: 0e9890790292741c8186201a536b6bb6a78d02dd
Solar: 2dc6e7cc39186cb0c8228fa08df76fb50c7d8f24
Turf: c6bdf62d6a70c647874f295dd1cf4eefc0c3e9e6
Turf: bdcfefe60df3ca8dc5f742681c178e47f8c5a567

PODFILE CHECKSUM: d4084fe664fbacd0cffd88ab45eaed1ad907ad1d

COCOAPODS: 1.7.5
COCOAPODS: 1.8.4
30 changes: 15 additions & 15 deletions MapboxCoreNavigationTests/RouteProgressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,22 @@ class RouteProgressTests: XCTestCase {
XCTAssertEqual(remainingWaypoints.count, 4,
"At the first via point before backtracking, all but the source and first via point should remain")

legProgress.currentStepProgress.distanceTraveled = LineString(coordinates).distance() / 2.0
legProgress.currentStepProgress.distanceTraveled = LineString(coordinates).distance()! / 2.0
remainingWaypoints = legProgress.remainingWaypoints(among: Array(options.waypoints.dropLast()))
XCTAssertEqual(remainingWaypoints.count, 2,
"At the via point where the leg backtracks, only the via points after backtracking should remain")

legProgress.currentStepProgress.distanceTraveled = LineString(coordinates).distance() / 2.0 + coordinates[3].distance(to: coordinates[4]) / 2.0
legProgress.currentStepProgress.distanceTraveled = LineString(coordinates).distance()! / 2.0 + coordinates[3].distance(to: coordinates[4]) / 2.0
remainingWaypoints = legProgress.remainingWaypoints(among: Array(options.waypoints.dropLast()))
XCTAssertEqual(remainingWaypoints.count, 2,
"Halfway to the via point where the leg backtracks, only the via points after backtracking should remain")

legProgress.currentStepProgress.distanceTraveled = LineString(coordinates).distance() / 2.0 + coordinates[3].distance(to: coordinates[4])
legProgress.currentStepProgress.distanceTraveled = LineString(coordinates).distance()! / 2.0 + coordinates[3].distance(to: coordinates[4])
remainingWaypoints = legProgress.remainingWaypoints(among: Array(options.waypoints.dropLast()))
XCTAssertEqual(remainingWaypoints.count, 1,
"At the first via point after backtracking, all but one of the via points after backtracking should remain")

legProgress.currentStepProgress.distanceTraveled = LineString(coordinates).distance()
legProgress.currentStepProgress.distanceTraveled = LineString(coordinates).distance()!
remainingWaypoints = legProgress.remainingWaypoints(among: Array(options.waypoints.dropLast()))
XCTAssertEqual(remainingWaypoints.count, 0,
"At the last via point after backtracking, nothing should remain")
Expand Down Expand Up @@ -243,32 +243,32 @@ class RouteProgressTests: XCTestCase {

XCTAssertEqual(legProgress.distanceTraveled, 0)
XCTAssertEqual(legProgress.currentSpeedLimit, Measurement(value: 10, unit: UnitSpeed.kilometersPerHour))
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[1]) / 2.0
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[1])! / 2.0
XCTAssertEqual(legProgress.currentSpeedLimit, Measurement(value: 10, unit: UnitSpeed.kilometersPerHour))

legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[1])
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[1])!
XCTAssertEqual(legProgress.currentSpeedLimit, Measurement(value: 20, unit: UnitSpeed.milesPerHour))
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[1]) + lineString.distance(from: coordinates[1], to: coordinates[2]) / 2.0
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[1])! + lineString.distance(from: coordinates[1], to: coordinates[2])! / 2.0
XCTAssertEqual(legProgress.currentSpeedLimit, Measurement(value: 20, unit: UnitSpeed.milesPerHour))

legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[2])
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[2])!
XCTAssertNil(legProgress.currentSpeedLimit)
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[2]) + lineString.distance(from: coordinates[2], to: coordinates[3]) / 2.0
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[2])! + lineString.distance(from: coordinates[2], to: coordinates[3])! / 2.0
XCTAssertNil(legProgress.currentSpeedLimit)

legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[3])
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[3])!
XCTAssertEqual(legProgress.currentSpeedLimit, Measurement(value: 40, unit: UnitSpeed.milesPerHour))
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[3]) + lineString.distance(from: coordinates[3], to: coordinates[4]) / 2.0
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[3])! + lineString.distance(from: coordinates[3], to: coordinates[4])! / 2.0
XCTAssertEqual(legProgress.currentSpeedLimit, Measurement(value: 40, unit: UnitSpeed.milesPerHour))

legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[4])
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[4])!
XCTAssertEqual(legProgress.currentSpeedLimit, Measurement(value: 50, unit: UnitSpeed.kilometersPerHour))
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[4]) + lineString.distance(from: coordinates[4], to: coordinates[5]) / 2.0
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[4])! + lineString.distance(from: coordinates[4], to: coordinates[5])! / 2.0
XCTAssertEqual(legProgress.currentSpeedLimit, Measurement(value: 50, unit: UnitSpeed.kilometersPerHour))

legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[5])
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[5])!
XCTAssertTrue(legProgress.currentSpeedLimit?.value.isInfinite ?? false)
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[5]) + (lineString.distance() - lineString.distance(to: coordinates[5])) / 2.0
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[5])! + (lineString.distance()! - lineString.distance(to: coordinates[5])!) / 2.0
XCTAssertTrue(legProgress.currentSpeedLimit?.value.isInfinite ?? false)
}
}
4 changes: 2 additions & 2 deletions MapboxNavigation-Documentation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ Pod::Spec.new do |s|
s.frameworks = ['CarPlay']

s.dependency "MapboxAccounts", "~> 2.2.0"
s.dependency "MapboxDirections", "~> 0.31.0"
s.dependency "MapboxDirections", "~> 0.32.0"
s.dependency "MapboxGeocoder.swift", "~> 0.10.0"
s.dependency "Mapbox-iOS-SDK", "~> 5.6"
s.dependency "MapboxMobileEvents", "~> 0.10.2"
s.dependency "MapboxNavigationNative", "= 9.0.4"
s.dependency "Solar", "~> 2.1"
s.dependency "Turf", "~> 0.3.0"
s.dependency "Turf", "~> 0.5.0"
s.dependency "MapboxSpeech", "~> 0.3.0"

s.swift_version = "5.0"
Expand Down
2 changes: 2 additions & 0 deletions MapboxNavigation/InstructionPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class InstructionPresenter {
?? NSAttributedString(string: text.text, attributes: defaultAttributes)
case .lane(_, _):
preconditionFailure("Lane component has no attributed string representation.")
case .guidanceView(_, let alternativeText):
return NSAttributedString(string: alternativeText.text, attributes: defaultAttributes)
}
}
let separator = NSAttributedString(string: " ", attributes: defaultAttributes)
Expand Down
Loading