Repository: mrdoob/three.js (JavaScript)
Task: Bug Fix (2018-09-03 10:34:13+00:00)

Issue:
box3.intersectsPlane bug
In the following example, the plane obviously intersects with the box, but the function intersectsPlane returns false.
[example](https://jsfiddle.net/rn6jzdub/4/)
I find that adding two negative sign before both of the plane.constant can fix the bug.
https://github.com/mrdoob/three.js/blob/c570b9bd95cf94829715b2cd3a8b128e37768a9c/src/math/Box3.js#L387
Also, I think the definition of the constant of the plane is not distinct, which cause the bug.

##### Three.js version

- [x] Dev
- [x] r96
- [x] ...

##### Browser

- [x] All of them


##### OS

- [x] All of them




Discussion:
Good find! Would you like to do a PR with the fix? It would be great if you also adjust the wrong [unit test](https://github.com/mrdoob/three.js/blob/dev/test/unit/src/math/Box3.tests.js#L406).

> Also, I think the definition of the constant of the plane is not distinct, which cause the bug

`three.js` uses [Hessian Normal Form](http://mathworld.wolfram.com/HessianNormalForm.html), a common way to specify planes. I think okay to stick with that.

Patch:
diff --git a/src/math/Box3.js b/src/math/Box3.js
--- a/src/math/Box3.js
+++ b/src/math/Box3.js
@@ -384,7 +384,7 @@ Object.assign( Box3.prototype, {
 
 		}
 
-		return ( min <= plane.constant && max >= plane.constant );
+		return ( min <= - plane.constant && max >= - plane.constant );
 
 	},
 


Test patch:
diff --git a/test/unit/src/math/Box3.tests.js b/test/unit/src/math/Box3.tests.js
--- a/test/unit/src/math/Box3.tests.js
+++ b/test/unit/src/math/Box3.tests.js
@@ -409,10 +409,22 @@ export default QUnit.module( 'Maths', () => {
 			var b = new Plane( new Vector3( 0, 1, 0 ), 1 );
 			var c = new Plane( new Vector3( 0, 1, 0 ), 1.25 );
 			var d = new Plane( new Vector3( 0, - 1, 0 ), 1.25 );
-
-			assert.ok( a.intersectsPlane( b ), "Passed!" );
+			var e = new Plane( new Vector3( 0, 1, 0 ), 0.25 );
+			var f = new Plane( new Vector3( 0, 1, 0 ), - 0.25 );
+			var g = new Plane( new Vector3( 0, 1, 0 ), - 0.75 );
+			var h = new Plane( new Vector3( 0, 1, 0 ), - 1 );
+			var i = new Plane( new Vector3( 1, 1, 1 ).normalize(), - 1.732 );
+			var j = new Plane( new Vector3( 1, 1, 1 ).normalize(), - 1.733 );
+
+			assert.ok( ! a.intersectsPlane( b ), "Passed!" );
 			assert.ok( ! a.intersectsPlane( c ), "Passed!" );
 			assert.ok( ! a.intersectsPlane( d ), "Passed!" );
+			assert.ok( ! a.intersectsPlane( e ), "Passed!" );
+			assert.ok( a.intersectsPlane( f ), "Passed!" );
+			assert.ok( a.intersectsPlane( g ), "Passed!" );
+			assert.ok( a.intersectsPlane( h ), "Passed!" );
+			assert.ok( a.intersectsPlane( i ), "Passed!" );
+			assert.ok( ! a.intersectsPlane( j ), "Passed!" );
 
 		} );