Skip to content

Commit 4535745

Browse files
authored
Merge pull request #4268 from mapbox/NAVIOS-763
Use the same algorithm for calculating distance to intersection as in distance traveled
2 parents c0dfd14 + e08a480 commit 4535745

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* Fixed an issue where the route progress could be incorrectly calculated for folding back route steps. ([#4234](https://github.com/mapbox/mapbox-navigation-ios/pull/4234))
5757
* `NavigationView.init(frame:tileStoreLocation:navigationMapView:)`, `NavigationView.navigationMapView`, `NavigationView.floatingStackView`, `NavigationView.floatingButtons`, `NavigationView.wayNameView`, `NavigationView.speedLimitView`, `NavigationView.topBannerContainerView` and `NavigationView.bottomBannerContainerView` are now publicly accessible. ([#4249](https://github.com/mapbox/mapbox-navigation-ios/pull/4249))
5858
* Fixed an issue where empty intersections of the current step could cause a crash. ([#4260](https://github.com/mapbox/mapbox-navigation-ios/pull/4260))
59+
* Fixed an issue where `RouteProgress.currentLegProgress.currentStepProgress.userDistanceToUpcomingIntersection` could be incorrectly calculated for folding back route steps. ([#4268](https://github.com/mapbox/mapbox-navigation-ios/pull/4268))
5960
* Deprecated `NavigationSettings.initialize(directions:tileStoreConfiguration:routingProviderSource:alternativeRouteDetectionStrategy:utilizeSensorData:navigatorPredictionInterval:liveIncidentsOptions:statusUpdatingSettings:)` method in favor of `NavigationSettings.initialize(with:)`. ([#4275](https://github.com/mapbox/mapbox-navigation-ios/pull/4275))
6061
* Added new parameter that allows configuring logging level for Mapbox SDKs. Checkout new `NavigationSettings.initialize(with:)` method for more information. ([#4275](https://github.com/mapbox/mapbox-navigation-ios/pull/4275))
6162
* Fixed an issue where the `UserHaloCourseView` will be shown under reduced location accuracy mode with `NavigationMapview.reducedAccuracyActivatedMode` as `false`. Right now `UserHaloCourseView` will be applied in only one case: when user explicitly sets `NavigationMapView.reducedAccuracyActivatedMode` to `true`, and the `Precise Location` property in the settings of current application is disabled by user. ([#4285](https://github.com/mapbox/mapbox-navigation-ios/pull/4285))

Sources/MapboxCoreNavigation/RouteController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ open class RouteController: NSObject {
388388
updateSpokenInstructionProgress(status: status, willReRoute: isRerouting)
389389
updateVisualInstructionProgress(status: status)
390390
updateRoadName(status: status)
391-
routeProgress.updateDistanceToIntersection(from: snappedLocation)
392-
391+
393392
rerouteAfterArrivalIfNeeded(snappedLocation, status: status)
394393

395394
if status.routeState != .complete {
@@ -507,6 +506,7 @@ open class RouteController: NSObject {
507506

508507
private func update(progress: RouteProgress, status: NavigationStatus, with location: CLLocation, rawLocation: CLLocation, upcomingRouteAlerts routeAlerts: [UpcomingRouteAlert], mapMatchingResult: MapMatchingResult, routeShapeIndex: Int) {
509508
progress.updateDistanceTraveled(navigationStatus: status)
509+
510510
progress.upcomingRouteAlerts = routeAlerts.map { RouteAlert($0) }
511511
progress.shapeIndex = routeShapeIndex
512512

Sources/MapboxCoreNavigation/RouteProgress.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ open class RouteProgress: Codable {
164164
intersectionIndex: currentLegProgress.currentStepProgress.intersectionIndex)
165165
calculateLegsCongestion()
166166
updateDistanceTraveled(with: location)
167-
updateDistanceToIntersection(from: location)
168167
}
169168

170169
/**
@@ -200,24 +199,31 @@ open class RouteProgress: Codable {
200199
else {
201200
updateDistanceTraveled(with: .init(navigationStatus.location))
202201
}
202+
updateDistanceToIntersection()
203203
}
204204

205205
/**
206206
Update the distance to intersection according to new location specified.
207207
- parameter location: Updated user location.
208208
*/
209-
func updateDistanceToIntersection(from location: CLLocation) {
209+
private func updateDistanceToIntersection() {
210210
guard var intersections = currentLegProgress.currentStepProgress.step.intersections else { return }
211211

212212
// The intersections array does not include the upcoming maneuver intersection.
213213
if let upcomingIntersection = currentLegProgress.upcomingStep?.intersections?.first {
214214
intersections += [upcomingIntersection]
215215
}
216216
currentLegProgress.currentStepProgress.intersectionsIncludingUpcomingManeuverIntersection = intersections
217-
217+
218218
if let shape = currentLegProgress.currentStep.shape,
219-
let upcomingIntersection = currentLegProgress.currentStepProgress.upcomingIntersection {
220-
currentLegProgress.currentStepProgress.userDistanceToUpcomingIntersection = shape.distance(from: location.coordinate, to: upcomingIntersection.location)
219+
let upcomingIntersection = currentLegProgress.currentStepProgress.upcomingIntersection,
220+
let coordinateOnStep = shape.coordinateFromStart(
221+
distance: currentLegProgress.currentStepProgress.distanceTraveled
222+
) {
223+
currentLegProgress.currentStepProgress.userDistanceToUpcomingIntersection = shape.distance(
224+
from: coordinateOnStep,
225+
to: upcomingIntersection.location
226+
)
221227
}
222228

223229
updateIntersectionDistances()

Tests/MapboxCoreNavigationTests/Progress/RouteProgressTests.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import TestHelper
66
import struct Polyline.Polyline
77
import Turf
88
@testable import MapboxCoreNavigation
9+
import MapboxNavigationNative
910

1011
class RouteProgressTests: TestCase {
1112

@@ -297,6 +298,50 @@ class RouteProgressTests: TestCase {
297298
legProgress.currentStepProgress.distanceTraveled = lineString.distance(to: coordinates[5])! + (lineString.distance()! - lineString.distance(to: coordinates[5])!) / 2.0
298299
XCTAssertTrue(legProgress.currentSpeedLimit?.value.isInfinite ?? false)
299300
}
301+
302+
func testDistanceToIntersection() {
303+
func navigationState(stepDistanceTraveled: CLLocationDistance) -> NavigationStatus {
304+
.init(
305+
routeState: .tracking,
306+
locatedAlternativeRouteId: nil,
307+
stale: false,
308+
location: .init(.init()),
309+
routeIndex: 0,
310+
legIndex: 0,
311+
step: 0,
312+
isFallback: false,
313+
inTunnel: false,
314+
predicted: 0,
315+
geometryIndex: 0,
316+
shapeIndex: 0,
317+
intersectionIndex: 0,
318+
roads: [],
319+
voiceInstruction: nil,
320+
bannerInstruction: nil,
321+
speedLimit: nil,
322+
keyPoints: [],
323+
mapMatcherOutput: .init(matches: [], isTeleport: false),
324+
offRoadProba: 0,
325+
activeGuidanceInfo: .init(
326+
routeProgress: .init(distanceTraveled: 0, fractionTraveled: 0, remainingDistance: 0, remainingDuration: 0),
327+
legProgress: .init(distanceTraveled: 0, fractionTraveled: 0, remainingDistance: 0, remainingDuration: 0),
328+
step: .init(distanceTraveled: stepDistanceTraveled, fractionTraveled: 0, remainingDistance: 0, remainingDuration: 0)
329+
),
330+
upcomingRouteAlerts: [],
331+
nextWaypointIndex: 0,
332+
layer: nil
333+
)
334+
}
335+
336+
let routeProgress = RouteProgress(route: route, options: routeOptions)
337+
routeProgress.updateDistanceTraveled(navigationStatus: navigationState(stepDistanceTraveled: 0))
338+
XCTAssertEqual(round(routeProgress.currentLegProgress.currentStepProgress.userDistanceToUpcomingIntersection ?? 0), 81)
339+
340+
// `updateDistanceTraveled` only reads `activeGuidanceInfo.step.distanceTraveled`, so it is the only valid data
341+
// we must provide here.
342+
routeProgress.updateDistanceTraveled(navigationStatus: navigationState(stepDistanceTraveled: 50))
343+
XCTAssertEqual(round(routeProgress.currentLegProgress.currentStepProgress.userDistanceToUpcomingIntersection ?? 0), 31)
344+
}
300345

301346
func testRouteProggressCodable() {
302347
let routeProgress = RouteProgress(route: route,

0 commit comments

Comments
 (0)