浏览代码

Merge pull request #7445 from Mugen87/dev

Bugfix intersectsPlane and new unit tests
Mr.doob 9 年之前
父节点
当前提交
1ef8ba5adb
共有 3 个文件被更改,包括 33 次插入1 次删除
  1. 1 1
      src/math/Sphere.js
  2. 21 0
      test/unit/math/Box3.js
  3. 11 0
      test/unit/math/Sphere.js

+ 1 - 1
src/math/Sphere.js

@@ -114,7 +114,7 @@ THREE.Sphere.prototype = {
 		// If this distance is greater than the radius of the sphere,
 		// If this distance is greater than the radius of the sphere,
 		// then there is no intersection.
 		// then there is no intersection.
 
 
-		return ( ( this.center.dot( plane.normal ) - plane.constant ) <= this.radius );
+		return ( Math.abs( ( this.center.dot( plane.normal ) - plane.constant ) ) <= this.radius );
 
 
 	},
 	},
 
 

+ 21 - 0
test/unit/math/Box3.js

@@ -223,6 +223,27 @@ test( "intersectsBox", function() {
 	ok( ! b.intersectsBox( c ), "Passed!" );
 	ok( ! b.intersectsBox( c ), "Passed!" );
 });
 });
 
 
+test( "intersectsSphere", function() {
+	var a = new THREE.Box3( zero3.clone(), one3.clone() );
+	var b = new THREE.Sphere( zero3.clone(), 1 );
+
+	ok( a.intersectsSphere( b ) , "Passed!" );
+
+	b.translate( new THREE.Vector3( 2, 2, 2 ) );
+	ok( ! a.intersectsSphere( b ) , "Passed!" );
+});
+
+test( "intersectsPlane", function() {
+	var a = new THREE.Box3( zero3.clone(), one3.clone() );
+	var b = new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), 1 );
+	var c = new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), 1.25 );
+	var d = new THREE.Plane( new THREE.Vector3( 0, -1, 0 ), 1.25 );
+
+	ok( a.intersectsPlane( b ) , "Passed!" );
+	ok( ! a.intersectsPlane( c ) , "Passed!" );
+	ok( ! a.intersectsPlane( d ) , "Passed!" );
+});
+
 test( "getBoundingSphere", function() {
 test( "getBoundingSphere", function() {
 	var a = new THREE.Box3( zero3.clone(), zero3.clone() );
 	var a = new THREE.Box3( zero3.clone(), zero3.clone() );
 	var b = new THREE.Box3( zero3.clone(), one3.clone() );
 	var b = new THREE.Box3( zero3.clone(), one3.clone() );

+ 11 - 0
test/unit/math/Sphere.js

@@ -69,6 +69,17 @@ test( "intersectsSphere", function() {
 	ok( ! a.intersectsSphere( c ) , "Passed!" );
 	ok( ! a.intersectsSphere( c ) , "Passed!" );
 });
 });
 
 
+test( "intersectsPlane", function() {
+	var a = new THREE.Sphere( zero3.clone(), 1 );
+	var b = new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), 1 );
+	var c = new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), 1.25 );
+	var d = new THREE.Plane( new THREE.Vector3( 0, -1, 0 ), 1.25 );
+
+	ok( a.intersectsPlane( b ) , "Passed!" );
+	ok( ! a.intersectsPlane( c ) , "Passed!" );
+	ok( ! a.intersectsPlane( d ) , "Passed!" );
+});
+
 test( "clampPoint", function() {
 test( "clampPoint", function() {
 	var a = new THREE.Sphere( one3.clone(), 1 );
 	var a = new THREE.Sphere( one3.clone(), 1 );