diff --git a/src/math/Sphere.js b/src/math/Sphere.js index f75fb2a17bf56913e420abbc7537e9042be32835..290963028ff2dffba7ead90748064ab3b5094bd4 100644 --- a/src/math/Sphere.js +++ b/src/math/Sphere.js @@ -67,9 +67,11 @@ THREE.Sphere.prototype = { }, - isIntersectionSphere: function(sphere) { + isIntersectionSphere: function( sphere ) { - return ( sphere.center.distanceToSquared( this.center ) <= ( this.radius * this.radius + sphere.radius * sphere.radius) ); + var radiusSum = this.radius + sphere.radius; + + return ( sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum ) ); }, diff --git a/test/unit/math/Sphere.js b/test/unit/math/Sphere.js index 18a1f9d27c2633afbf47d328509efed4553d0074..baf057c0f29170e4e1ba66813b6abc7c6d91b9eb 100644 --- a/test/unit/math/Sphere.js +++ b/test/unit/math/Sphere.js @@ -60,6 +60,15 @@ test( "distanceToPoint", function() { ok( a.distanceToPoint( one3 ) === -1, "Passed!" ); }); +test( "isIntersectionSphere", function() { + var a = new THREE.Sphere( one3, 1 ); + var b = new THREE.Sphere( zero3, 1 ); + var c = new THREE.Sphere( zero3, 0.25 ); + + ok( a.isIntersectionSphere( b ) , "Passed!" ); + ok( ! a.isIntersectionSphere( c ) , "Passed!" ); +}); + test( "clampPoint", function() { var a = new THREE.Sphere( one3, 1 );