@lakuna/umath 1.4.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/index.d.ts +6 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +11 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/linalg/DualQuaternion.d.ts +23 -46
  6. package/dist/linalg/DualQuaternion.d.ts.map +1 -1
  7. package/dist/linalg/DualQuaternion.js +47 -70
  8. package/dist/linalg/DualQuaternion.js.map +1 -1
  9. package/dist/linalg/Matrix2.d.ts +16 -30
  10. package/dist/linalg/Matrix2.d.ts.map +1 -1
  11. package/dist/linalg/Matrix2.js +30 -44
  12. package/dist/linalg/Matrix2.js.map +1 -1
  13. package/dist/linalg/Matrix3.d.ts +21 -42
  14. package/dist/linalg/Matrix3.d.ts.map +1 -1
  15. package/dist/linalg/Matrix3.js +43 -84
  16. package/dist/linalg/Matrix3.js.map +1 -1
  17. package/dist/linalg/Matrix4.d.ts +40 -79
  18. package/dist/linalg/Matrix4.d.ts.map +1 -1
  19. package/dist/linalg/Matrix4.js +86 -171
  20. package/dist/linalg/Matrix4.js.map +1 -1
  21. package/dist/linalg/Quaternion.d.ts +29 -60
  22. package/dist/linalg/Quaternion.d.ts.map +1 -1
  23. package/dist/linalg/Quaternion.js +54 -85
  24. package/dist/linalg/Quaternion.js.map +1 -1
  25. package/dist/linalg/SlowMatrix.d.ts.map +1 -1
  26. package/dist/linalg/SlowMatrix.js +52 -78
  27. package/dist/linalg/SlowMatrix.js.map +1 -1
  28. package/dist/linalg/SlowSquareMatrix.js +1 -1
  29. package/dist/linalg/SlowSquareMatrix.js.map +1 -1
  30. package/dist/linalg/SlowVector.d.ts +165 -0
  31. package/dist/linalg/SlowVector.d.ts.map +1 -0
  32. package/dist/linalg/SlowVector.js +369 -0
  33. package/dist/linalg/SlowVector.js.map +1 -0
  34. package/dist/linalg/Vector.d.ts +20 -15
  35. package/dist/linalg/Vector.d.ts.map +1 -1
  36. package/dist/linalg/Vector2.d.ts +42 -48
  37. package/dist/linalg/Vector2.d.ts.map +1 -1
  38. package/dist/linalg/Vector2.js +74 -82
  39. package/dist/linalg/Vector2.js.map +1 -1
  40. package/dist/linalg/Vector3.d.ts +46 -56
  41. package/dist/linalg/Vector3.d.ts.map +1 -1
  42. package/dist/linalg/Vector3.js +82 -104
  43. package/dist/linalg/Vector3.js.map +1 -1
  44. package/dist/linalg/Vector4.d.ts +40 -44
  45. package/dist/linalg/Vector4.d.ts.map +1 -1
  46. package/dist/linalg/Vector4.js +69 -79
  47. package/dist/linalg/Vector4.js.map +1 -1
  48. package/dist/utility/MatrixSizeError.d.ts +1 -1
  49. package/dist/utility/MatrixSizeError.d.ts.map +1 -1
  50. package/dist/utility/MatrixSizeError.js +1 -1
  51. package/dist/utility/MatrixSizeError.js.map +1 -1
  52. package/dist/utility/VectorSizeError.d.ts +12 -0
  53. package/dist/utility/VectorSizeError.d.ts.map +1 -0
  54. package/dist/utility/VectorSizeError.js +15 -0
  55. package/dist/utility/VectorSizeError.js.map +1 -0
  56. package/dist/utility/createAxisAngleLike.d.ts +10 -0
  57. package/dist/utility/createAxisAngleLike.d.ts.map +1 -0
  58. package/dist/utility/createAxisAngleLike.js +10 -0
  59. package/dist/utility/createAxisAngleLike.js.map +1 -0
  60. package/package.json +8 -10
  61. package/src/index.ts +16 -0
  62. package/src/linalg/DualQuaternion.ts +51 -134
  63. package/src/linalg/Matrix2.ts +32 -83
  64. package/src/linalg/Matrix3.ts +55 -149
  65. package/src/linalg/Matrix4.ts +136 -292
  66. package/src/linalg/Quaternion.ts +62 -153
  67. package/src/linalg/SlowMatrix.ts +82 -81
  68. package/src/linalg/SlowSquareMatrix.ts +1 -1
  69. package/src/linalg/SlowVector.ts +449 -0
  70. package/src/linalg/Vector.ts +21 -16
  71. package/src/linalg/Vector2.ts +84 -147
  72. package/src/linalg/Vector3.ts +102 -188
  73. package/src/linalg/Vector4.ts +88 -137
  74. package/src/utility/MatrixSizeError.ts +1 -1
  75. package/src/utility/VectorSizeError.ts +14 -0
  76. package/src/utility/createAxisAngleLike.ts +13 -0
