Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* Fixed an issue where `UserPuckCourseView`’s color desaturated during turn-by-turn navigation even as the location was being updated. ([#3836](https://github.com/mapbox/mapbox-navigation-ios/pull/3836))
* Fixed an issue where the `PassiveLocationManager(directions:systemLocationManager:eventsManagerType:userInfo:datasetProfileIdentifier:)` initializer’s `datasetProfileIdentifier` argument was ignored. ([#3867](https://github.com/mapbox/mapbox-navigation-ios/pull/3867))
* Fixed an issue where the user location was sometimes snapped to a parallel street just before it merges with the actual street. ([#3862](https://github.com/mapbox/mapbox-navigation-ios/pull/3862))
* Fix the possible crash after rerouting when `routeLineTracksTraversal` enabled. ([#3896](https://github.com/mapbox/mapbox-navigation-ios/pull/3896))

### Routing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension NavigationMapView {
if currentStepProgress.distanceTraveled <= 0 {
allRemainingPoints += currentLegSteps[currentLegProgress.stepIndex].dropLast().count
} else if let startIndex = lineString.indexedCoordinateFromStart(distance: currentStepProgress.distanceTraveled)?.index,
startIndex < lineString.coordinates.endIndex - 1 {
lineString.coordinates.indices.contains(startIndex) {
allRemainingPoints += lineString.coordinates.suffix(from: startIndex + 1).dropLast().count
}

Expand Down Expand Up @@ -154,7 +154,7 @@ extension NavigationMapView {
func updateFractionTraveled(coordinate: CLLocationCoordinate2D) {
guard let granularDistances = routeLineGranularDistances,
let index = routeRemainingDistancesIndex,
index < granularDistances.distanceArray.endIndex else { return }
granularDistances.distanceArray.indices.contains(index) else { return }
let traveledIndex = granularDistances.distanceArray[index]
let upcomingPoint = traveledIndex.point

Expand Down
53 changes: 53 additions & 0 deletions Tests/MapboxNavigationTests/VanishingRouteLineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ class VanishingRouteLineTests: TestCase {
return routeProgress
}

func getEmptyRoute() -> Route {
let route = getRoute()
let routeLeg = route.legs.first!
let emptySteps = routeLeg.steps.map { (routeStep: RouteStep) -> RouteStep in
routeStep.shape?.coordinates = []
return routeStep
}
let emptyLeg = RouteLeg(steps: emptySteps,
name: routeLeg.name,
distance: routeLeg.distance,
expectedTravelTime: routeLeg.expectedTravelTime,
profileIdentifier: routeLeg.profileIdentifier)
let emptyRoute = Route(legs: [emptyLeg], shape: route.shape, distance: route.distance, expectedTravelTime: route.expectedTravelTime)
return emptyRoute
}

func getUnstartedRouteProgress(route: Route) -> RouteProgress {
let routeProgress = RouteProgress(route: route, options: routeOptions, legIndex: 0, spokenInstructionIndex: 0)
routeProgress.currentLegProgress = RouteLegProgress(leg: route.legs[0], stepIndex: 0, spokenInstructionIndex: 0)
routeProgress.currentLegProgress.currentStepProgress = RouteStepProgress(step: route.legs[0].steps[0], spokenInstructionIndex: 0)
routeProgress.currentLegProgress.currentStepProgress.distanceTraveled = 0.0
return routeProgress
}

func lineGradientToString(lineGradient: Value<StyleColor>?) -> String {
guard let halfStringFromLineGradient = lineGradient.debugDescription.components(separatedBy: "(").last,
let stringFromLineGradient = halfStringFromLineGradient.components(separatedBy: ")").first else {
Expand Down Expand Up @@ -142,6 +166,35 @@ class VanishingRouteLineTests: TestCase {
XCTAssertEqual(navigationMapView.fractionTraveled, expectedFractionTraveled, accuracy: 0.0000000001)
}

func testEmptyRouteWithValidRouteProgress() {
let routeProgress = getRouteProgress()
let route = getEmptyRoute()

let coordinate = CLLocationCoordinate2DMake(-122.5237429, 37.975393)
navigationMapView.routeLineTracksTraversal = true
navigationMapView.show([route])
navigationMapView.updateUpcomingRoutePointIndex(routeProgress: routeProgress)
navigationMapView.updateFractionTraveled(coordinate: coordinate)

// Route without coordinates inside its steps would lead to invalid routeRemainingDistancesIndex.
XCTAssertEqual(navigationMapView.routeRemainingDistancesIndex, -1)
XCTAssertEqual(navigationMapView.fractionTraveled, 0.0, accuracy: 0)
}

func testUnstartedRouteProgressWithValidRoute() {
let route = getRoute()
let routeProgress = getUnstartedRouteProgress(route: route)

let coordinate = CLLocationCoordinate2DMake(-122.5237429, 37.975393)
navigationMapView.routeLineTracksTraversal = true
navigationMapView.show([route])
navigationMapView.updateUpcomingRoutePointIndex(routeProgress: routeProgress)
navigationMapView.updateFractionTraveled(coordinate: coordinate)

XCTAssert(navigationMapView.routeRemainingDistancesIndex! >= 0, "Non-empty route should have valid routeRemainingDistancesIndex.")
XCTAssertEqual(navigationMapView.fractionTraveled, 0.0, accuracy: 0)
}

func disabled_UpdateRouteLineWithDifferentDistance() {
let routeProgress = getRouteProgress()
let route = routeProgress.route
Expand Down