Explorar o código

Math: Make use of Static initialization blocks. (#33140)

PoseidonEnergy hai 2 meses
pai
achega
4fad923a7f
Modificáronse 6 ficheiros con 75 adicións e 51 borrados
  1. 13 9
      src/math/Matrix2.js
  2. 13 9
      src/math/Matrix3.js
  3. 13 9
      src/math/Matrix4.js
  4. 11 7
      src/math/Vector2.js
  5. 12 8
      src/math/Vector3.js
  6. 13 9
      src/math/Vector4.js

+ 13 - 9
src/math/Matrix2.js

@@ -26,6 +26,19 @@
  */
 export class Matrix2 {
 
+	static {
+
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {boolean}
+		 * @readonly
+		 * @default true
+		 */
+		Matrix2.prototype.isMatrix2 = true;
+
+	}
+
 	/**
 	 * Constructs a new 2x2 matrix. The arguments are supposed to be
 	 * in row-major order. If no arguments are provided, the constructor
@@ -38,15 +51,6 @@ export class Matrix2 {
 	 */
 	constructor( n11, n12, n21, n22 ) {
 
-		/**
-		 * This flag can be used for type testing.
-		 *
-		 * @type {boolean}
-		 * @readonly
-		 * @default true
-		 */
-		Matrix2.prototype.isMatrix2 = true;
-
 		/**
 		 * A column-major list of matrix values.
 		 *

+ 13 - 9
src/math/Matrix3.js

@@ -28,6 +28,19 @@
  */
 class Matrix3 {
 
+	static {
+
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {boolean}
+		 * @readonly
+		 * @default true
+		 */
+		Matrix3.prototype.isMatrix3 = true;
+
+	}
+
 	/**
 	 * Constructs a new 3x3 matrix. The arguments are supposed to be
 	 * in row-major order. If no arguments are provided, the constructor
@@ -45,15 +58,6 @@ class Matrix3 {
 	 */
 	constructor( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
 
-		/**
-		 * This flag can be used for type testing.
-		 *
-		 * @type {boolean}
-		 * @readonly
-		 * @default true
-		 */
-		Matrix3.prototype.isMatrix3 = true;
-
 		/**
 		 * A column-major list of matrix values.
 		 *

+ 13 - 9
src/math/Matrix4.js

@@ -41,6 +41,19 @@ import { Vector3 } from './Vector3.js';
  */
 class Matrix4 {
 
+	static {
+
+		/**
+		 * This flag can be used for type testing.
+		 *
+		 * @type {boolean}
+		 * @readonly
+		 * @default true
+		 */
+		Matrix4.prototype.isMatrix4 = true;
+
+	}
+
 	/**
 	 * Constructs a new 4x4 matrix. The arguments are supposed to be
 	 * in row-major order. If no arguments are provided, the constructor
@@ -65,15 +78,6 @@ class Matrix4 {
 	 */
 	constructor( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
 
-		/**
-		 * This flag can be used for type testing.
-		 *
-		 * @type {boolean}
-		 * @readonly
-		 * @default true
-		 */
-		Matrix4.prototype.isMatrix4 = true;
-
 		/**
 		 * A column-major list of matrix values.
 		 *

+ 11 - 7
src/math/Vector2.js

@@ -27,13 +27,7 @@ import { clamp } from './MathUtils.js';
  */
 class Vector2 {
 
-	/**
-	 * Constructs a new 2D vector.
-	 *
-	 * @param {number} [x=0] - The x value of this vector.
-	 * @param {number} [y=0] - The y value of this vector.
-	 */
-	constructor( x = 0, y = 0 ) {
+	static {
 
 		/**
 		 * This flag can be used for type testing.
@@ -44,6 +38,16 @@ class Vector2 {
 		 */
 		Vector2.prototype.isVector2 = true;
 
+	}
+
+	/**
+	 * Constructs a new 2D vector.
+	 *
+	 * @param {number} [x=0] - The x value of this vector.
+	 * @param {number} [y=0] - The y value of this vector.
+	 */
+	constructor( x = 0, y = 0 ) {
+
 		/**
 		 * The x value of this vector.
 		 *

+ 12 - 8
src/math/Vector3.js

@@ -28,14 +28,7 @@ import { Quaternion } from './Quaternion.js';
  */
 class Vector3 {
 
-	/**
-	 * Constructs a new 3D vector.
-	 *
-	 * @param {number} [x=0] - The x value of this vector.
-	 * @param {number} [y=0] - The y value of this vector.
-	 * @param {number} [z=0] - The z value of this vector.
-	 */
-	constructor( x = 0, y = 0, z = 0 ) {
+	static {
 
 		/**
 		 * This flag can be used for type testing.
@@ -46,6 +39,17 @@ class Vector3 {
 		 */
 		Vector3.prototype.isVector3 = true;
 
+	}
+
+	/**
+	 * Constructs a new 3D vector.
+	 *
+	 * @param {number} [x=0] - The x value of this vector.
+	 * @param {number} [y=0] - The y value of this vector.
+	 * @param {number} [z=0] - The z value of this vector.
+	 */
+	constructor( x = 0, y = 0, z = 0 ) {
+
 		/**
 		 * The x value of this vector.
 		 *

+ 13 - 9
src/math/Vector4.js

@@ -26,15 +26,7 @@ import { clamp } from './MathUtils.js';
  */
 class Vector4 {
 
-	/**
-	 * Constructs a new 4D vector.
-	 *
-	 * @param {number} [x=0] - The x value of this vector.
-	 * @param {number} [y=0] - The y value of this vector.
-	 * @param {number} [z=0] - The z value of this vector.
-	 * @param {number} [w=1] - The w value of this vector.
-	 */
-	constructor( x = 0, y = 0, z = 0, w = 1 ) {
+	static {
 
 		/**
 		 * This flag can be used for type testing.
@@ -45,6 +37,18 @@ class Vector4 {
 		 */
 		Vector4.prototype.isVector4 = true;
 
+	}
+
+	/**
+	 * Constructs a new 4D vector.
+	 *
+	 * @param {number} [x=0] - The x value of this vector.
+	 * @param {number} [y=0] - The y value of this vector.
+	 * @param {number} [z=0] - The z value of this vector.
+	 * @param {number} [w=1] - The w value of this vector.
+	 */
+	constructor( x = 0, y = 0, z = 0, w = 1 ) {
+
 		/**
 		 * The x value of this vector.
 		 *

粤ICP备19079148号