Browse Source

ensure result is a new object (feedback from @gero3)

Ben Houston 12 years ago
parent
commit
ae3164787e
1 changed files with 5 additions and 5 deletions
  1. 5 5
      src/core/Sphere.js

+ 5 - 5
src/core/Sphere.js

@@ -67,15 +67,15 @@ THREE.Sphere.prototype = {
 
 		var deltaLengthSq = this.center.distanceToSquared( point );
 
-		if( deltaLengthSq > ( this.radius * this.radius ) ) {
+		var result = new THREE.Vector3().copy( point );
 
-			var delta = new THREE.Vector3().sub( point, center ).normalize();
-			delta.multiplyScalar( this.radius ).addSelf( this.center );
+		if( deltaLengthSq > ( this.radius * this.radius ) ) {
 
-			return delta;
+			result.subSelf( center ).normalize();
+			result.multiplyScalar( this.radius ).addSelf( this.center );
 		}
 
-		return point;
+		return result;
 	},
 
 	bounds: function () {