turf-nearest-point-on-line: fix for points far away from the segment endpoints #2871
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2870; see that ticket for a description of the observed bug.
This patch fixes the described bug by adjusting how
nearestPointOnSegment
picks an endpoint when it determines that the nearest intersection of the great circles is not on the segment. Rather than doing work with angles, it just computes the distance to the two endpoints and picks the closer one.I think this is safe—it does not break any existing tests—and should not lead to a performance reduction (there are just as many calls to
distance
as there were before, and some vector math has been removed), but the algorithms here are a little bit outside of my wheelhouse, so I would certainly appreciate any feedback if there is something wrong. A more natural way of fixing the issue might be to correctly choose the right value ofI
in the section above the one I modified, but I can not quite figure out how to make that work.Thanks so much for turf and for your attention to this!
Please provide the following when creating a PR:
contributors
field ofpackage.json
- you've earned it! 👏