Просмотр исходного кода

Line3: Handle degenerate line in `closestPointToPointParameter()`. (#33264)

Rohan Kumar 2 недель назад
Родитель
Сommit
112ba9b71c
2 измененных файлов с 9 добавлено и 0 удалено
  1. 3 0
      src/math/Line3.js
  2. 6 0
      test/unit/src/math/Line3.tests.js

+ 3 - 0
src/math/Line3.js

@@ -142,6 +142,9 @@ class Line3 {
 		_startEnd.subVectors( this.end, this.start );
 
 		const startEnd2 = _startEnd.dot( _startEnd );
+
+		if ( startEnd2 === 0 ) return 0;
+
 		const startEnd_startP = _startEnd.dot( _startP );
 
 		let t = startEnd_startP / startEnd2;

+ 6 - 0
test/unit/src/math/Line3.tests.js

@@ -161,6 +161,12 @@ export default QUnit.module( 'Maths', () => {
 			a.closestPointToPoint( one3.clone(), true, point );
 			assert.ok( point.distanceTo( one3.clone() ) < 0.0001, 'Passed!' );
 
+			// degenerate line (zero-length)
+			const b = new Line3( one3.clone(), one3.clone() );
+			assert.ok( b.closestPointToPointParameter( zero3.clone(), true ) == 0, 'Passed!' );
+			b.closestPointToPoint( zero3.clone(), true, point );
+			assert.ok( point.distanceTo( one3.clone() ) < 0.0001, 'Passed!' );
+
 		} );
 
 		QUnit.test( 'applyMatrix4', ( assert ) => {

粤ICP备19079148号