fix(nearest-point-on-line): segmentIndex always returns i, add segment helper functions#3096
Open
feliperm17 wants to merge 3 commits into
Open
fix(nearest-point-on-line): segmentIndex always returns i, add segment helper functions#3096feliperm17 wants to merge 3 commits into
feliperm17 wants to merge 3 commits into
Conversation
Author
|
@smallsaucepan when you get a chance, would appreciate your review! Happy to adjust anything based on your feedback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #3023
Design discussion: #3022
Summary
segmentIndexnow always equals the indexiof the segment on which the nearest point was found. The legacy "favour the next segment" behaviour (returningi + 1when the nearest point lands exactly on an end vertex) has been removed entirely — for both intermediate vertices and the last vertex of a LineString. Three helper functions are added so callers can restore that behaviour when needed.Breaking change⚠️
Before:
After:
New helper functions
Three exported helpers allow callers to restore the previous behaviour or build their own logic (e.g. turn-by-turn navigation):
Tests
segmentIndex: 8 → 7expectation (intermediate vertex case, intentional breaking change).test/out/multiLine1.geojson:segmentIndex/index21 → 20(the only real value change; full fixture regen was discarded as it produced 34k lines of pure formatting noise with no value changes).atEndOfSegment/hasNextSegment+ legacy index reconstruction,atEndOfLineString, mid-segment, LineString↔MultiLineString parity via segment offsets, and helpers on bare geometry input.test:typespasses; eslint clean.Note for maintainers
packages/turf-line-slice/index.ts:69contains afixSegmentIndexBoundsworkaround that was added explicitly to handle this bug. It is now a harmless no-op. Removing it is out of scope for this PR but worth a follow-up.Checklist
contributorsfield ofpackage.json.