Skip to content

Commit 112ba9b

Browse files
author
Rohan Kumar
authored
Line3: Handle degenerate line in closestPointToPointParameter(). (#33264)
1 parent e584798 commit 112ba9b

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/math/Line3.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ class Line3 {
142142
_startEnd.subVectors( this.end, this.start );
143143

144144
const startEnd2 = _startEnd.dot( _startEnd );
145+
146+
if ( startEnd2 === 0 ) return 0;
147+
145148
const startEnd_startP = _startEnd.dot( _startP );
146149

147150
let t = startEnd_startP / startEnd2;

test/unit/src/math/Line3.tests.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ export default QUnit.module( 'Maths', () => {
161161
a.closestPointToPoint( one3.clone(), true, point );
162162
assert.ok( point.distanceTo( one3.clone() ) < 0.0001, 'Passed!' );
163163

164+
// degenerate line (zero-length)
165+
const b = new Line3( one3.clone(), one3.clone() );
166+
assert.ok( b.closestPointToPointParameter( zero3.clone(), true ) == 0, 'Passed!' );
167+
b.closestPointToPoint( zero3.clone(), true, point );
168+
assert.ok( point.distanceTo( one3.clone() ) < 0.0001, 'Passed!' );
169+
164170
} );
165171

166172
QUnit.test( 'applyMatrix4', ( assert ) => {

0 commit comments

Comments
 (0)