فهرست منبع

Add unit test, fix is isIntersectionSphere

Add missing space
Fix isIntersectionSphere
Addunit test for isIntersectionSphere
Oliver Sand 12 سال پیش
والد
کامیت
1269d968fb
2فایلهای تغییر یافته به همراه13 افزوده شده و 2 حذف شده
  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 );