Browse Source

Add unit test, fix is isIntersectionSphere

Add missing space
Fix isIntersectionSphere
Addunit test for isIntersectionSphere
Oliver Sand 12 years ago
parent
commit
1269d968fb
2 changed files with 13 additions and 2 deletions
  1. 4 2
      src/math/Sphere.js
  2. 9 0
      test/unit/math/Sphere.js

+ 4 - 2
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 ) );
 		
 	},
 

+ 9 - 0
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 );