Skip to content

Commit 3f0dc82

Browse files
committed
NAVAND-925: fix IllegalArgumentException in ConstantVelocityInterpolator
1 parent 03d1fc0 commit 3f0dc82

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Mapbox welcomes participation and contributions from everyone.
66
#### Features
77
#### Bug fixes and improvements
88
- Fixed crash in `PermissionsLauncherFragment` occurring on device rotation. [#6635](https://github.com/mapbox/mapbox-navigation-android/pull/6635)
9+
- Fixed a rare `java.lang.IllegalArgumentException: The Path cannot loop back on itself.` exception when using `NavigationLocationProvider`. [#6641](https://github.com/mapbox/mapbox-navigation-android/pull/6641)
910

1011
## Mapbox Navigation SDK 2.9.2 - 18 November, 2022
1112
### Changelog

libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/internal/location/ConstantVelocityInterpolator.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ class ConstantVelocityInterpolator(
4545

4646
private fun timingPath(distances: List<Double>, total: Double): Path {
4747
val path = Path()
48-
val step = 1.0f / distances.size
49-
var pathTime = 0.0f
48+
val step = 1.0 / distances.size
49+
var pathTime = 0.0
5050
// NOTE: The Path must start at (0,0) and end at (1,1)
5151
// To avoid PathInterpolator IllegalArgException, we ignore last keypoint distance value
5252
// and manually add line to (1,1).
5353
for (i in 0..distances.size - 2) {
5454
val deltaTime = distances[i] / total
55-
pathTime += deltaTime.toFloat()
56-
path.lineTo(pathTime, (step * (i + 1)))
55+
pathTime += deltaTime
56+
if (pathTime > 1.0) {
57+
pathTime = 1.0
58+
}
59+
path.lineTo(pathTime.toFloat(), (step * (i + 1)).toFloat())
5760
}
5861
path.lineTo(1f, 1f)
5962
return path

libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/internal/location/ConstantVelocityInterpolatorTest.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,29 @@ class ConstantVelocityInterpolatorTest {
7272
)
7373
}
7474

75+
@Test
76+
fun `should not crash because of error accumulation`() { // caused by NAVAND-925
77+
val startPoint = Point.fromLngLat(48.36654772857354, 11.13222120183356)
78+
val keyPoints = arrayOf(
79+
Point.fromLngLat(48.416596, 11.027287),
80+
Point.fromLngLat(48.416520999999996, 11.027080999999999),
81+
Point.fromLngLat(48.416281, 11.02683),
82+
Point.fromLngLat(48.416156, 11.02656),
83+
Point.fromLngLat(48.416146999999995, 11.026156),
84+
Point.fromLngLat(48.416205999999995, 11.02605),
85+
Point.fromLngLat(48.416253, 11.025912),
86+
Point.fromLngLat(48.416194, 11.025749),
87+
Point.fromLngLat(48.416028, 11.025495999999999),
88+
Point.fromLngLat(48.415786, 11.025307),
89+
Point.fromLngLat(48.415642999999996, 11.025171),
90+
Point.fromLngLat(48.4156, 11.025034),
91+
Point.fromLngLat(48.415535999999996, 11.024955),
92+
Point.fromLngLat(48.415535999999996, 11.024955000000004),
93+
)
94+
// no crash
95+
ConstantVelocityInterpolator(startPoint, keyPoints)
96+
}
97+
7598
private fun calculatePathValues(p0: Point, vararg points: Point): List<Pair<Float, Float>> {
7699
val distances = mutableListOf<Double>()
77100
var totalDistance = 0.0

0 commit comments

Comments
 (0)