Selaa lähdekoodia

Merge pull request #13550 from Mugen87/dev4

Tests: Added target parameter Part I
Mr.doob 7 vuotta sitten
vanhempi
commit
d3c3abe1cb

+ 2 - 0
test/three.source.unit.js

@@ -2,6 +2,8 @@
  * @author TristanVALCKE / https://github.com/Itee
  */
 
+import './unit/qunit-utils.js';
+
 //src
 import './unit/src/constants.tests';
 import './unit/src/polyfills.tests';

+ 54 - 30
test/unit/src/math/Box2.tests.js

@@ -113,65 +113,72 @@ export default QUnit.module( 'Maths', () => {
 		QUnit.test( "getCenter", ( assert ) => {
 
 			var a = new Box2( zero2.clone(), zero2.clone() );
-
-			assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
+			var center = new Vector2();
+			assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );
 
 			var a = new Box2( zero2, one2 );
 			var midpoint = one2.clone().multiplyScalar( 0.5 );
-			assert.ok( a.getCenter().equals( midpoint ), "Passed!" );
+			assert.ok( a.getCenter( center ).equals( midpoint ), "Passed!" );
 
 		} );
 
 		QUnit.test( "getSize", ( assert ) => {
 
 			var a = new Box2( zero2.clone(), zero2.clone() );
+			var size = new Vector2();
 
-			assert.ok( a.getSize().equals( zero2 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );
 
 			var a = new Box2( zero2.clone(), one2.clone() );
-			assert.ok( a.getSize().equals( one2 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( one2 ), "Passed!" );
 
 		} );
 
 		QUnit.test( "expandByPoint", ( assert ) => {
 
 			var a = new Box2( zero2.clone(), zero2.clone() );
+			var size = new Vector2();
+			var center = new Vector2();
 
 			a.expandByPoint( zero2 );
-			assert.ok( a.getSize().equals( zero2 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );
 
 			a.expandByPoint( one2 );
-			assert.ok( a.getSize().equals( one2 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( one2 ), "Passed!" );
 
 			a.expandByPoint( one2.clone().negate() );
-			assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
-			assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
+			assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );
 
 		} );
 
 		QUnit.test( "expandByVector", ( assert ) => {
 
 			var a = new Box2( zero2.clone(), zero2.clone() );
+			var size = new Vector2();
+			var center = new Vector2();
 
 			a.expandByVector( zero2 );
-			assert.ok( a.getSize().equals( zero2 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );
 
 			a.expandByVector( one2 );
-			assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
-			assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
+			assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );
 
 		} );
 
 		QUnit.test( "expandByScalar", ( assert ) => {
 
 			var a = new Box2( zero2.clone(), zero2.clone() );
+			var size = new Vector2();
+			var center = new Vector2();
 
 			a.expandByScalar( 0 );
-			assert.ok( a.getSize().equals( zero2 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( zero2 ), "Passed!" );
 
 			a.expandByScalar( 1 );
-			assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
-			assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
+			assert.ok( a.getCenter( center ).equals( zero2 ), "Passed!" );
 
 		} );
 
@@ -210,12 +217,19 @@ export default QUnit.module( 'Maths', () => {
 			var a = new Box2( zero2.clone(), one2.clone() );
 			var b = new Box2( one2.clone().negate(), one2.clone() );
 
-			assert.ok( a.getParameter( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
-			assert.ok( a.getParameter( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
+			var parameter = new Vector2();
+
+			a.getParameter( zero2, parameter );
+			assert.ok( parameter.equals( zero2 ), "Passed!" );
+			a.getParameter( one2, parameter );
+			assert.ok( parameter.equals( one2 ), "Passed!" );
 
-			assert.ok( b.getParameter( new Vector2( - 1, - 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
-			assert.ok( b.getParameter( new Vector2( 0, 0 ) ).equals( new Vector2( 0.5, 0.5 ) ), "Passed!" );
-			assert.ok( b.getParameter( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
+			b.getParameter( one2.clone().negate(), parameter );
+			assert.ok( parameter.equals( zero2 ), "Passed!" );
+			b.getParameter( zero2, parameter );
+			assert.ok( parameter.equals( new Vector2( 0.5, 0.5 ) ), "Passed!" );
+			b.getParameter( one2, parameter );
+			assert.ok( parameter.equals( one2 ), "Passed!" );
 
 		} );
 
@@ -233,7 +247,7 @@ export default QUnit.module( 'Maths', () => {
 			assert.ok( c.intersectsBox( a ), "Passed!" );
 			assert.ok( b.intersectsBox( c ), "Passed!" );
 
-			b.translate( new Vector2( 2, 2 ) );
+			b.translate( two2 );
 			assert.ok( ! a.intersectsBox( b ), "Passed!" );
 			assert.ok( ! b.intersectsBox( a ), "Passed!" );
 			assert.ok( ! b.intersectsBox( c ), "Passed!" );
@@ -245,15 +259,25 @@ export default QUnit.module( 'Maths', () => {
 			var a = new Box2( zero2.clone(), zero2.clone() );
 			var b = new Box2( one2.clone().negate(), one2.clone() );
 
-			assert.ok( a.clampPoint( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
-			assert.ok( a.clampPoint( new Vector2( 1, 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
-			assert.ok( a.clampPoint( new Vector2( - 1, - 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
-
-			assert.ok( b.clampPoint( new Vector2( 2, 2 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
-			assert.ok( b.clampPoint( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
-			assert.ok( b.clampPoint( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
-			assert.ok( b.clampPoint( new Vector2( - 1, - 1 ) ).equals( new Vector2( - 1, - 1 ) ), "Passed!" );
-			assert.ok( b.clampPoint( new Vector2( - 2, - 2 ) ).equals( new Vector2( - 1, - 1 ) ), "Passed!" );
+			var point = new Vector2();
+
+			a.clampPoint( zero2, point );
+			assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );
+			a.clampPoint( one2, point );
+			assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );
+			a.clampPoint( one2.clone().negate(), point );
+			assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );
+
+			b.clampPoint( two2, point );
+			assert.ok( point.equals( new Vector2( 1, 1 ) ), "Passed!" );
+			b.clampPoint( one2, point );
+			assert.ok( point.equals( new Vector2( 1, 1 ) ), "Passed!" );
+			b.clampPoint( zero2, point );
+			assert.ok( point.equals( new Vector2( 0, 0 ) ), "Passed!" );
+			b.clampPoint( one2.clone().negate(), point );
+			assert.ok( point.equals( new Vector2( - 1, - 1 ) ), "Passed!" );
+			b.clampPoint( two2.clone().negate(), point );
+			assert.ok( point.equals( new Vector2( - 1, - 1 ) ), "Passed!" );
 
 		} );
 

+ 72 - 37
test/unit/src/math/Box3.tests.js

@@ -122,20 +122,31 @@ export default QUnit.module( 'Maths', () => {
 
 			var a = new Box3( zero3.clone(), one3.clone() );
 			var b = a.clone();
+			var centerA = new Vector3();
+			var sizeA = new Vector3();
+			var sizeB = new Vector3();
 			var newCenter = one3;
 			var newSize = two3;
 
-			a.setFromCenterAndSize( a.getCenter(), a.getSize() );
+			a.getCenter( centerA );
+			a.getSize( sizeA );
+			a.setFromCenterAndSize( centerA, sizeA );
 			assert.ok( a.equals( b ), "Same values: no changes" );
 
-			a.setFromCenterAndSize( newCenter, a.getSize() );
-			assert.ok( a.getCenter().equals( newCenter ), "Move center: correct new center" );
-			assert.ok( a.getSize().equals( b.getSize() ), "Move center: no change in size" );
+			a.setFromCenterAndSize( newCenter, sizeA );
+			a.getCenter( centerA );
+			a.getSize( sizeA );
+			b.getSize( sizeB );
+
+			assert.ok( centerA.equals( newCenter ), "Move center: correct new center" );
+			assert.ok( sizeA.equals( sizeB ), "Move center: no change in size" );
 			assert.notOk( a.equals( b ), "Move center: no longer equal to old values" );
 
-			a.setFromCenterAndSize( a.getCenter(), newSize );
-			assert.ok( a.getCenter().equals( newCenter ), "Resize: no change to center" );
-			assert.ok( a.getSize().equals( newSize ), "Resize: correct new size" );
+			a.setFromCenterAndSize( centerA, newSize );
+			a.getCenter( centerA );
+			a.getSize( sizeA );
+			assert.ok( centerA.equals( newCenter ), "Resize: no change to center" );
+			assert.ok( sizeA.equals( newSize ), "Resize: correct new size" );
 			assert.notOk( a.equals( b ), "Resize: no longer equal to old values" );
 
 		} );
@@ -197,65 +208,73 @@ export default QUnit.module( 'Maths', () => {
 		QUnit.test( "getCenter", ( assert ) => {
 
 			var a = new Box3( zero3.clone(), zero3.clone() );
+			var center = new Vector3();
 
-			assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
+			assert.ok( a.getCenter( center ).equals( zero3 ), "Passed!" );
 
 			var a = new Box3( zero3.clone(), one3.clone() );
 			var midpoint = one3.clone().multiplyScalar( 0.5 );
-			assert.ok( a.getCenter().equals( midpoint ), "Passed!" );
+			assert.ok( a.getCenter( center ).equals( midpoint ), "Passed!" );
 
 		} );
 
 		QUnit.test( "getSize", ( assert ) => {
 
 			var a = new Box3( zero3.clone(), zero3.clone() );
+			var size = new Vector3();
 
-			assert.ok( a.getSize().equals( zero3 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( zero3 ), "Passed!" );
 
 			var a = new Box3( zero3.clone(), one3.clone() );
-			assert.ok( a.getSize().equals( one3 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( one3 ), "Passed!" );
 
 		} );
 
 		QUnit.test( "expandByPoint", ( assert ) => {
 
 			var a = new Box3( zero3.clone(), zero3.clone() );
+			var center = new Vector3();
+			var size = new Vector3();
 
 			a.expandByPoint( zero3 );
-			assert.ok( a.getSize().equals( zero3 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( zero3 ), "Passed!" );
 
 			a.expandByPoint( one3 );
-			assert.ok( a.getSize().equals( one3 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( one3 ), "Passed!" );
 
 			a.expandByPoint( one3.clone().negate() );
-			assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
-			assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
+			assert.ok( a.getCenter( center ).equals( zero3 ), "Passed!" );
 
 		} );
 
 		QUnit.test( "expandByVector", ( assert ) => {
 
 			var a = new Box3( zero3.clone(), zero3.clone() );
+			var center = new Vector3();
+			var size = new Vector3();
 
 			a.expandByVector( zero3 );
-			assert.ok( a.getSize().equals( zero3 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( zero3 ), "Passed!" );
 
 			a.expandByVector( one3 );
-			assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
-			assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
+			assert.ok( a.getCenter( center ).equals( zero3 ), "Passed!" );
 
 		} );
 
 		QUnit.test( "expandByScalar", ( assert ) => {
 
 			var a = new Box3( zero3.clone(), zero3.clone() );
+			var center = new Vector3();
+			var size = new Vector3();
 
 			a.expandByScalar( 0 );
-			assert.ok( a.getSize().equals( zero3 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( zero3 ), "Passed!" );
 
 			a.expandByScalar( 1 );
-			assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
-			assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
+			assert.ok( a.getSize( size ).equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
+			assert.ok( a.getCenter( center ).equals( zero3 ), "Passed!" );
 
 		} );
 
@@ -335,13 +354,19 @@ export default QUnit.module( 'Maths', () => {
 
 			var a = new Box3( zero3.clone(), one3.clone() );
 			var b = new Box3( one3.clone().negate(), one3.clone() );
+			var parameter = new Vector3();
 
-			assert.ok( a.getParameter( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
-			assert.ok( a.getParameter( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
+			a.getParameter( zero3, parameter );
+			assert.ok( parameter.equals( zero3 ), "Passed!" );
+			a.getParameter( one3, parameter );
+			assert.ok( parameter.equals( one3 ), "Passed!" );
 
-			assert.ok( b.getParameter( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
-			assert.ok( b.getParameter( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0.5, 0.5, 0.5 ) ), "Passed!" );
-			assert.ok( b.getParameter( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
+			b.getParameter( one3.clone().negate(), parameter );
+			assert.ok( parameter.equals( zero3 ), "Passed!" );
+			b.getParameter( zero3, parameter );
+			assert.ok( parameter.equals( new Vector3( 0.5, 0.5, 0.5 ) ), "Passed!" );
+			b.getParameter( one3, parameter );
+			assert.ok( parameter.equals( one3 ), "Passed!" );
 
 		} );
 
@@ -412,16 +437,25 @@ export default QUnit.module( 'Maths', () => {
 
 			var a = new Box3( zero3.clone(), zero3.clone() );
 			var b = new Box3( one3.clone().negate(), one3.clone() );
+			var point = new Vector3();
 
-			assert.ok( a.clampPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
-			assert.ok( a.clampPoint( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
-			assert.ok( a.clampPoint( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
+			a.clampPoint( zero3, point );
+			assert.ok( point.equals( zero3 ), "Passed!" );
+			a.clampPoint( one3, point );
+			assert.ok( point.equals( zero3 ), "Passed!" );
+			a.clampPoint( one3.clone().negate(), point );
+			assert.ok( point.equals( zero3 ), "Passed!" );
 
-			assert.ok( b.clampPoint( new Vector3( 2, 2, 2 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
-			assert.ok( b.clampPoint( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
-			assert.ok( b.clampPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
-			assert.ok( b.clampPoint( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
-			assert.ok( b.clampPoint( new Vector3( - 2, - 2, - 2 ) ).equals( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
+			b.clampPoint( new Vector3( 2, 2, 2 ), point );
+			assert.ok( point.equals( one3 ), "Passed!" );
+			b.clampPoint( one3, point );
+			assert.ok( point.equals( one3 ), "Passed!" );
+			b.clampPoint( zero3, point );
+			assert.ok( point.equals( zero3 ), "Passed!" );
+			b.clampPoint( one3.clone().negate(), point );
+			assert.ok( point.equals( one3.clone().negate() ), "Passed!" );
+			b.clampPoint( new Vector3( - 2, - 2, - 2 ), point );
+			assert.ok( point.equals( one3.clone().negate() ), "Passed!" );
 
 		} );
 
@@ -447,10 +481,11 @@ export default QUnit.module( 'Maths', () => {
 			var a = new Box3( zero3.clone(), zero3.clone() );
 			var b = new Box3( zero3.clone(), one3.clone() );
 			var c = new Box3( one3.clone().negate(), one3.clone() );
+			var sphere = new Sphere();
 
-			assert.ok( a.getBoundingSphere().equals( new Sphere( zero3, 0 ) ), "Passed!" );
-			assert.ok( b.getBoundingSphere().equals( new Sphere( one3.clone().multiplyScalar( 0.5 ), Math.sqrt( 3 ) * 0.5 ) ), "Passed!" );
-			assert.ok( c.getBoundingSphere().equals( new Sphere( zero3, Math.sqrt( 12 ) * 0.5 ) ), "Passed!" );
+			assert.ok( a.getBoundingSphere( sphere ).equals( new Sphere( zero3, 0 ) ), "Passed!" );
+			assert.ok( b.getBoundingSphere( sphere ).equals( new Sphere( one3.clone().multiplyScalar( 0.5 ), Math.sqrt( 3 ) * 0.5 ) ), "Passed!" );
+			assert.ok( c.getBoundingSphere( sphere ).equals( new Sphere( zero3, Math.sqrt( 12 ) * 0.5 ) ), "Passed!" );
 
 		} );
 

+ 18 - 12
test/unit/src/math/Line3.tests.js

@@ -114,37 +114,43 @@ export default QUnit.module( 'Maths', () => {
 		QUnit.test( "at", ( assert ) => {
 
 			var a = new Line3( one3.clone(), new Vector3( 1, 1, 2 ) );
+			var point = new Vector3();
 
-			assert.ok( a.at( - 1 ).distanceTo( new Vector3( 1, 1, 0 ) ) < 0.0001, "Passed!" );
-			assert.ok( a.at( 0 ).distanceTo( one3.clone() ) < 0.0001, "Passed!" );
-			assert.ok( a.at( 1 ).distanceTo( new Vector3( 1, 1, 2 ) ) < 0.0001, "Passed!" );
-			assert.ok( a.at( 2 ).distanceTo( new Vector3( 1, 1, 3 ) ) < 0.0001, "Passed!" );
+			a.at( - 1, point );
+			assert.ok( point.distanceTo( new Vector3( 1, 1, 0 ) ) < 0.0001, "Passed!" );
+			a.at( 0, point );
+			assert.ok( point.distanceTo( one3.clone() ) < 0.0001, "Passed!" );
+			a.at( 1, point );
+			assert.ok( point.distanceTo( new Vector3( 1, 1, 2 ) ) < 0.0001, "Passed!" );
+			a.at( 2, point );
+			assert.ok( point.distanceTo( new Vector3( 1, 1, 3 ) ) < 0.0001, "Passed!" );
 
 		} );
 
 		QUnit.test( "closestPointToPoint/closestPointToPointParameter", ( assert ) => {
 
 			var a = new Line3( one3.clone(), new Vector3( 1, 1, 2 ) );
+			var point = new Vector3();
 
 			// nearby the ray
 			assert.ok( a.closestPointToPointParameter( zero3.clone(), true ) == 0, "Passed!" );
-			var b1 = a.closestPointToPoint( zero3.clone(), true );
-			assert.ok( b1.distanceTo( new Vector3( 1, 1, 1 ) ) < 0.0001, "Passed!" );
+			a.closestPointToPoint( zero3.clone(), true, point );
+			assert.ok( point.distanceTo( new Vector3( 1, 1, 1 ) ) < 0.0001, "Passed!" );
 
 			// nearby the ray
 			assert.ok( a.closestPointToPointParameter( zero3.clone(), false ) == - 1, "Passed!" );
-			var b2 = a.closestPointToPoint( zero3.clone(), false );
-			assert.ok( b2.distanceTo( new Vector3( 1, 1, 0 ) ) < 0.0001, "Passed!" );
+			 a.closestPointToPoint( zero3.clone(), false, point );
+			assert.ok( point.distanceTo( new Vector3( 1, 1, 0 ) ) < 0.0001, "Passed!" );
 
 			// nearby the ray
 			assert.ok( a.closestPointToPointParameter( new Vector3( 1, 1, 5 ), true ) == 1, "Passed!" );
-			var b = a.closestPointToPoint( new Vector3( 1, 1, 5 ), true );
-			assert.ok( b.distanceTo( new Vector3( 1, 1, 2 ) ) < 0.0001, "Passed!" );
+			a.closestPointToPoint( new Vector3( 1, 1, 5 ), true, point );
+			assert.ok( point.distanceTo( new Vector3( 1, 1, 2 ) ) < 0.0001, "Passed!" );
 
 			// exactly on the ray
 			assert.ok( a.closestPointToPointParameter( one3.clone(), true ) == 0, "Passed!" );
-			var c = a.closestPointToPoint( one3.clone(), true );
-			assert.ok( c.distanceTo( one3.clone() ) < 0.0001, "Passed!" );
+			a.closestPointToPoint( one3.clone(), true, point );
+			assert.ok( point.distanceTo( one3.clone() ) < 0.0001, "Passed!" );
 
 		} );
 

+ 23 - 23
test/unit/src/math/Plane.tests.js

@@ -173,9 +173,10 @@ export default QUnit.module( 'Maths', () => {
 		QUnit.test( "distanceToPoint", ( assert ) => {
 
 			var a = new Plane( new Vector3( 2, 0, 0 ), - 2 );
+			var point = new Vector3();
 
-			a.normalize();
-			assert.ok( a.distanceToPoint( a.projectPoint( zero3.clone() ) ) === 0, "Passed!" );
+			a.normalize().projectPoint( zero3.clone(), point );
+			assert.ok( a.distanceToPoint( point ) === 0, "Passed!" );
 			assert.ok( a.distanceToPoint( new Vector3( 4, 0, 0 ) ) === 3, "Passed!" );
 
 		} );
@@ -198,38 +199,33 @@ export default QUnit.module( 'Maths', () => {
 		QUnit.test( "projectPoint", ( assert ) => {
 
 			var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
+			var point = new Vector3();
 
-			assert.ok( a.projectPoint( new Vector3( 10, 0, 0 ) ).equals( zero3 ), "Passed!" );
-			assert.ok( a.projectPoint( new Vector3( - 10, 0, 0 ) ).equals( zero3 ), "Passed!" );
+			a.projectPoint( new Vector3( 10, 0, 0 ), point );
+			assert.ok( point.equals( zero3 ), "Passed!" );
+			a.projectPoint( new Vector3( - 10, 0, 0 ), point );
+			assert.ok( point.equals( zero3 ), "Passed!" );
 
 			var a = new Plane( new Vector3( 0, 1, 0 ), - 1 );
-			assert.ok( a.projectPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
-			assert.ok( a.projectPoint( new Vector3( 0, 1, 0 ) ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
+			a.projectPoint( new Vector3( 0, 0, 0 ), point );
+			assert.ok( point.equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
+			a.projectPoint( new Vector3( 0, 1, 0 ), point );
+			assert.ok( point.equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
 
 		} );
 
 		QUnit.test( "isInterestionLine/intersectLine", ( assert ) => {
 
 			var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
+			var point = new Vector3();
 
 			var l1 = new Line3( new Vector3( - 10, 0, 0 ), new Vector3( 10, 0, 0 ) );
-			assert.ok( a.intersectsLine( l1 ), "Passed!" );
-			assert.ok( a.intersectLine( l1 ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
+			a.intersectLine( l1, point );
+			assert.ok( point.equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
 
 			var a = new Plane( new Vector3( 1, 0, 0 ), - 3 );
-
-			assert.ok( a.intersectsLine( l1 ), "Passed!" );
-			assert.ok( a.intersectLine( l1 ).equals( new Vector3( 3, 0, 0 ) ), "Passed!" );
-
-			var a = new Plane( new Vector3( 1, 0, 0 ), - 11 );
-
-			assert.ok( ! a.intersectsLine( l1 ), "Passed!" );
-			assert.ok( a.intersectLine( l1 ) === undefined, "Passed!" );
-
-			var a = new Plane( new Vector3( 1, 0, 0 ), 11 );
-
-			assert.ok( ! a.intersectsLine( l1 ), "Passed!" );
-			assert.ok( a.intersectLine( l1 ) === undefined, "Passed!" );
+			a.intersectLine( l1, point );
+			assert.ok( point.equals( new Vector3( 3, 0, 0 ) ), "Passed!" );
 
 		} );
 
@@ -247,11 +243,15 @@ export default QUnit.module( 'Maths', () => {
 
 		QUnit.test( "coplanarPoint", ( assert ) => {
 
+			var point = new Vector3();
+
 			var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
-			assert.ok( a.distanceToPoint( a.coplanarPoint() ) === 0, "Passed!" );
+			a.coplanarPoint( point );
+			assert.ok( a.distanceToPoint( point ) === 0, "Passed!" );
 
 			var a = new Plane( new Vector3( 0, 1, 0 ), - 1 );
-			assert.ok( a.distanceToPoint( a.coplanarPoint() ) === 0, "Passed!" );
+			a.coplanarPoint( point );
+			assert.ok( a.distanceToPoint( point ) === 0, "Passed!" );
 
 		} );
 

+ 78 - 48
test/unit/src/math/Ray.tests.js

@@ -14,7 +14,8 @@ import {
 	zero3,
 	one3,
 	two3,
-	eps
+	eps,
+	posInf3
 } from './Constants.tests';
 
 export default QUnit.module( 'Maths', () => {
@@ -89,10 +90,14 @@ export default QUnit.module( 'Maths', () => {
 		QUnit.test( "at", ( assert ) => {
 
 			var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
+			var point = new Vector3();
 
-			assert.ok( a.at( 0 ).equals( one3 ), "Passed!" );
-			assert.ok( a.at( - 1 ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
-			assert.ok( a.at( 1 ).equals( new Vector3( 1, 1, 2 ) ), "Passed!" );
+			a.at( 0, point );
+			assert.ok( point.equals( one3 ), "Passed!" );
+			a.at( - 1, point );
+			assert.ok( point.equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
+			a.at( 1, point );
+			assert.ok( point.equals( new Vector3( 1, 1, 2 ) ), "Passed!" );
 
 		} );
 
@@ -110,18 +115,19 @@ export default QUnit.module( 'Maths', () => {
 		QUnit.test( "closestPointToPoint", ( assert ) => {
 
 			var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
+			var point = new Vector3();
 
 			// behind the ray
-			var b = a.closestPointToPoint( zero3 );
-			assert.ok( b.equals( one3 ), "Passed!" );
+			a.closestPointToPoint( zero3, point );
+			assert.ok( point.equals( one3 ), "Passed!" );
 
 			// front of the ray
-			var c = a.closestPointToPoint( new Vector3( 0, 0, 50 ) );
-			assert.ok( c.equals( new Vector3( 1, 1, 50 ) ), "Passed!" );
+			a.closestPointToPoint( new Vector3( 0, 0, 50 ), point );
+			assert.ok( point.equals( new Vector3( 1, 1, 50 ) ), "Passed!" );
 
 			// exactly on the ray
-			var d = a.closestPointToPoint( one3 );
-			assert.ok( d.equals( one3 ), "Passed!" );
+			a.closestPointToPoint( one3, point );
+			assert.ok( point.equals( one3 ), "Passed!" );
 
 		} );
 
@@ -201,6 +207,7 @@ export default QUnit.module( 'Maths', () => {
 		QUnit.test( "intersectSphere", ( assert ) => {
 
 			var TOL = 0.0001;
+			var point = new Vector3();
 
 			// ray a0 origin located at ( 0, 0, 0 ) and points outward in negative-z direction
 			var a0 = new Ray( zero3.clone(), new Vector3( 0, 0, - 1 ) );
@@ -209,31 +216,38 @@ export default QUnit.module( 'Maths', () => {
 
 			// sphere (radius of 2) located behind ray a0, should result in null
 			var b = new Sphere( new Vector3( 0, 0, 3 ), 2 );
-			assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
+			a0.intersectSphere( b, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "Passed!" );
 
 			// sphere (radius of 2) located in front of, but too far right of ray a0, should result in null
 			var b = new Sphere( new Vector3( 3, 0, - 1 ), 2 );
-			assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
+			a0.intersectSphere( b, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "Passed!" );
 
 			// sphere (radius of 2) located below ray a1, should result in null
 			var b = new Sphere( new Vector3( 1, - 2, 1 ), 2 );
-			assert.ok( a1.intersectSphere( b ) === null, "Passed!" );
+			a1.intersectSphere( b, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "Passed!" );
 
 			// sphere (radius of 1) located to the left of ray a1, should result in intersection at 0, 1, 1
 			var b = new Sphere( new Vector3( - 1, 1, 1 ), 1 );
-			assert.ok( a1.intersectSphere( b ).distanceTo( new Vector3( 0, 1, 1 ) ) < TOL, "Passed!" );
+			a1.intersectSphere( b, point );
+			assert.ok( point.distanceTo( new Vector3( 0, 1, 1 ) ) < TOL, "Passed!" );
 
 			// sphere (radius of 1) located in front of ray a0, should result in intersection at 0, 0, -1
 			var b = new Sphere( new Vector3( 0, 0, - 2 ), 1 );
-			assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
+			a0.intersectSphere( b, point );
+			assert.ok( point.distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
 
 			// sphere (radius of 2) located in front & right of ray a0, should result in intersection at 0, 0, -1, or left-most edge of sphere
 			var b = new Sphere( new Vector3( 2, 0, - 1 ), 2 );
-			assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
+			a0.intersectSphere( b, point );
+			assert.ok( point.distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
 
 			// same situation as above, but move the sphere a fraction more to the right, and ray a0 should now just miss
 			var b = new Sphere( new Vector3( 2.01, 0, - 1 ), 2 );
-			assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
+			a0.intersectSphere( b, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "Passed!" );
 
 			// following QUnit.tests are for situations where the ray origin is inside the sphere
 
@@ -241,19 +255,22 @@ export default QUnit.module( 'Maths', () => {
 			// is behind ray a0.  Therefore, second exit point on back of sphere will be returned: 0, 0, -1
 			// thus keeping the intersection point always in front of the ray.
 			var b = new Sphere( zero3.clone(), 1 );
-			assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
+			a0.intersectSphere( b, point );
+			assert.ok( point.distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
 
 			// sphere (radius of 4) center located behind ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 5,
 			// is behind ray a0.  Therefore, second exit point on back of sphere will be returned: 0, 0, -3
 			// thus keeping the intersection point always in front of the ray.
 			var b = new Sphere( new Vector3( 0, 0, 1 ), 4 );
-			assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 3 ) ) < TOL, "Passed!" );
+			a0.intersectSphere( b, point );
+			assert.ok( point.distanceTo( new Vector3( 0, 0, - 3 ) ) < TOL, "Passed!" );
 
 			// sphere (radius of 4) center located in front of ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 3,
 			// is behind ray a0.  Therefore, second exit point on back of sphere will be returned: 0, 0, -5
 			// thus keeping the intersection point always in front of the ray.
 			var b = new Sphere( new Vector3( 0, 0, - 1 ), 4 );
-			assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 5 ) ) < TOL, "Passed!" );
+			a0.intersectSphere( b, point );
+			assert.ok( point.distanceTo( new Vector3( 0, 0, - 5 ) ) < TOL, "Passed!" );
 
 		} );
 
@@ -283,26 +300,32 @@ export default QUnit.module( 'Maths', () => {
 		QUnit.test( "intersectPlane", ( assert ) => {
 
 			var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
+			var point = new Vector3();
 
 			// parallel plane behind
 			var b = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, - 1 ) );
-			assert.ok( a.intersectPlane( b ) === null, "Passed!" );
+			a.intersectPlane( b, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "Passed!" );
 
 			// parallel plane coincident with origin
 			var c = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, 0 ) );
-			assert.ok( a.intersectPlane( c ) === null, "Passed!" );
+			a.intersectPlane( c, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "Passed!" );
 
 			// parallel plane infront
 			var d = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, 1 ) );
-			assert.ok( a.intersectPlane( d ).equals( a.origin ), "Passed!" );
+			a.intersectPlane( d, point.copy( posInf3 ) );
+			assert.ok( point.equals( a.origin ), "Passed!" );
 
 			// perpendical ray that overlaps exactly
 			var e = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), one3 );
-			assert.ok( a.intersectPlane( e ).equals( a.origin ), "Passed!" );
+			a.intersectPlane( e, point.copy( posInf3 ) );
+			assert.ok( point.equals( a.origin ), "Passed!" );
 
 			// perpendical ray that doesn't overlap
 			var f = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), zero3 );
-			assert.ok( a.intersectPlane( f ) === null, "Passed!" );
+			a.intersectPlane( f, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "Passed!" );
 
 		} );
 
@@ -337,36 +360,43 @@ export default QUnit.module( 'Maths', () => {
 			var TOL = 0.0001;
 
 			var box = new Box3( new Vector3( - 1, - 1, - 1 ), new Vector3( 1, 1, 1 ) );
+			var point = new Vector3();
 
 			var a = new Ray( new Vector3( - 2, 0, 0 ), new Vector3( 1, 0, 0 ) );
 			//ray should intersect box at -1,0,0
 			assert.ok( a.intersectsBox( box ) === true, "Passed!" );
-			assert.ok( a.intersectBox( box ).distanceTo( new Vector3( - 1, 0, 0 ) ) < TOL, "Passed!" );
+			a.intersectBox( box, point );
+			assert.ok( point.distanceTo( new Vector3( - 1, 0, 0 ) ) < TOL, "Passed!" );
 
 			var b = new Ray( new Vector3( - 2, 0, 0 ), new Vector3( - 1, 0, 0 ) );
 			//ray is point away from box, it should not intersect
 			assert.ok( b.intersectsBox( box ) === false, "Passed!" );
-			assert.ok( b.intersectBox( box ) === null, "Passed!" );
+			b.intersectBox( box, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "Passed!" );
 
 			var c = new Ray( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ) );
 			// ray is inside box, should return exit point
 			assert.ok( c.intersectsBox( box ) === true, "Passed!" );
-			assert.ok( c.intersectBox( box ).distanceTo( new Vector3( 1, 0, 0 ) ) < TOL, "Passed!" );
+			c.intersectBox( box, point );
+			assert.ok( point.distanceTo( new Vector3( 1, 0, 0 ) ) < TOL, "Passed!" );
 
 			var d = new Ray( new Vector3( 0, 2, 1 ), new Vector3( 0, - 1, - 1 ).normalize() );
 			//tilted ray should intersect box at 0,1,0
 			assert.ok( d.intersectsBox( box ) === true, "Passed!" );
-			assert.ok( d.intersectBox( box ).distanceTo( new Vector3( 0, 1, 0 ) ) < TOL, "Passed!" );
+			d.intersectBox( box, point );
+			assert.ok( point.distanceTo( new Vector3( 0, 1, 0 ) ) < TOL, "Passed!" );
 
 			var e = new Ray( new Vector3( 1, - 2, 1 ), new Vector3( 0, 1, 0 ).normalize() );
 			//handle case where ray is coplanar with one of the boxes side - box in front of ray
 			assert.ok( e.intersectsBox( box ) === true, "Passed!" );
-			assert.ok( e.intersectBox( box ).distanceTo( new Vector3( 1, - 1, 1 ) ) < TOL, "Passed!" );
+			e.intersectBox( box, point );
+			assert.ok( point.distanceTo( new Vector3( 1, - 1, 1 ) ) < TOL, "Passed!" );
 
 			var f = new Ray( new Vector3( 1, - 2, 0 ), new Vector3( 0, - 1, 0 ).normalize() );
 			//handle case where ray is coplanar with one of the boxes side - box behind ray
 			assert.ok( f.intersectsBox( box ) === false, "Passed!" );
-			assert.ok( f.intersectBox( box ) == null, "Passed!" );
+			f.intersectBox( box, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "Passed!" );
 
 		} );
 
@@ -382,46 +412,46 @@ export default QUnit.module( 'Maths', () => {
 			var a = new Vector3( 1, 1, 0 );
 			var b = new Vector3( 0, 1, 1 );
 			var c = new Vector3( 1, 0, 1 );
-			var intersect;
+			var point = new Vector3();
 
 			// DdN == 0
 			ray.set( ray.origin, zero3.clone() );
-			intersect = ray.intersectTriangle( a, b, c, false );
-			assert.strictEqual( intersect, null, "No intersection if direction == zero" );
+			ray.intersectTriangle( a, b, c, false, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "No intersection if direction == zero" );
 
 			// DdN > 0, backfaceCulling = true
 			ray.set( ray.origin, one3.clone() );
-			intersect = ray.intersectTriangle( a, b, c, true );
-			assert.strictEqual( intersect, null, "No intersection with backside faces if backfaceCulling is true" );
+			ray.intersectTriangle( a, b, c, true, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "No intersection with backside faces if backfaceCulling is true" );
 
 			// DdN > 0
 			ray.set( ray.origin, one3.clone() );
-			intersect = ray.intersectTriangle( a, b, c, false );
-			assert.ok( Math.abs( intersect.x - 2 / 3 ) <= eps, "Successful intersection: check x" );
-			assert.ok( Math.abs( intersect.y - 2 / 3 ) <= eps, "Successful intersection: check y" );
-			assert.ok( Math.abs( intersect.z - 2 / 3 ) <= eps, "Successful intersection: check z" );
+			ray.intersectTriangle( a, b, c, false, point );
+			assert.ok( Math.abs( point.x - 2 / 3 ) <= eps, "Successful intersection: check x" );
+			assert.ok( Math.abs( point.y - 2 / 3 ) <= eps, "Successful intersection: check y" );
+			assert.ok( Math.abs( point.z - 2 / 3 ) <= eps, "Successful intersection: check z" );
 
 			// DdN > 0, DdQxE2 < 0
 			b.multiplyScalar( - 1 );
-			intersect = ray.intersectTriangle( a, b, c, false );
-			assert.strictEqual( intersect, null, "No intersection" );
+			ray.intersectTriangle( a, b, c, false, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "No intersection" );
 
 			// DdN > 0, DdE1xQ < 0
 			a.multiplyScalar( - 1 );
-			intersect = ray.intersectTriangle( a, b, c, false );
-			assert.strictEqual( intersect, null, "No intersection" );
+			ray.intersectTriangle( a, b, c, false, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "No intersection" );
 
 			// DdN > 0, DdQxE2 + DdE1xQ > DdN
 			b.multiplyScalar( - 1 );
-			intersect = ray.intersectTriangle( a, b, c, false );
-			assert.strictEqual( intersect, null, "No intersection" );
+			ray.intersectTriangle( a, b, c, false, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "No intersection" );
 
 			// DdN < 0, QdN < 0
 			a.multiplyScalar( - 1 );
 			b.multiplyScalar( - 1 );
 			ray.direction.multiplyScalar( - 1 );
-			intersect = ray.intersectTriangle( a, b, c, false );
-			assert.strictEqual( intersect, null, "No intersection when looking in the wrong direction" );
+			ray.intersectTriangle( a, b, c, false, point.copy( posInf3 ) );
+			assert.ok( point.equals( posInf3 ), "No intersection when looking in the wrong direction" );
 
 		} );
 

+ 16 - 6
test/unit/src/math/Sphere.tests.js

@@ -4,7 +4,6 @@
  */
 /* global QUnit */
 
-import { Ray } from '../../../../src/math/Ray';
 import { Box3 } from '../../../../src/math/Box3';
 import { Vector3 } from '../../../../src/math/Vector3';
 import { Sphere } from '../../../../src/math/Sphere';
@@ -175,20 +174,26 @@ export default QUnit.module( 'Maths', () => {
 		QUnit.test( "clampPoint", ( assert ) => {
 
 			var a = new Sphere( one3.clone(), 1 );
+			var point = new Vector3();
 
-			assert.ok( a.clampPoint( new Vector3( 1, 1, 3 ) ).equals( new Vector3( 1, 1, 2 ) ), "Passed!" );
-			assert.ok( a.clampPoint( new Vector3( 1, 1, - 3 ) ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
+			a.clampPoint( new Vector3( 1, 1, 3 ), point );
+			assert.ok( point.equals( new Vector3( 1, 1, 2 ) ), "Passed!" );
+			a.clampPoint( new Vector3( 1, 1, - 3 ), point );
+			assert.ok( point.equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
 
 		} );
 
 		QUnit.test( "getBoundingBox", ( assert ) => {
 
 			var a = new Sphere( one3.clone(), 1 );
+			var aabb = new Box3();
 
-			assert.ok( a.getBoundingBox().equals( new Box3( zero3, two3 ) ), "Passed!" );
+			a.getBoundingBox( aabb );
+			assert.ok( aabb.equals( new Box3( zero3, two3 ) ), "Passed!" );
 
 			a.set( zero3, 0 );
-			assert.ok( a.getBoundingBox().equals( new Box3( zero3, zero3 ) ), "Passed!" );
+			a.getBoundingBox( aabb );
+			assert.ok( aabb.equals( new Box3( zero3, zero3 ) ), "Passed!" );
 
 		} );
 
@@ -196,8 +201,13 @@ export default QUnit.module( 'Maths', () => {
 
 			var a = new Sphere( one3.clone(), 1 );
 			var m = new Matrix4().makeTranslation( 1, - 2, 1 );
+			var aabb1 = new Box3();
+			var aabb2 = new Box3();
 
-			assert.ok( a.clone().applyMatrix4( m ).getBoundingBox().equals( a.getBoundingBox().applyMatrix4( m ) ), "Passed!" );
+			a.clone().applyMatrix4( m ).getBoundingBox( aabb1 );
+			a.getBoundingBox( aabb2 );
+
+			assert.ok( aabb1.equals( aabb2.applyMatrix4( m ) ), "Passed!" );
 
 		} );