Przeglądaj źródła

Fix intersect test parameters to translate.

Ondřej Španěl 7 lat temu
rodzic
commit
1ef8062877
2 zmienionych plików z 9 dodań i 2 usunięć
  1. 6 0
      src/math/Box3.js
  2. 3 2
      test/unit/src/math/Frustum.tests.js

+ 6 - 0
src/math/Box3.js

@@ -468,6 +468,12 @@ Object.assign( Box3.prototype, {
 
 	translate: function ( offset ) {
 
+		if ( ! offset.isVector3 ) {
+
+			throw new Error( 'THREE.Box3: .translate() expects a Vector3.' );
+
+		}
+
 		this.min.add( offset );
 		this.max.add( offset );
 

+ 3 - 2
test/unit/src/math/Frustum.tests.js

@@ -13,7 +13,7 @@ import { Matrix4 } from '../../../../src/math/Matrix4';
 import { Box3 } from '../../../../src/math/Box3';
 import { Mesh } from '../../../../src/objects/Mesh';
 import { BoxGeometry } from '../../../../src/geometries/BoxGeometry';
-import { zero3, one3 } from './Constants.tests';
+import { zero3, one3, eps } from './Constants.tests';
 
 const unit3 = new Vector3( 1, 0, 0 );
 
@@ -262,7 +262,8 @@ export default QUnit.module( 'Maths', () => {
 			intersects = a.intersectsBox( box );
 			assert.notOk( intersects, "No intersection" );
 
-			box.translate( - 1, - 1, - 1 );
+			// add eps so that we prevent box touching the frustum, which might intersect depending on floating point numerics
+			box.translate( new Vector3( - 1 - eps, - 1 - eps, - 1 - eps ) );
 
 			intersects = a.intersectsBox( box );
 			assert.ok( intersects, "Successful intersection" );