Browse Source

Code clean up.

Mr.doob 11 years ago
parent
commit
174ed38ff5
3 changed files with 116 additions and 62 deletions
  1. 35 17
      src/math/Vector2.js
  2. 38 20
      src/math/Vector3.js
  3. 43 25
      src/math/Vector4.js

+ 35 - 17
src/math/Vector2.js

@@ -227,46 +227,64 @@ THREE.Vector2.prototype = {
 	},
 
 	clampScalar: ( function () {
+
 		var min, max;
 
 		return function ( minVal, maxVal ) {
-			if ( !min || !max ) {
+
+			if ( min === undefined ) {
+
 				min = new THREE.Vector2();
 				max = new THREE.Vector2();
+
 			}
 
-			min.set(minVal, minVal);
-			max.set(maxVal, maxVal);
-			return this.clamp(min, max);
+			min.set( minVal, minVal );
+			max.set( maxVal, maxVal );
+
+			return this.clamp( min, max );
 
 		};
+		
 	} )(),
 
-	floor: function() {
-		this.x = Math.floor(this.x);
-		this.y = Math.floor(this.y);
+	floor: function () {
+
+		this.x = Math.floor( this.x );
+		this.y = Math.floor( this.y );
+
 		return this;
+
 	},
 
-	ceil: function() {
-		this.x = Math.ceil(this.x);
-		this.y = Math.ceil(this.y);
+	ceil: function () {
+
+		this.x = Math.ceil( this.x );
+		this.y = Math.ceil( this.y );
+
 		return this;
+
 	},
 
-	round: function() {
-		this.x = Math.round(this.x);
-		this.y = Math.round(this.y);
+	round: function () {
+
+		this.x = Math.round( this.x );
+		this.y = Math.round( this.y );
+
 		return this;
+
 	},
 
-	roundToZero: function() {
-		this.x = (this.x < 0) ? Math.ceil(this.x) : Math.floor(this.x);
-		this.y = (this.y < 0) ? Math.ceil(this.y) : Math.floor(this.y);
+	roundToZero: function () {
+
+		this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
+		this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
+
 		return this;
+
 	},
 
-	negate: function() {
+	negate: function () {
 
 		return this.multiplyScalar( - 1 );
 

+ 38 - 20
src/math/Vector3.js

@@ -405,47 +405,65 @@ THREE.Vector3.prototype = {
 	},
 
 	clampScalar: ( function () {
+
 		var min, max;
 
 		return function ( minVal, maxVal ) {
-			if ( !min || !max ) {
+
+			if ( min === undefined ) {
+
 				min = new THREE.Vector3();
 				max = new THREE.Vector3();
+
 			}
 
-			min.set(minVal, minVal, minVal);
-			max.set(maxVal, maxVal, maxVal);
-			return this.clamp(min, max);
+			min.set( minVal, minVal, minVal );
+			max.set( maxVal, maxVal, maxVal );
+
+			return this.clamp( min, max );
 
 		};
+
 	} )(),
 
-	floor: function() {
-		this.x = Math.floor(this.x);
-		this.y = Math.floor(this.y);
-		this.z = Math.floor(this.z);
+	floor: function () {
+
+		this.x = Math.floor( this.x );
+		this.y = Math.floor( this.y );
+		this.z = Math.floor( this.z );
+
 		return this;
+
 	},
 
-	ceil: function() {
-		this.x = Math.ceil(this.x);
-		this.y = Math.ceil(this.y);
-		this.z = Math.ceil(this.z);
+	ceil: function () {
+
+		this.x = Math.ceil( this.x );
+		this.y = Math.ceil( this.y );
+		this.z = Math.ceil( this.z );
+
 		return this;
+
 	},
 
-	round: function() {
-		this.x = Math.round(this.x);
-		this.y = Math.round(this.y);
-		this.z = Math.round(this.z);
+	round: function () {
+
+		this.x = Math.round( this.x );
+		this.y = Math.round( this.y );
+		this.z = Math.round( this.z );
+
 		return this;
+
 	},
 
-	roundToZero: function() {
-		this.x = (this.x < 0) ? Math.ceil(this.x) : Math.floor(this.x);
-		this.y = (this.y < 0) ? Math.ceil(this.y) : Math.floor(this.y);
-		this.z = (this.z < 0) ? Math.ceil(this.z) : Math.floor(this.z);
+	roundToZero: function () {
+
+		this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
+		this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
+		this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
+
 		return this;
+
 	},
 
 	negate: function () {

+ 43 - 25
src/math/Vector4.js

@@ -484,54 +484,72 @@ THREE.Vector4.prototype = {
 	},
 
 	clampScalar: ( function () {
+
 		var min, max;
 
 		return function ( minVal, maxVal ) {
-			if ( !min || !max ) {
+
+			if ( min === undefined ) {
+
 				min = new THREE.Vector4();
 				max = new THREE.Vector4();
+
 			}
 
-			min.set(minVal, minVal, minVal, minVal);
-			max.set(maxVal, maxVal, maxVal, maxVal);
-			return this.clamp(min, max);
+			min.set( minVal, minVal, minVal, minVal );
+			max.set( maxVal, maxVal, maxVal, maxVal );
+
+			return this.clamp( min, max );
 
 		};
+
 	} )(),
 
-    floor: function() {
-        this.x = Math.floor(this.x);
-        this.y = Math.floor(this.y);
-        this.z = Math.floor(this.z);
-        this.w = Math.floor(this.w);
+    floor: function () {
+
+        this.x = Math.floor( this.x );
+        this.y = Math.floor( this.y );
+        this.z = Math.floor( this.z );
+        this.w = Math.floor( this.w );
+
         return this;
+
     },
 
-    ceil: function() {
-        this.x = Math.ceil(this.x);
-        this.y = Math.ceil(this.y);
-        this.z = Math.ceil(this.z);
-        this.w = Math.ceil(this.w);
+    ceil: function () {
+
+        this.x = Math.ceil( this.x );
+        this.y = Math.ceil( this.y );
+        this.z = Math.ceil( this.z );
+        this.w = Math.ceil( this.w );
+
         return this;
+
     },
 
-    round: function() {
-        this.x = Math.round(this.x);
-        this.y = Math.round(this.y);
-        this.z = Math.round(this.z);
-        this.w = Math.round(this.w);
+    round: function () {
+
+        this.x = Math.round( this.x );
+        this.y = Math.round( this.y );
+        this.z = Math.round( this.z );
+        this.w = Math.round( this.w );
+
         return this;
+
     },
 
-    roundToZero: function() {
-        this.x = (this.x < 0) ? Math.ceil(this.x) : Math.floor(this.x);
-        this.y = (this.y < 0) ? Math.ceil(this.y) : Math.floor(this.y);
-        this.z = (this.z < 0) ? Math.ceil(this.z) : Math.floor(this.z);
-        this.w = (this.w < 0) ? Math.ceil(this.w) : Math.floor(this.w);
+    roundToZero: function () {
+
+        this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
+        this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
+        this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
+        this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
+
         return this;
+
     },
 
-	negate: function() {
+	negate: function () {
 
 		return this.multiplyScalar( -1 );