Browse Source

Vector*: Simplified setLength(). See #7326.

Mr.doob 9 years ago
parent
commit
fc881d66b4
3 changed files with 7 additions and 25 deletions
  1. 2 8
      src/math/Vector2.js
  2. 3 9
      src/math/Vector3.js
  3. 2 8
      src/math/Vector4.js

+ 2 - 8
src/math/Vector2.js

@@ -379,15 +379,9 @@ THREE.Vector2.prototype = {
 
 	},
 
-	setLength: function ( l ) {
+	setLength: function ( length ) {
 
-		var oldLength = this.length();
-
-		if ( oldLength !== 0 && l !== oldLength ) {
-
-			this.multiplyScalar( l / oldLength );
-
-		}
+		this.multiplyScalar( length / this.length() );
 
 		return this;
 

+ 3 - 9
src/math/Vector3.js

@@ -584,15 +584,9 @@ THREE.Vector3.prototype = {
 
 	},
 
-	setLength: function ( l ) {
+	setLength: function ( length ) {
 
-		var oldLength = this.length();
-
-		if ( oldLength !== 0 && l !== oldLength  ) {
-
-			this.multiplyScalar( l / oldLength );
-
-		}
+		this.multiplyScalar( length / this.length() );
 
 		return this;
 
@@ -701,7 +695,7 @@ THREE.Vector3.prototype = {
 
 	angleTo: function ( v ) {
 
-		var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
+		var theta = this.dot( v ) / Math.sqrt( this.lengthSq() * v.lengthSq() );
 
 		// clamp, to handle numerical problems
 

+ 2 - 8
src/math/Vector4.js

@@ -589,15 +589,9 @@ THREE.Vector4.prototype = {
 
 	},
 
-	setLength: function ( l ) {
+	setLength: function ( length ) {
 
-		var oldLength = this.length();
-
-		if ( oldLength !== 0 && l !== oldLength ) {
-
-			this.multiplyScalar( l / oldLength );
-
-		}
+		this.multiplyScalar( length / this.length() );
 
 		return this;