@@ -234,7 +234,7 @@ export const fromRotation = <T extends Matrix4Like>(
234
234
  let y = axis[1];
235
235
  let z = axis[2];
236
236
 
237
- let len = Math.sqrt(x * x + y * y + z * z);
237
+ let len = Math.hypot(x, y, z);
238
238
  if (len === 0) {
239
239
  throw new MagnitudeError();
240
240
  }
@@ -941,7 +941,7 @@ export const lookAt = <T extends Matrix4Like>(
941
941
  let z0 = eyex - centerx;
942
942
  let z1 = eyey - centery;
943
943
  let z2 = eyez - centerz;
944
- let len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); // `Math.hypot` is slower.
944
+ let len = 1 / Math.hypot(z0, z1, z2);
945
945
  z0 *= len;
946
946
  z1 *= len;
947
947
  z2 *= len;
@@ -949,7 +949,7 @@ export const lookAt = <T extends Matrix4Like>(
949
949
  let x0 = upy * z2 - upz * z1;
950
950
  let x1 = upz * z0 - upx * z2;
951
951
  let x2 = upx * z1 - upy * z0;
952
- len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
952
+ len = Math.hypot(x0, x1, x2);
953
953
  if (len) {
954
954
  len = 1 / len;
955
955
  x0 *= len;
@@ -964,7 +964,7 @@ export const lookAt = <T extends Matrix4Like>(
964
964
  let y0 = z1 * x2 - z2 * x1;
965
965
  let y1 = z2 * x0 - z0 * x2;
966
966
  let y2 = z0 * x1 - z1 * x0;
967
- len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
967
+ len = Math.hypot(y0, y1, y2);
968
968
  if (len) {
969
969
  len = 1 / len;
970
970
  y0 *= len;
@@ -1000,7 +1000,7 @@ export const lookAt = <T extends Matrix4Like>(
1000
1000
  /**
1001
1001
  * Create a matrix that makes something look at something else.
1002
1002
  * @param eye - The position of the viewer.
1003
- * @param center - The point that the viewer is looking at.
1003
+ * @param target - The point that the viewer is looking at.
1004
1004
  * @param up - The local up direction.
1005
1005
  * @param out - The matrix to store the result in.
1006
1006
  * @returns The transformation matrix.
@@ -1246,44 +1246,25 @@ export const copy = <T extends Matrix4Like>(matrix: Matrix4Like, out: T): T =>
1246
1246
  * @see {@link https://en.wikipedia.org/wiki/Matrix_norm | Matrix norm}
1247
1247
  * @public
1248
1248
  */
1249
- export const frob = (matrix: Matrix4Like): number => {
1250
- const a00 = matrix[0];
1251
- const a01 = matrix[1];
1252
- const a02 = matrix[2];
1253
- const a03 = matrix[3];
1254
- const a10 = matrix[4];
1255
- const a11 = matrix[5];
1256
- const a12 = matrix[6];
1257
- const a13 = matrix[7];
1258
- const a20 = matrix[8];
1259
- const a21 = matrix[9];
1260
- const a22 = matrix[10];
1261
- const a23 = matrix[11];
1262
- const a30 = matrix[12];
1263
- const a31 = matrix[13];
1264
- const a32 = matrix[14];
1265
- const a33 = matrix[15];
1266
-
1267
- // `Math.hypot` is slower.
1268
- return Math.sqrt(
1269
- a00 * a00 +
1270
- a01 * a01 +
1271
- a02 * a02 +
1272
- a03 * a03 +
1273
- a10 * a10 +
1274
- a11 * a11 +
1275
- a12 * a12 +
1276
- a13 * a13 +
1277
- a20 * a20 +
1278
- a21 * a21 +
1279
- a22 * a22 +
1280
- a23 * a23 +
1281
- a30 * a30 +
1282
- a31 * a31 +
1283
- a32 * a32 +
1284
- a33 * a33
1249
+ export const frob = (matrix: Matrix4Like): number =>
1250
+ Math.hypot(
1251
+ matrix[0],
1252
+ matrix[1],
1253
+ matrix[2],
1254
+ matrix[3],
1255
+ matrix[4],
1256
+ matrix[5],
1257
+ matrix[6],
1258
+ matrix[7],
1259
+ matrix[8],
1260
+ matrix[9],
1261
+ matrix[10],
1262
+ matrix[11],
1263
+ matrix[12],
1264
+ matrix[13],
1265
+ matrix[14],
1266
+ matrix[15]
1285
1267
  );
1286
- };
1287
1268
 
1288
1269
  /**
1289
1270
  * Multiply two matrices.
@@ -1739,7 +1720,7 @@ export const rotate = <T extends Matrix4Like>(
1739
1720
  let y = axis[1];
1740
1721
  let z = axis[2];
1741
1722
 
1742
- let len = Math.sqrt(x * x + y * y + z * z); // `Math.hypot` is slower.
1723
+ let len = Math.hypot(x, y, z);
1743
1724
  if (len < epsilon) {
1744
1725
  return out;
1745
1726
  }
@@ -2011,25 +1992,13 @@ export const setTranslation = <T extends Matrix4Like>(
2011
1992
  export const getScaling = <T extends Vector3Like>(
2012
1993
  matrix: Matrix4Like,
2013
1994
  out: T
2014
- ): T => {
2015
- const m11 = matrix[0];
2016
- const m12 = matrix[1];
2017
- const m13 = matrix[2];
2018
- const m21 = matrix[4];
2019
- const m22 = matrix[5];
2020
- const m23 = matrix[6];
2021
- const m31 = matrix[8];
2022
- const m32 = matrix[9];
2023
- const m33 = matrix[10];
2024
-
2025
- // `Math.hypot` is slower.
2026
- return vector3FromValues(
2027
- Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13),
2028
- Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23),
2029
- Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33),
1995
+ ): T =>
1996
+ vector3FromValues(
1997
+ Math.hypot(matrix[0], matrix[1], matrix[2]),
1998
+ Math.hypot(matrix[4], matrix[5], matrix[6]),
1999
+ Math.hypot(matrix[8], matrix[9], matrix[10]),
2030
2000
  out
2031
2001
  );
2032
- };
2033
2002
 
2034
2003
  /**
2035
2004
  * Get the rotational component of a transformation matrix.
@@ -2116,104 +2085,77 @@ export default class Matrix4
2116
2085
  /**
2117
2086
  * Create a transformation matrix that represents a translation by the given vector.
2118
2087
  * @param vector - The translation vector.
2119
- * @param out - The matrix to store the result in.
2120
2088
  * @returns The transformation matrix.
2121
2089
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2122
2090
  */
2123
- public static fromTranslation<T extends Matrix4Like = Matrix4>(
2124
- vector: Vector3Like,
2125
- out: T = new Matrix4() as Matrix4 & T
2126
- ): T {
2127
- return fromTranslation(vector, out);
2091
+ public static fromTranslation(vector: Vector3Like): Matrix4 {
2092
+ return fromTranslation(vector, new Matrix4());
2128
2093
  }
2129
2094
 
2130
2095
  /**
2131
2096
  * Create a transformation matrix that represents a scaling by the given vector.
2132
2097
  * @param vector - The scaling vector.
2133
- * @param out - The matrix to store the result in.
2134
2098
  * @returns The transformation matrix.
2135
2099
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2136
2100
  */
2137
- public static fromScaling<T extends Matrix4Like = Matrix4>(
2138
- vector: Vector3Like,
2139
- out: T = new Matrix4() as Matrix4 & T
2140
- ): T {
2141
- return fromScaling(vector, out);
2101
+ public static fromScaling(vector: Vector3Like): Matrix4 {
2102
+ return fromScaling(vector, new Matrix4());
2142
2103
  }
2143
2104
 
2144
2105
  /**
2145
2106
  * Create a transformation matrix that represents a rotation by the given angle around the Z-axis.
2146
2107
  * @param r - The angle in radians.
2147
2108
  * @param axis - The axis to rotate around.
2148
- * @param out - The matrix to store the result in.
2149
2109
  * @returns The transformation matrix.
2150
2110
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2151
2111
  */
2152
- public static fromRotation<T extends Matrix4Like = Matrix4>(
2153
- r: number,
2154
- axis: Vector3Like,
2155
- out: T = new Matrix4() as Matrix4 & T
2156
- ): T {
2157
- return fromRotation(r, axis, out);
2112
+ public static fromRotation(r: number, axis: Vector3Like): Matrix4 {
2113
+ return fromRotation(r, axis, new Matrix4());
2158
2114
  }
2159
2115
 
2160
2116
  /**
2161
2117
  * Create a transformation matrix that represents a rotation by the given angle around the X-axis.
2162
2118
  * @param r - The angle in radians.
2163
- * @param out - The matrix to store the result in.
2164
2119
  * @returns The transformation matrix.
2165
2120
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2166
2121
  */
2167
- public static fromXRotation<T extends Matrix4Like = Matrix4>(
2168
- r: number,
2169
- out: T = new Matrix4() as Matrix4 & T
2170
- ): T {
2171
- return fromXRotation(r, out);
2122
+ public static fromXRotation(r: number): Matrix4 {
2123
+ return fromXRotation(r, new Matrix4());
2172
2124
  }
2173
2125
 
2174
2126
  /**
2175
2127
  * Create a transformation matrix that represents a rotation by the given angle around the Y-axis.
2176
2128
  * @param r - The angle in radians.
2177
- * @param out - The matrix to store the result in.
2178
2129
  * @returns The transformation matrix.
2179
2130
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2180
2131
  */
2181
- public static fromYRotation<T extends Matrix4Like = Matrix4>(
2182
- r: number,
2183
- out: T = new Matrix4() as Matrix4 & T
2184
- ): T {
2185
- return fromYRotation(r, out);
2132
+ public static fromYRotation(r: number): Matrix4 {
2133
+ return fromYRotation(r, new Matrix4());
2186
2134
  }
2187
2135
 
2188
2136
  /**
2189
2137
  * Create a transformation matrix that represents a rotation by the given angle around the Z-axis.
2190
2138
  * @param r - The angle in radians.
2191
- * @param out - The matrix to store the result in.
2192
2139
  * @returns The transformation matrix.
2193
2140
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2194
2141
  */
2195
- public static fromZRotation<T extends Matrix4Like = Matrix4>(
2196
- r: number,
2197
- out: T = new Matrix4() as Matrix4 & T
2198
- ): T {
2199
- return fromZRotation(r, out);
2142
+ public static fromZRotation(r: number): Matrix4 {
2143
+ return fromZRotation(r, new Matrix4());
2200
2144
  }
2201
2145
 
2202
2146
  /**
2203
2147
  * Create a transformation matrix from the given rotation and translation.
2204
2148
  * @param rotation - The rotation quaternion.
2205
2149
  * @param translation - The translation vector.
2206
- * @param out - The matrix to store the result in.
2207
2150
  * @returns The transformation matrix.
2208
2151
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2209
2152
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2210
2153
  */
2211
- public static fromRotationTranslation<T extends Matrix4Like = Matrix4>(
2154
+ public static fromRotationTranslation(
2212
2155
  rotation: QuaternionLike,
2213
- translation: Vector3Like,
2214
- out: T = new Matrix4() as Matrix4 & T
2215
- ): T {
2216
- return fromRotationTranslation(rotation, translation, out);
2156
+ translation: Vector3Like
2157
+ ): Matrix4 {
2158
+ return fromRotationTranslation(rotation, translation, new Matrix4());
2217
2159
  }
2218
2160
 
2219
2161
  /**
@@ -2221,18 +2163,21 @@ export default class Matrix4
2221
2163
  * @param rotation - The rotation quaternion.
2222
2164
  * @param translation - The translation vector.
2223
2165
  * @param scaling - The scaling vector.
2224
- * @param out - The matrix to store the result in.
2225
2166
  * @returns The transformation matrix.
2226
2167
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2227
2168
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2228
2169
  */
2229
- public static fromRotationTranslationScale<T extends Matrix4Like = Matrix4>(
2170
+ public static fromRotationTranslationScale(
2230
2171
  rotation: QuaternionLike,
2231
2172
  translation: Vector3Like,
2232
- scaling: Vector3Like,
2233
- out: T = new Matrix4() as Matrix4 & T
2234
- ): T {
2235
- return fromRotationTranslationScale(rotation, translation, scaling, out);
2173
+ scaling: Vector3Like
2174
+ ): Matrix4 {
2175
+ return fromRotationTranslationScale(
2176
+ rotation,
2177
+ translation,
2178
+ scaling,
2179
+ new Matrix4()
2180
+ );
2236
2181
  }
2237
2182
 
2238
2183
  /**
@@ -2241,58 +2186,46 @@ export default class Matrix4
2241
2186
  * @param translation - The translation vector.
2242
2187
  * @param scaling - The scaling vector.
2243
2188
  * @param origin - The origin vector.
2244
- * @param out - The matrix to store the result in.
2245
2189
  * @returns The transformation matrix.
2246
2190
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2247
2191
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2248
2192
  */
2249
- public static fromRotationTranslationScaleOrigin<
2250
- T extends Matrix4Like = Matrix4
2251
- >(
2193
+ public static fromRotationTranslationScaleOrigin(
2252
2194
  rotation: QuaternionLike,
2253
2195
  translation: Vector3Like,
2254
2196
  scaling: Vector3Like,
2255
- origin: Vector3Like,
2256
- out: T = new Matrix4() as Matrix4 & T
2257
- ): T {
2197
+ origin: Vector3Like
2198
+ ): Matrix4 {
2258
2199
  return fromRotationTranslationScaleOrigin(
2259
2200
  rotation,
2260
2201
  translation,
2261
2202
  scaling,
2262
2203
  origin,
2263
- out
2204
+ new Matrix4()
2264
2205
  );
2265
2206
  }
2266
2207
 
2267
2208
  /**
2268
2209
  * Create a transformation matrix from a dual quaternion.
2269
2210
  * @param quaternion - The dual quaternion.
2270
- * @param out - The matrix to store the result in.
2271
2211
  * @returns The transformation matrix.
2272
2212
  * @see {@link https://en.wikipedia.org/wiki/Dual_quaternion | Dual quaternion}
2273
2213
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2274
2214
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2275
2215
  */
2276
- public static fromDualQuaternion<T extends Matrix4Like = Matrix4>(
2277
- quaternion: DualQuaternionLike,
2278
- out: T = new Matrix4() as Matrix4 & T
2279
- ): T {
2280
- return fromDualQuaternion(quaternion, out);
2216
+ public static fromDualQuaternion(quaternion: DualQuaternionLike): Matrix4 {
2217
+ return fromDualQuaternion(quaternion, new Matrix4());
2281
2218
  }
2282
2219
 
2283
2220
  /**
2284
2221
  * Create a transformation matrix from a quaternion.
2285
2222
  * @param quaternion - The quaternion.
2286
- * @param out - The matrix to store the result in.
2287
2223
  * @returns The transformation matrix.
2288
2224
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2289
2225
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2290
2226
  */
2291
- public static fromQuaternion<T extends Matrix4Like = Matrix4>(
2292
- quaternion: QuaternionLike,
2293
- out: T = new Matrix4() as Matrix4 & T
2294
- ): T {
2295
- return fromQuaternion(quaternion, out);
2227
+ public static fromQuaternion(quaternion: QuaternionLike): Matrix4 {
2228
+ return fromQuaternion(quaternion, new Matrix4());
2296
2229
  }
2297
2230
 
2298
2231
  /**
@@ -2303,21 +2236,19 @@ export default class Matrix4
2303
2236
  * @param top - The top bound of the frustum.
2304
2237
  * @param near - The near bound of the frustum.
2305
2238
  * @param far - The far bound of the frustum.
2306
- * @param out - The matrix to store the result in.
2307
2239
  * @returns The frustum matrix.
2308
2240
  * @see {@link https://en.wikipedia.org/wiki/Camera_matrix | Camera matrix}
2309
2241
  * @see {@link https://en.wikipedia.org/wiki/3D_projection | 3D projection}
2310
2242
  */
2311
- public static frustum<T extends Matrix4Like = Matrix4>(
2243
+ public static frustum(
2312
2244
  left: number,
2313
2245
  right: number,
2314
2246
  bottom: number,
2315
2247
  top: number,
2316
2248
  near: number,
2317
- far: number,
2318
- out: T = new Matrix4() as Matrix4 & T
2319
- ): T {
2320
- return frustum(left, right, bottom, top, near, far, out);
2249
+ far: number
2250
+ ): Matrix4 {
2251
+ return frustum(left, right, bottom, top, near, far, new Matrix4());
2321
2252
  }
2322
2253
 
2323
2254
  /**
@@ -2326,19 +2257,17 @@ export default class Matrix4
2326
2257
  * @param aspect - The aspect ratio (typically the width of the viewport divided by its height).
2327
2258
  * @param near - The near bound of the frustum.
2328
2259
  * @param far - The far bound of the frustum.
2329
- * @param out - The matrix to store the result in.
2330
2260
  * @returns The perspective projection matrix.
2331
2261
  * @see {@link https://en.wikipedia.org/wiki/Camera_matrix | Camera matrix}
2332
2262
  * @see {@link https://en.wikipedia.org/wiki/3D_projection | 3D projection}
2333
2263
  */
2334
- public static perspective<T extends Matrix4Like = Matrix4>(
2264
+ public static perspective(
2335
2265
  fov: number,
2336
2266
  aspect: number,
2337
2267
  near: number,
2338
- far: number,
2339
- out: T = new Matrix4() as Matrix4 & T
2340
- ): T {
2341
- return perspective(fov, aspect, near, far, out);
2268
+ far: number
2269
+ ): Matrix4 {
2270
+ return perspective(fov, aspect, near, far, new Matrix4());
2342
2271
  }
2343
2272
 
2344
2273
  /**
@@ -2347,19 +2276,17 @@ export default class Matrix4
2347
2276
  * @param aspect - The aspect ratio (typically the width of the viewport divided by its height).
2348
2277
  * @param near - The near bound of the frustum.
2349
2278
  * @param far - The far bound of the frustum.
2350
- * @param out - The matrix to store the result in.
2351
2279
  * @returns The perspective projection matrix.
2352
2280
  * @see {@link https://en.wikipedia.org/wiki/Camera_matrix | Camera matrix}
2353
2281
  * @see {@link https://en.wikipedia.org/wiki/3D_projection | 3D projection}
2354
2282
  */
2355
- public static perspectiveGpu<T extends Matrix4Like = Matrix4>(
2283
+ public static perspectiveGpu(
2356
2284
  fov: number,
2357
2285
  aspect: number,
2358
2286
  near: number,
2359
- far: number,
2360
- out: T = new Matrix4() as Matrix4 & T
2361
- ): T {
2362
- return perspectiveGpu(fov, aspect, near, far, out);
2287
+ far: number
2288
+ ): Matrix4 {
2289
+ return perspectiveGpu(fov, aspect, near, far, new Matrix4());
2363
2290
  }
2364
2291
 
2365
2292
  /**
@@ -2367,19 +2294,17 @@ export default class Matrix4
2367
2294
  * @param fov - The field of view.
2368
2295
  * @param near - The near bound of the frustum.
2369
2296
  * @param far - The far bound of the frustum.
2370
- * @param out - The matrix to store the result in.
2371
2297
  * @returns The perspective projection matrix.
2372
2298
  * @see {@link https://en.wikipedia.org/wiki/Camera_matrix | Camera matrix}
2373
2299
  * @see {@link https://en.wikipedia.org/wiki/3D_projection | 3D projection}
2374
2300
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WebXR_Device_API | WebXR API}
2375
2301
  */
2376
- public static perspectiveFromFieldOfView<T extends Matrix4Like = Matrix4>(
2302
+ public static perspectiveFromFieldOfView(
2377
2303
  fov: FieldOfView,
2378
2304
  near: number,
2379
- far: number,
2380
- out: T = new Matrix4() as Matrix4 & T
2381
- ): T {
2382
- return perspectiveFromFieldOfView(fov, near, far, out);
2305
+ far: number
2306
+ ): Matrix4 {
2307
+ return perspectiveFromFieldOfView(fov, near, far, new Matrix4());
2383
2308
  }
2384
2309
 
2385
2310
  /**
@@ -2390,21 +2315,19 @@ export default class Matrix4
2390
2315
  * @param top - The top bound of the frustum.
2391
2316
  * @param near - The near bound of the frustum.
2392
2317
  * @param far - The far bound of the frustum.
2393
- * @param out - The matrix to store the result in.
2394
2318
  * @returns The frustum matrix.
2395
2319
  * @see {@link https://en.wikipedia.org/wiki/Camera_matrix | Camera matrix}
2396
2320
  * @see {@link https://en.wikipedia.org/wiki/3D_projection | 3D projection}
2397
2321
  */
2398
- public static ortho<T extends Matrix4Like = Matrix4>(
2322
+ public static ortho(
2399
2323
  left: number,
2400
2324
  right: number,
2401
2325
  bottom: number,
2402
2326
  top: number,
2403
2327
  near: number,
2404
- far: number,
2405
- out: T = new Matrix4() as Matrix4 & T
2406
- ): T {
2407
- return ortho(left, right, bottom, top, near, far, out);
2328
+ far: number
2329
+ ): Matrix4 {
2330
+ return ortho(left, right, bottom, top, near, far, new Matrix4());
2408
2331
  }
2409
2332
 
2410
2333
  /**
@@ -2415,21 +2338,19 @@ export default class Matrix4
2415
2338
  * @param top - The top bound of the frustum.
2416
2339
  * @param near - The near bound of the frustum.
2417
2340
  * @param far - The far bound of the frustum.
2418
- * @param out - The matrix to store the result in.
2419
2341
  * @returns The frustum matrix.
2420
2342
  * @see {@link https://en.wikipedia.org/wiki/Camera_matrix | Camera matrix}
2421
2343
  * @see {@link https://en.wikipedia.org/wiki/3D_projection | 3D projection}
2422
2344
  */
2423
- public static orthoGpu<T extends Matrix4Like = Matrix4>(
2345
+ public static orthoGpu(
2424
2346
  left: number,
2425
2347
  right: number,
2426
2348
  bottom: number,
2427
2349
  top: number,
2428
2350
  near: number,
2429
- far: number,
2430
- out: T = new Matrix4() as Matrix4 & T
2431
- ): T {
2432
- return orthoGpu(left, right, bottom, top, near, far, out);
2351
+ far: number
2352
+ ): Matrix4 {
2353
+ return orthoGpu(left, right, bottom, top, near, far, new Matrix4());
2433
2354
  }
2434
2355
 
2435
2356
  /**
@@ -2437,17 +2358,15 @@ export default class Matrix4
2437
2358
  * @param eye - The position of the viewer.
2438
2359
  * @param center - The point that the viewer is looking at.
2439
2360
  * @param up - The local up direction.
2440
- * @param out - The matrix to store the result in.
2441
2361
  * @returns The look-at matrix.
2442
2362
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2443
2363
  */
2444
- public static lookAt<T extends Matrix4Like = Matrix4>(
2364
+ public static lookAt(
2445
2365
  eye: Vector3Like,
2446
2366
  center: Vector3Like,
2447
- up: Vector3Like = [0, 1, 0],
2448
- out: T = new Matrix4() as Matrix4 & T
2449
- ): T {
2450
- return lookAt(eye, center, up, out);
2367
+ up: Vector3Like = [0, 1, 0]
2368
+ ): Matrix4 {
2369
+ return lookAt(eye, center, up, new Matrix4());
2451
2370
  }
2452
2371
 
2453
2372
  /**
@@ -2455,17 +2374,15 @@ export default class Matrix4
2455
2374
  * @param eye - The position of the viewer.
2456
2375
  * @param target - The point that the viewer is looking at.
2457
2376
  * @param up - The local up direction.
2458
- * @param out - The matrix to store the result in.
2459
2377
  * @returns The transformation matrix.
2460
2378
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2461
2379
  */
2462
- public static targetTo<T extends Matrix4Like = Matrix4>(
2380
+ public static targetTo(
2463
2381
  eye: Vector3Like,
2464
2382
  target: Vector3Like,
2465
- up: Vector3Like = [0, 1, 0],
2466
- out: T = new Matrix4() as Matrix4 & T
2467
- ): T {
2468
- return targetTo(eye, target, up, out);
2383
+ up: Vector3Like = [0, 1, 0]
2384
+ ): Matrix4 {
2385
+ return targetTo(eye, target, up, new Matrix4());
2469
2386
  }
2470
2387
 
2471
2388
  /**
@@ -2486,10 +2403,9 @@ export default class Matrix4
2486
2403
  * @param c3r1 - The value in the fourth column and second row.
2487
2404
  * @param c3r2 - The value in the fourth column and third row.
2488
2405
  * @param c3r3 - The value in the fourth column and fourth row.
2489
- * @param out - The matrix to store the result in.
2490
2406
  * @returns The matrix.
2491
2407
  */
2492
- public static fromValues<T extends Matrix4Like = Matrix4>(
2408
+ public static fromValues(
2493
2409
  c0r0: number,
2494
2410
  c0r1: number,
2495
2411
  c0r2: number,
@@ -2505,9 +2421,8 @@ export default class Matrix4
2505
2421
  c3r0: number,
2506
2422
  c3r1: number,
2507
2423
  c3r2: number,
2508
- c3r3: number,
2509
- out: T = new Matrix4() as Matrix4 & T
2510
- ): T {
2424
+ c3r3: number
2425
+ ): Matrix4 {
2511
2426
  return fromValues(
2512
2427
  c0r0,
2513
2428
  c0r1,
@@ -2525,7 +2440,7 @@ export default class Matrix4
2525
2440
  c3r1,
2526
2441
  c3r2,
2527
2442
  c3r3,
2528
- out
2443
+ new Matrix4()
2529
2444
  );
2530
2445
  }
2531
2446
 
@@ -2620,38 +2535,28 @@ export default class Matrix4
2620
2535
  /**
2621
2536
  * Add two matrices of the same size.
2622
2537
  * @param matrix - The other matrix.
2623
- * @param out - The matrix to store the result in.
2624
2538
  * @returns The sum of the matrices.
2625
2539
  * @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
2626
2540
  */
2627
- public add<T extends Matrix4Like = Matrix4>(
2628
- matrix: Matrix4Like,
2629
- out: T = new Matrix4() as Matrix4 & T
2630
- ): T {
2631
- return add(this, matrix, out);
2541
+ public add(matrix: Matrix4Like): Matrix4 {
2542
+ return add(this, matrix, new Matrix4());
2632
2543
  }
2633
2544
 
2634
2545
  /**
2635
2546
  * Calculate the adjugate of this matrix.
2636
- * @param out - The matrix to store the result in.
2637
2547
  * @returns The adjugate of this matrix.
2638
2548
  * @see {@link https://en.wikipedia.org/wiki/Adjugate_matrix | Adjugate matrix}
2639
2549
  */
2640
- public adjoint<T extends Matrix4Like = Matrix4>(
2641
- out: T = new Matrix4() as Matrix4 & T
2642
- ): T {
2643
- return adjoint(this, out);
2550
+ public adjoint(): Matrix4 {
2551
+ return adjoint(this, new Matrix4());
2644
2552
  }
2645
2553
 
2646
2554
  /**
2647
2555
  * Copy the values from this matrix to another one.
2648
- * @param out - The matrix to store the result in.
2649
2556
  * @returns The copy.
2650
2557
  */
2651
- public clone<T extends Matrix4Like = Matrix4>(
2652
- out: T = new Matrix4() as Matrix4 & T
2653
- ): T {
2654
- return copy(this, out);
2558
+ public clone(): Matrix4 {
2559
+ return copy(this, new Matrix4());
2655
2560
  }
2656
2561
 
2657
2562
  /**
@@ -2674,72 +2579,52 @@ export default class Matrix4
2674
2579
  /**
2675
2580
  * Multiply this matrix by another.
2676
2581
  * @param matrix - The other matrix.
2677
- * @param out - The matrix to store the result in.
2678
2582
  * @returns The product of the matrices.
2679
2583
  * @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
2680
2584
  */
2681
- public multiply<T extends Matrix4Like = Matrix4>(
2682
- matrix: Matrix4Like,
2683
- out: T = new Matrix4() as Matrix4 & T
2684
- ): T {
2685
- return multiply(this, matrix, out);
2585
+ public multiply(matrix: Matrix4Like): Matrix4 {
2586
+ return multiply(this, matrix, new Matrix4());
2686
2587
  }
2687
2588
 
2688
2589
  /**
2689
2590
  * Multiply this matrix by a scalar value.
2690
2591
  * @param scalar - The scalar value.
2691
- * @param out - The matrix to store the result in.
2692
2592
  * @returns The product of the matrix and the scalar value.
2693
2593
  * @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
2694
2594
  */
2695
- public multiplyScalar<T extends Matrix4Like = Matrix4>(
2696
- scalar: number,
2697
- out: T = new Matrix4() as Matrix4 & T
2698
- ): T {
2699
- return multiplyScalar(this, scalar, out);
2595
+ public multiplyScalar(scalar: number): Matrix4 {
2596
+ return multiplyScalar(this, scalar, new Matrix4());
2700
2597
  }
2701
2598
 
2702
2599
  /**
2703
2600
  * Add this matrix to another after multiplying the other by a scalar.
2704
2601
  * @param matrix - The other matrix.
2705
2602
  * @param scalar - The scalar.
2706
- * @param out - The matrix to store the result in.
2707
2603
  * @returns The sum.
2708
2604
  * @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
2709
2605
  * @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
2710
2606
  */
2711
- public multiplyScalarAndAdd<T extends Matrix4Like = Matrix4>(
2712
- matrix: Matrix4Like,
2713
- scalar: number,
2714
- out: T = new Matrix4() as Matrix4 & T
2715
- ): T {
2716
- return multiplyScalarAndAdd(this, matrix, scalar, out);
2607
+ public multiplyScalarAndAdd(matrix: Matrix4Like, scalar: number): Matrix4 {
2608
+ return multiplyScalarAndAdd(this, matrix, scalar, new Matrix4());
2717
2609
  }
2718
2610
 
2719
2611
  /**
2720
2612
  * Subtract another matrix from this one.
2721
2613
  * @param matrix - The other matrix.
2722
- * @param out - The matrix to store the result in.
2723
2614
  * @returns The difference between the matrices.
2724
2615
  * @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
2725
2616
  */
2726
- public subtract<T extends Matrix4Like = Matrix4>(
2727
- matrix: Matrix4Like,
2728
- out: T = new Matrix4() as Matrix4 & T
2729
- ): T {
2730
- return subtract(this, matrix, out);
2617
+ public subtract(matrix: Matrix4Like): Matrix4 {
2618
+ return subtract(this, matrix, new Matrix4());
2731
2619
  }
2732
2620
 
2733
2621
  /**
2734
2622
  * Transpose this matrix.
2735
- * @param out - The matrix to store the result in.
2736
2623
  * @returns The transpose of this matrix.
2737
2624
  * @see {@link https://en.wikipedia.org/wiki/Transpose | Transpose}
2738
2625
  */
2739
- public transpose<T extends Matrix4Like = Matrix4>(
2740
- out: T = new Matrix4() as Matrix4 & T
2741
- ): T {
2742
- return transpose(this, out);
2626
+ public transpose(): Matrix4 {
2627
+ return transpose(this, new Matrix4());
2743
2628
  }
2744
2629
 
2745
2630
  /**
@@ -2761,149 +2646,108 @@ export default class Matrix4
2761
2646
 
2762
2647
  /**
2763
2648
  * Invert this matrix.
2764
- * @param out - The matrix to store the result in.
2765
2649
  * @returns The inverted matrix.
2766
2650
  * @see {@link https://en.wikipedia.org/wiki/Invertible_matrix | Invertible matrix}
2767
2651
  */
2768
- public invert<T extends Matrix4Like = Matrix4>(
2769
- out: T = new Matrix4() as Matrix4 & T
2770
- ): T {
2771
- return invert(this, out);
2652
+ public invert(): Matrix4 {
2653
+ return invert(this, new Matrix4());
2772
2654
  }
2773
2655
 
2774
2656
  /**
2775
2657
  * Scale this matrix by the given vector.
2776
2658
  * @param vector - The scaling vector.
2777
- * @param out - The matrix to store the result in.
2778
2659
  * @returns The scaled matrix.
2779
2660
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2780
2661
  */
2781
- public scale<T extends Matrix4Like = Matrix4>(
2782
- vector: Vector3Like,
2783
- out: T = new Matrix4() as Matrix4 & T
2784
- ): T {
2785
- return scale(this, vector, out);
2662
+ public scale(vector: Vector3Like): Matrix4 {
2663
+ return scale(this, vector, new Matrix4());
2786
2664
  }
2787
2665
 
2788
2666
  /**
2789
2667
  * Translate this matrix by the given vector.
2790
2668
  * @param vector - The translation vector.
2791
- * @param out - The matrix to store the result in.
2792
2669
  * @returns The translated matrix.
2793
2670
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2794
2671
  */
2795
- public translate<T extends Matrix4Like = Matrix4>(
2796
- vector: Vector3Like,
2797
- out: T = new Matrix4() as Matrix4 & T
2798
- ): T {
2799
- return translate(this, vector, out);
2672
+ public translate(vector: Vector3Like): Matrix4 {
2673
+ return translate(this, vector, new Matrix4());
2800
2674
  }
2801
2675
 
2802
2676
  /**
2803
2677
  * Rotate this matrix by the given angle around the given axis.
2804
2678
  * @param r - The angle in radians.
2805
2679
  * @param axis - The axis.
2806
- * @param out - The matrix to store the result in.
2807
2680
  * @returns The rotated matrix.
2808
2681
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2809
2682
  */
2810
- public rotate<T extends Matrix4Like = Matrix4>(
2811
- r: number,
2812
- axis: Vector3Like,
2813
- out: T = new Matrix4() as Matrix4 & T
2814
- ): T {
2815
- return rotate(this, r, axis, out);
2683
+ public rotate(r: number, axis: Vector3Like): Matrix4 {
2684
+ return rotate(this, r, axis, new Matrix4());
2816
2685
  }
2817
2686
 
2818
2687
  /**
2819
2688
  * Rotate this matrix by the given angle around the X-axis.
2820
2689
  * @param r - The angle in radians.
2821
- * @param out - The matrix to store the result in.
2822
2690
  * @returns The rotated matrix.
2823
2691
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2824
2692
  */
2825
- public rotateX<T extends Matrix4Like = Matrix4>(
2826
- r: number,
2827
- out: T = new Matrix4() as Matrix4 & T
2828
- ): T {
2829
- return rotateX(this, r, out);
2693
+ public rotateX(r: number): Matrix4 {
2694
+ return rotateX(this, r, new Matrix4());
2830
2695
  }
2831
2696
 
2832
2697
  /**
2833
2698
  * Rotate this matrix by the given angle around the Y-axis.
2834
2699
  * @param r - The angle in radians.
2835
- * @param out - The matrix to store the result in.
2836
2700
  * @returns The rotated matrix.
2837
2701
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2838
2702
  */
2839
- public rotateY<T extends Matrix4Like = Matrix4>(
2840
- r: number,
2841
- out: T = new Matrix4() as Matrix4 & T
2842
- ): T {
2843
- return rotateY(this, r, out);
2703
+ public rotateY(r: number): Matrix4 {
2704
+ return rotateY(this, r, new Matrix4());
2844
2705
  }
2845
2706
 
2846
2707
  /**
2847
2708
  * Rotate this matrix by the given angle around the Z-axis.
2848
2709
  * @param r - The angle in radians.
2849
- * @param out - The matrix to store the result in.
2850
2710
  * @returns The rotated matrix.
2851
2711
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2852
2712
  */
2853
- public rotateZ<T extends Matrix4Like = Matrix4>(
2854
- r: number,
2855
- out: T = new Matrix4() as Matrix4 & T
2856
- ): T {
2857
- return rotateZ(this, r, out);
2713
+ public rotateZ(r: number): Matrix4 {
2714
+ return rotateZ(this, r, new Matrix4());
2858
2715
  }
2859
2716
 
2860
2717
  /**
2861
2718
  * Get the translation vector component of this transformation matrix.
2862
- * @param out - The vector to store the result in.
2863
2719
  * @returns The translation.
2864
2720
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2865
2721
  */
2866
- public getTranslation<T extends Vector3Like = Vector3>(
2867
- out: T = new Vector3() as Vector3 & T
2868
- ): T {
2869
- return getTranslation(this, out);
2722
+ public getTranslation(): Vector3 {
2723
+ return getTranslation(this, new Vector3());
2870
2724
  }
2871
2725
 
2872
2726
  /**
2873
2727
  * Set the translation vector component of this transformation matrix.
2874
2728
  * @param translation - The translation vector.
2875
- * @param out - The matrix to store the result in.
2876
2729
  * @returns The transformation matrix.
2877
2730
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2878
2731
  */
2879
- public setTranslation<T extends Matrix4Like = Matrix4>(
2880
- translation: Vector3Like,
2881
- out: T = new Matrix4() as Matrix4 & T
2882
- ): T {
2883
- return setTranslation(this, translation, out);
2732
+ public setTranslation(translation: Vector3Like): Matrix4 {
2733
+ return setTranslation(this, translation, new Matrix4());
2884
2734
  }
2885
2735
 
2886
2736
  /**
2887
2737
  * Get the scaling vector component of this transformation matrix.
2888
- * @param out - The vector to store the result in.
2889
2738
  * @returns The scaling.
2890
2739
  * @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
2891
2740
  */
2892
- public getScaling<T extends Vector3Like = Vector3>(
2893
- out: T = new Vector3() as Vector3 & T
2894
- ): T {
2895
- return getScaling(this, out);
2741
+ public getScaling(): Vector3 {
2742
+ return getScaling(this, new Vector3());
2896
2743
  }
2897
2744
 
2898
2745
  /**
2899
2746
  * Get the scaling vector component of this transformation matrix.
2900
- * @param out - The quaternion to store the result in.
2901
2747
  * @returns The rotation.
2902
2748
  * @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
2903
2749
  */
2904
- public getRotation<T extends QuaternionLike = Quaternion>(
2905
- out: T = new Quaternion() as Quaternion & T
2906
- ): T {
2907
- return getRotation(this, out);
2750
+ public getRotation(): Quaternion {
2751
+ return getRotation(this, new Quaternion());
2908
2752
  }
2909
2753
  }