Browse Source

Vector*, Quaternion toArray: cleaner code

arose 10 years ago
parent
commit
9c30286b38
4 changed files with 27 additions and 55 deletions
  1. 8 15
      src/math/Quaternion.js
  2. 5 12
      src/math/Vector2.js
  3. 6 13
      src/math/Vector3.js
  4. 8 15
      src/math/Vector4.js

+ 8 - 15
src/math/Quaternion.js

@@ -482,25 +482,18 @@ THREE.Quaternion.prototype = {
 		return this;
 
 	},
-	
-	toArray: function ( array, offset ) {
-
-		if ( array ) {
 
-			if ( offset === undefined ) offset = 0;
-
-			array[ offset ] = this._x;
-			array[ offset + 1 ] = this._y;
-			array[ offset + 2 ] = this._z;
-			array[ offset + 3 ] = this._w;
-			
-			return array;
+	toArray: function ( array, offset ) {
 
-		} else {
+		if ( array === undefined ) array = [];
+		if ( offset === undefined ) offset = 0;
 
-			return [ this._x, this._y, this._z, this._w ];
+		array[ offset ] = this._x;
+		array[ offset + 1 ] = this._y;
+		array[ offset + 2 ] = this._z;
+		array[ offset + 3 ] = this._w;
 
-		}
+		return array;
 
 	},
 

+ 5 - 12
src/math/Vector2.js

@@ -388,20 +388,13 @@ THREE.Vector2.prototype = {
 
 	toArray: function ( array, offset ) {
 
-		if ( array ) {
-
-			if ( offset === undefined ) offset = 0;
-
-			array[ offset ] = this.x;
-			array[ offset + 1 ] = this.y;
-			
-			return array;
-
-		} else {
+		if ( array === undefined ) array = [];
+		if ( offset === undefined ) offset = 0;
 
-			return [ this.x, this.y ];
+		array[ offset ] = this.x;
+		array[ offset + 1 ] = this.y;
 
-		}
+		return array;
 
 	},
 

+ 6 - 13
src/math/Vector3.js

@@ -798,21 +798,14 @@ THREE.Vector3.prototype = {
 
 	toArray: function ( array, offset ) {
 
-		if ( array ) {
-
-			if ( offset === undefined ) offset = 0;
-
-			array[ offset ] = this.x;
-			array[ offset + 1 ] = this.y;
-			array[ offset + 2 ] = this.z;
-			
-			return array;
-
-		} else {
+		if ( array === undefined ) array = [];
+		if ( offset === undefined ) offset = 0;
 
-			return [ this.x, this.y, this.z ];
+		array[ offset ] = this.x;
+		array[ offset + 1 ] = this.y;
+		array[ offset + 2 ] = this.z;
 
-		}
+		return array;
 
 	},
 

+ 8 - 15
src/math/Vector4.js

@@ -633,25 +633,18 @@ THREE.Vector4.prototype = {
 		return this;
 
 	},
-	
-	toArray: function ( array, offset ) {
-
-		if ( array ) {
 
-			if ( offset === undefined ) offset = 0;
-
-			array[ offset ] = this.x;
-			array[ offset + 1 ] = this.y;
-			array[ offset + 2 ] = this.z;
-			array[ offset + 3 ] = this.w;
-			
-			return array;
+	toArray: function ( array, offset ) {
 
-		} else {
+		if ( array === undefined ) array = [];
+		if ( offset === undefined ) offset = 0;
 
-			return [ this.x, this.y, this.z, this.w ];
+		array[ offset ] = this.x;
+		array[ offset + 1 ] = this.y;
+		array[ offset + 2 ] = this.z;
+		array[ offset + 3 ] = this.w;
 
-		}
+		return array;
 
 	},