mapbox-java
mapbox-java copied to clipboard
TurfMisc#nearestPointOnLine index is not correct in some cases
We encountered following problem in our project:
When we pass a list to the above mentioned method and if the last point in the list is the closest point, the index returned by the matching feature is List.size - 2 .
I would expect the index to be List.size - 1.
In the following code snippet the index seems not to be set correctly: https://github.com/mapbox/mapbox-java/blob/main/services-turf/src/main/java/com/mapbox/turf/TurfMisc.java#L336-L339
Imo it should say
if ((double) stop.getNumberProperty("dist")
< (double) closestPt.getNumberProperty("dist")) {
closestPt = stop;
closestPt.addNumberProperty(INDEX_KEY, i + 1); // the index of the closest point is i + 1, not i
}