Skip to content

Commit 3578c0e

Browse files
committed
Use skip index
1 parent 3108291 commit 3578c0e

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

libnavigation-core/src/main/java/com/mapbox/navigation/core/replay/route/ReplayPolylineDecodeStream.kt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,11 @@ class ReplayPolylineDecodeStream(
9696
}
9797

9898
/**
99-
* Skip the next [minDistance] of the geometry. Similar to decode except that this does not
99+
* Skip the next [count] points of the geometry. Similar to decode except that this does not
100100
* hold any points in memory.
101101
*/
102-
fun skip(
103-
minDistance: Double,
104-
@TurfConstants.TurfUnitCriteria units: String = TurfConstants.UNIT_KILOMETERS
105-
) {
106-
var travelled = 0.0
107-
current?.let { if (minDistance > 0.0 && hasNext()) next() }
108-
while (travelled < minDistance && hasNext()) {
109-
val previous = current
110-
val next = next()
111-
travelled += previous?.let { TurfMeasurement.distance(previous, next, units) } ?: 0.0
112-
}
102+
fun skip(count: Int) {
103+
var skipped = 0
104+
while (skipped++ < count && hasNext()) { next() }
113105
}
114106
}

libnavigation-core/src/main/java/com/mapbox/navigation/core/replay/route/ReplayRouteSession.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.mapbox.navigation.core.replay.history.ReplayEventBase
1919
import com.mapbox.navigation.core.replay.history.ReplayEventUpdateLocation
2020
import com.mapbox.navigation.core.replay.history.ReplayEventsObserver
2121
import com.mapbox.navigation.core.trip.session.RouteProgressObserver
22+
import com.mapbox.navigation.utils.internal.logI
2223
import com.mapbox.navigation.utils.internal.logW
2324
import com.mapbox.turf.TurfConstants
2425
import java.util.*
@@ -156,9 +157,12 @@ class ReplayRouteSession : MapboxNavigationObserver {
156157
}
157158
return
158159
}
159-
val distanceTraveled = routeProgress.distanceTraveled.toDouble()
160160
polylineDecodeStream = ReplayPolylineDecodeStream(geometry, 6)
161-
polylineDecodeStream.skip(distanceTraveled, TurfConstants.UNIT_METERS)
161+
162+
// Skip up to the current geometry index. There is some imprecision here because the
163+
// distance traveled is not equal to a route index.
164+
polylineDecodeStream.skip(routeProgress.currentRouteGeometryIndex)
165+
162166
pushMorePoints()
163167
}
164168

0 commit comments

Comments
 (0)