Browse Source

more compact version of clampLength

Mugen87 9 years ago
parent
commit
3b8338c746
2 changed files with 4 additions and 16 deletions
  1. 2 8
      src/math/Vector2.js
  2. 2 8
      src/math/Vector3.js

+ 2 - 8
src/math/Vector2.js

@@ -292,15 +292,9 @@ THREE.Vector2.prototype = {
 
 	clampLength: function ( min, max ) {
 
-		var oldLength = this.length();
-
-		var newLength = ( oldLength < min ) ? min : ( ( oldLength > max ) ? max : oldLength );
-
-		if ( oldLength !== 0 && newLength !== oldLength ) {
+		var length = this.length();
 
-			this.multiplyScalar( newLength / oldLength );
-
-		}
+		this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
 
 		return this;
 

+ 2 - 8
src/math/Vector3.js

@@ -522,15 +522,9 @@ THREE.Vector3.prototype = {
 
 	clampLength: function ( min, max ) {
 
-		var oldLength = this.length();
-
-		var newLength = ( oldLength < min ) ? min : ( ( oldLength > max ) ? max : oldLength );
-
-		if ( oldLength !== 0 && newLength !== oldLength ) {
+		var length = this.length();
 
-			this.multiplyScalar( newLength / oldLength );
-
-		}
+		this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
 
 		return this;