When calling nearestPointOnLine and the result is at the end of a segment, there is legacy behaviour that sets the segmentIndex to that of the next segment (end point of one segment being the same as the start point of the next). Unsure why this is the behaviour.
Unfortunately, if the original segment was the last in the lineString the segmentIndex is still incremented meaning it now refers to a non-existent segment.
After fixing #2946 with PR #2951, it became apparent in #3008 some users were using the overflowing segmentIndex as an indicator for whether the nearest point was found at the end of the line. Although undocumented, this caused backwards compatibility issues and will be reverted.
This issue aims to fix the problem properly as a breaking change aligned with a major release. Current plan is to:
- ensure segmentIndex always refers to a valid segment
- clarify remaining behaviour in Document nearestPointOnLine behaviour for v8 #3022