Pārlūkot izejas kodu

Merge pull request #7380 from Mugen87/dev

Put isIntersectionSphere inside a closure
Mr.doob 9 gadi atpakaļ
vecāks
revīzija
8b06dfda73
1 mainītis faili ar 14 papildinājumiem un 6 dzēšanām
  1. 14 6
      src/math/Box3.js

+ 14 - 6
src/math/Box3.js

@@ -247,15 +247,23 @@ THREE.Box3.prototype = {
 
 	},
 
-	isIntersectionSphere: function ( sphere ) {
+	isIntersectionSphere: function () {
 
-		// Find the point on the AABB closest to the sphere center.
-		var closestPoint = this.clampPoint( sphere.center );
+	  var closestPoint;
 
-		// If that point is inside the sphere, the AABB and sphere intersect.
-		return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius )
+	  return function isIntersectionSphere( sphere ) {
 
-	},
+	    if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
+
+	    // Find the point on the AABB closest to the sphere center.
+	    this.clampPoint( sphere.center, closestPoint );
+
+	    // If that point is inside the sphere, the AABB and sphere intersect.
+	    return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
+
+	  };
+
+	}(),
 
 	clampPoint: function ( point, optionalTarget ) {