Skip to content

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

@Blafasel3

Description

@Blafasel3

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
      }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions