Browse Source

added random method to vectors

Adding a method that sets the components of the vector with a random
number [0-1]
EthanHermsey 5 năm trước cách đây
mục cha
commit
1530a4cb96
6 tập tin đã thay đổi với 51 bổ sung6 xóa
  1. 6 1
      src/math/Vector2.d.ts
  2. 10 1
      src/math/Vector2.js
  3. 6 1
      src/math/Vector3.d.ts
  4. 11 1
      src/math/Vector3.js
  5. 6 1
      src/math/Vector4.d.ts
  6. 12 1
      src/math/Vector4.js

+ 6 - 1
src/math/Vector2.d.ts

@@ -457,6 +457,11 @@ export class Vector2 implements Vector {
 	 *
 	 * @see {@link http://en.wikipedia.org/wiki/Taxicab_geometry|Wikipedia: Taxicab Geometry}
 	 */
-	manhattanDistanceTo( v: Vector2 ): number;
+    manhattanDistanceTo( v: Vector2 ): number;
+    
+    /**
+	 * Sets this vector's x and y from Math.random
+	 */
+	random(): this;
 
 }

+ 10 - 1
src/math/Vector2.js

@@ -482,7 +482,16 @@ Object.assign( Vector2.prototype, {
 
 		return this;
 
-	}
+    },
+    
+    random: function () {
+
+        this.x = Math.random();
+        this.y = Math.random();
+
+        return this;
+
+    }
 
 } );
 

+ 6 - 1
src/math/Vector3.d.ts

@@ -285,6 +285,11 @@ export class Vector3 implements Vector {
 		attribute: BufferAttribute,
 		index: number,
 		offset?: number
-	): this;
+    ): this;
+    
+    /**
+	 * Sets this vector's x, y and z from Math.random
+	 */
+	random(): this;
 
 }

+ 11 - 1
src/math/Vector3.js

@@ -712,7 +712,17 @@ Object.assign( Vector3.prototype, {
 
 		return this;
 
-	}
+	},
+    
+    random: function () {
+
+        this.x = Math.random();
+        this.y = Math.random();
+        this.z = Math.random();
+
+        return this;
+        
+    }
 
 } );
 

+ 6 - 1
src/math/Vector4.d.ts

@@ -208,6 +208,11 @@ export class Vector4 implements Vector {
 		attribute: BufferAttribute,
 		index: number,
 		offset?: number
-	): this;
+    ): this;
+    
+    /**
+	 * Sets this vector's x, y, z and w from Math.random
+	 */
+	random(): this;
 
 }

+ 12 - 1
src/math/Vector4.js

@@ -646,7 +646,18 @@ Object.assign( Vector4.prototype, {
 
 		return this;
 
-	}
+	},
+    
+    random: function () {
+
+        this.x = Math.random();
+        this.y = Math.random();
+        this.z = Math.random();
+        this.w = Math.random();
+
+        return this;
+        
+    }
 
 } );