Skip to content

fix(math): geomLineIntersection returns null when segments share a start point#309

Merged
bhousel merged 1 commit into
mainfrom
fix/geomLineIntersection-coincident-endpoints
Jun 27, 2026
Merged

fix(math): geomLineIntersection returns null when segments share a start point#309
bhousel merged 1 commit into
mainfrom
fix/geomLineIntersection-coincident-endpoints

Conversation

@bhousel

@bhousel bhousel commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

Problem

geomLineIntersection returned null when a0 and b0 are the same point, even though the intersection is well-defined (it's that shared point).

Root cause: when a0 === b0, both qpx and qpy are 0, so uNumerator = 0. The condition:

if (uNumerator && denominator) {

treated a falsy uNumerator as a reason to skip the check entirely — but u = 0 is a perfectly valid intersection parameter (the intersection is at t = 0, u = 0, i.e. the shared start point).

Fix

Only gate on denominator (which being zero means the segments are parallel). A zero uNumerator simply means u = 0, which is within the valid [0, 1] range.

// before
if (uNumerator && denominator) {

// after
if (denominator) {

Test

Added a regression test using real-world geographic coordinates where a0 and b0 are coincident.

…art point

When a0 === b0, qpx and qpy are both 0, making uNumerator = 0.
The condition `if (uNumerator && denominator)` treated a falsy uNumerator
as a reason to skip the intersection check entirely — but u = 0 is a
valid intersection at t = 0, u = 0 (the shared start point).

Fix: only gate on `denominator` (parallel segments). A zero uNumerator
just means u = 0, which is within the valid [0, 1] range.

Adds a regression test with real-world geographic coordinates where
a0 and b0 are coincident.
@bhousel
bhousel merged commit 5934b8a into main Jun 27, 2026
1 check passed
@bhousel
bhousel deleted the fix/geomLineIntersection-coincident-endpoints branch June 27, 2026 01:36
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

Successfully merging this pull request may close these issues.

1 participant