Line3: Fix closest point for degenerate segments in `distanceSqToLine3()`. by kwy404 · Pull Request #34673 · mrdoob/three.js · GitHub
Skip to content

Line3: Fix closest point for degenerate segments in distanceSqToLine3(). - #34673

Merged
Mugen87 merged 1 commit into
mrdoob:devfrom
kwy404:line3-degenerate-closest-point
Sep 27, 2026
Merged

Mugen87 merged 1 commit into
mrdoob:devfrom
kwy404:line3-degenerate-closest-point

Conversation

@kwy404

@kwy404 kwy404 commented Sep 27, 2026

Copy link
Copy Markdown

Related issue: #32876

Description

Line3.distanceSqToLine3() writes the closest points into the optional c1 and c2 targets. When both segments are degenerate (start equals end), the early return computes the distance with c1.sub( c2 ), so c1 ends up holding p1 - p2 instead of the closest point on this segment. #32878 fixed the same problem for the general case, but this branch was left unchanged.

The fix keeps c1 and c2 as the two points and returns c1.distanceToSquared( c2 ), like the general case does.

The distanceSqToLine3 unit test now covers two degenerate segments and checks c1 and c2. It fails on dev (c1 is (-1, -1, -1) instead of (1, 1, 1)) and passes with this change.

@github-actions

Copy link
Copy Markdown

@Mugen87
Mugen87 merged commit 9b02bfe into mrdoob:dev Sep 27, 2026
10 checks passed
@Mugen87 Mugen87 added this to the r187 milestone Sep 27, 2026
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.

2 participants