stadiamaps / ferrostar

A FOSS navigation SDK built from the ground up for the future
https://stadiamaps.github.io/ferrostar/
Other
184 stars 24 forks source link

Fix incorrect geometry index after advancing #357

Closed ahmedre closed 1 week ago

ahmedre commented 2 weeks ago

After advancing the step, the geometry index sometimes incorrectly refers to an index in the previous RouteStep instead of the current one. This patch recomputes the geometry index when the RouteSteps change.

ahmedre commented 2 weeks ago

I have no idea if this is the ideal fix or not, but I saw this case while testing, where, while logging:

               "metadata: " +
                    navigatingState.tripState.remainingSteps.size +
                    " remaining steps, current index; " +
                    navigatingState.tripState.currentStepGeometryIndex +
                    " geometry size " +
                    navigatingState.tripState.remainingSteps.firstOrNull()?.geometry?.size

I saw a case where the geometry index was greater than the geometry size (and, at that point, the current remaining steps size had decreased by 1). Looking at the code, it seems that there's no re-computation of the current step geometry index after the current step changes, causing this to be incorrect.

ahmedre commented 2 weeks ago

CleanShot 2024-11-12 at 22 45 13@2x

ahmedre commented 1 week ago

Thanks - I was doing the recalculation in the wrong function (in the advance function). The caller actually disregards all fields it isn't interested in, and the comment actually says that this is by design, since the caller should re-compute whatever it needs to.