Skip to content

Commit 12ab92e

Browse files
committed
NAVAND-1152: fix alternative route geometry index calculation for not started alternatives
1 parent 2cf891a commit 12ab92e

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed an issue where alternative routes refresh might have finished with response code 422.

libnavigation-core/src/main/java/com/mapbox/navigation/core/routealternatives/AlternativeRouteProgressDataProvider.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ internal object AlternativeRouteProgressDataProvider {
2424
legIndex = primaryRouteProgressData.legIndex - legIndexDiff
2525
val routeGeometryIndexDiff =
2626
primaryFork.geometryIndexInRoute - alternativeFork.geometryIndexInRoute
27-
routeGeometryIndex =
27+
val alternativeStarted =
28+
primaryRouteProgressData.routeGeometryIndex >= routeGeometryIndexDiff
29+
routeGeometryIndex = if (alternativeStarted) {
2830
primaryRouteProgressData.routeGeometryIndex - routeGeometryIndexDiff
31+
} else {
32+
0
33+
}
2934
legGeometryIndex = routeGeometryIndex -
3035
prevLegsGeometryIndicesCount(alternativeMetadata.navigationRoute, legIndex)
3136
} else {

libnavigation-core/src/test/java/com/mapbox/navigation/core/routealternatives/AlternativeRouteProgressDataProviderTest.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,31 @@ class AlternativeRouteProgressDataProviderTest {
107107
assertEquals(expected, actual)
108108
}
109109

110+
@Test
111+
fun `before fork, alternative starts after the primary route ahead of current position`() =
112+
coroutineRule.runBlockingTest {
113+
val primaryRouteProgressData = RouteProgressData(0, 3, 3)
114+
val alternativeMetadata = alternativeRouteMetadata(
115+
primaryForkLegIndex = 0,
116+
primaryForkRouteGeometryIndex = 100,
117+
primaryForkLegGeometryIndex = 100,
118+
alternativeForkLegIndex = 0,
119+
alternativeForkRouteGeometryIndex = 80,
120+
alternativeForkLegGeometryIndex = 80,
121+
listOf(
122+
listOf(List(10) { mockk() }, List(7) { mockk() }, List(15) { mockk() }),
123+
)
124+
)
125+
val expected = RouteProgressData(0, 0, 0)
126+
127+
val actual = AlternativeRouteProgressDataProvider.getRouteProgressData(
128+
primaryRouteProgressData,
129+
alternativeMetadata
130+
)
131+
132+
assertEquals(expected, actual)
133+
}
134+
110135
@Test
111136
fun `before fork, alternative starts together with the primary route`() = coroutineRule.runBlockingTest {
112137
val primaryRouteProgressData = RouteProgressData(4, 200, 30)

0 commit comments

Comments
 (0)