Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TurfMisc#nearestPointOnLine index is not correct in some cases #1594

Open
Blafasel3 opened this issue Sep 17, 2024 · 0 comments
Open

TurfMisc#nearestPointOnLine index is not correct in some cases #1594

Blafasel3 opened this issue Sep 17, 2024 · 0 comments

Comments

@Blafasel3
Copy link

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
      }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant