@lakuna/umath 1.3.7 → 1.3.9

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 (47) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -0
  3. package/dist/algorithms/primeFactorization.d.ts.map +1 -1
  4. package/dist/algorithms/primeFactorization.js +2 -3
  5. package/dist/algorithms/primeFactorization.js.map +1 -1
  6. package/dist/linalg/DualQuaternion.d.ts +25 -25
  7. package/dist/linalg/DualQuaternion.d.ts.map +1 -1
  8. package/dist/linalg/DualQuaternion.js +7 -4
  9. package/dist/linalg/DualQuaternion.js.map +1 -1
  10. package/dist/linalg/Matrix2.d.ts +14 -14
  11. package/dist/linalg/Matrix2.d.ts.map +1 -1
  12. package/dist/linalg/Matrix2.js +10 -7
  13. package/dist/linalg/Matrix2.js.map +1 -1
  14. package/dist/linalg/Matrix3.d.ts +20 -20
  15. package/dist/linalg/Matrix3.d.ts.map +1 -1
  16. package/dist/linalg/Matrix3.js +28 -12
  17. package/dist/linalg/Matrix3.js.map +1 -1
  18. package/dist/linalg/Matrix4.d.ts +39 -39
  19. package/dist/linalg/Matrix4.d.ts.map +1 -1
  20. package/dist/linalg/Matrix4.js +62 -33
  21. package/dist/linalg/Matrix4.js.map +1 -1
  22. package/dist/linalg/Quaternion.d.ts +21 -21
  23. package/dist/linalg/Quaternion.d.ts.map +1 -1
  24. package/dist/linalg/Quaternion.js.map +1 -1
  25. package/dist/linalg/Vector2.d.ts +23 -23
  26. package/dist/linalg/Vector2.d.ts.map +1 -1
  27. package/dist/linalg/Vector2.js +2 -2
  28. package/dist/linalg/Vector2.js.map +1 -1
  29. package/dist/linalg/Vector3.d.ts +28 -28
  30. package/dist/linalg/Vector3.d.ts.map +1 -1
  31. package/dist/linalg/Vector3.js +2 -2
  32. package/dist/linalg/Vector3.js.map +1 -1
  33. package/dist/linalg/Vector4.d.ts +20 -20
  34. package/dist/linalg/Vector4.d.ts.map +1 -1
  35. package/dist/linalg/Vector4.js +2 -2
  36. package/dist/linalg/Vector4.js.map +1 -1
  37. package/dist/utility/epsilon.d.ts.map +1 -1
  38. package/package.json +14 -18
  39. package/src/algorithms/primeFactorization.ts +3 -2
  40. package/src/linalg/DualQuaternion.ts +57 -54
  41. package/src/linalg/Matrix2.ts +41 -32
  42. package/src/linalg/Matrix3.ts +73 -58
  43. package/src/linalg/Matrix4.ts +140 -117
  44. package/src/linalg/Quaternion.ts +42 -42
  45. package/src/linalg/Vector2.ts +52 -40
  46. package/src/linalg/Vector3.ts +62 -50
  47. package/src/linalg/Vector4.ts +48 -36
@@ -537,14 +537,17 @@ export const rotateAroundAxis = <T extends DualQuaternionLike>(
537
537
  return copy(dualQuaternion, out);
538
538
  }
539
539
 
540
- const axisLength = Math.hypot(axis[0], axis[1], axis[2]);
540
+ const ax = axis[0];
541
+ const ay = axis[1];
542
+ const az = axis[2];
543
+ const axisLength = Math.sqrt(ax * ax + ay * ay + az * az);
541
544
 
542
545
  const r = radians * 0.5;
543
546
 
544
547
  const s = Math.sin(r);
545
- const bx = (s * axis[0]) / axisLength;
546
- const by = (s * axis[1]) / axisLength;
547
- const bz = (s * axis[2]) / axisLength;
548
+ const bx = (s * ax) / axisLength;
549
+ const by = (s * ay) / axisLength;
550
+ const bz = (s * az) / axisLength;
548
551
  const bw = Math.cos(r);
549
552
 
550
553
  let x = dualQuaternion[0];
@@ -882,7 +885,7 @@ export default class DualQuaternion
882
885
  * @param out - The dual quaternion to store the result in.
883
886
  * @returns A new dual quaternion.
884
887
  */
885
- public static fromValues<T extends DualQuaternionLike>(
888
+ public static fromValues<T extends DualQuaternionLike = DualQuaternion>(
886
889
  x1: number,
887
890
  y1: number,
888
891
  z1: number,
@@ -891,7 +894,7 @@ export default class DualQuaternion
891
894
  y2: number,
892
895
  z2: number,
893
896
  w2: number,
894
- out = new DualQuaternion() as unknown as T
897
+ out: T = new DualQuaternion() as DualQuaternion & T
895
898
  ): T {
896
899
  return fromValues(x1, y1, z1, w1, x2, y2, z2, w2, out);
897
900
  }
@@ -903,10 +906,12 @@ export default class DualQuaternion
903
906
  * @param out - The dual quaternion to store the result in.
904
907
  * @returns The dual quaternion.
905
908
  */
906
- public static fromRotationTranslation<T extends DualQuaternionLike>(
909
+ public static fromRotationTranslation<
910
+ T extends DualQuaternionLike = DualQuaternion
911
+ >(
907
912
  q: QuaternionLike,
908
913
  t: Vector3Like,
909
- out = new DualQuaternion() as unknown as T
914
+ out: T = new DualQuaternion() as DualQuaternion & T
910
915
  ): T {
911
916
  return fromRotationTranslation(q, t, out);
912
917
  }
@@ -917,9 +922,9 @@ export default class DualQuaternion
917
922
  * @param out - The dual quaternion to store the result in.
918
923
  * @returns The dual quaternion.
919
924
  */
920
- public static fromTranslation<T extends DualQuaternionLike>(
925
+ public static fromTranslation<T extends DualQuaternionLike = DualQuaternion>(
921
926
  t: Vector3Like,
922
- out = new DualQuaternion() as unknown as T
927
+ out: T = new DualQuaternion() as DualQuaternion & T
923
928
  ): T {
924
929
  return fromTranslation(t, out);
925
930
  }
@@ -930,9 +935,9 @@ export default class DualQuaternion
930
935
  * @param out - The dual quaternion to store the result in.
931
936
  * @returns The dual quaternion.
932
937
  */
933
- public static fromRotation<T extends DualQuaternionLike>(
938
+ public static fromRotation<T extends DualQuaternionLike = DualQuaternion>(
934
939
  q: QuaternionLike,
935
- out = new DualQuaternion() as unknown as T
940
+ out: T = new DualQuaternion() as DualQuaternion & T
936
941
  ): T {
937
942
  return fromRotation(q, out);
938
943
  }
@@ -943,9 +948,9 @@ export default class DualQuaternion
943
948
  * @param out - The dual quaternion to store the result in.
944
949
  * @returns The dual quaternion.
945
950
  */
946
- public static fromMatrix4<T extends DualQuaternionLike>(
951
+ public static fromMatrix4<T extends DualQuaternionLike = DualQuaternion>(
947
952
  matrix: Matrix4Like,
948
- out = new DualQuaternion() as unknown as T
953
+ out: T = new DualQuaternion() as DualQuaternion & T
949
954
  ): T {
950
955
  return fromMatrix4(matrix, out);
951
956
  }
@@ -997,8 +1002,8 @@ export default class DualQuaternion
997
1002
  * @param out - The dual quaternion to store the result in.
998
1003
  * @returns The copy.
999
1004
  */
1000
- public clone<T extends DualQuaternionLike>(
1001
- out = new DualQuaternion() as unknown as T
1005
+ public clone<T extends DualQuaternionLike = DualQuaternion>(
1006
+ out: T = new DualQuaternion() as DualQuaternion & T
1002
1007
  ): T {
1003
1008
  return copy(this, out);
1004
1009
  }
@@ -1016,8 +1021,8 @@ export default class DualQuaternion
1016
1021
  * @param out - The quaternion to store the result in.
1017
1022
  * @returns The real part.
1018
1023
  */
1019
- public getReal<T extends QuaternionLike>(
1020
- out = new Quaternion() as unknown as T
1024
+ public getReal<T extends QuaternionLike = Quaternion>(
1025
+ out: T = new Quaternion() as Quaternion & T
1021
1026
  ): T {
1022
1027
  return xetReal(this, out);
1023
1028
  }
@@ -1035,8 +1040,8 @@ export default class DualQuaternion
1035
1040
  * @param out - The quaternion to store the result in.
1036
1041
  * @returns The dual part.
1037
1042
  */
1038
- public getDual<T extends QuaternionLike>(
1039
- out = new Quaternion() as unknown as T
1043
+ public getDual<T extends QuaternionLike = Quaternion>(
1044
+ out: T = new Quaternion() as Quaternion & T
1040
1045
  ): T {
1041
1046
  return getDual(this, out);
1042
1047
  }
@@ -1054,8 +1059,8 @@ export default class DualQuaternion
1054
1059
  * @param out - The vector to store the result in.
1055
1060
  * @returns The translation.
1056
1061
  */
1057
- public getTranslation<T extends Vector3Like>(
1058
- out = new Vector3() as unknown as T
1062
+ public getTranslation<T extends Vector3Like = Vector3>(
1063
+ out: T = new Vector3() as Vector3 & T
1059
1064
  ): T {
1060
1065
  return getTranslation(this, out);
1061
1066
  }
@@ -1066,9 +1071,9 @@ export default class DualQuaternion
1066
1071
  * @param out - The dual quaternion to store the result in.
1067
1072
  * @returns The translated dual quaternion.
1068
1073
  */
1069
- public translate<T extends DualQuaternionLike>(
1074
+ public translate<T extends DualQuaternionLike = DualQuaternion>(
1070
1075
  v: Vector3Like,
1071
- out = new DualQuaternion() as unknown as T
1076
+ out: T = new DualQuaternion() as DualQuaternion & T
1072
1077
  ): T {
1073
1078
  return translate(this, v, out);
1074
1079
  }
@@ -1079,9 +1084,9 @@ export default class DualQuaternion
1079
1084
  * @param out - The dual quaternion to store the result in.
1080
1085
  * @returns The rotated dual quaternion.
1081
1086
  */
1082
- public rotateX<T extends DualQuaternionLike>(
1087
+ public rotateX<T extends DualQuaternionLike = DualQuaternion>(
1083
1088
  r: number,
1084
- out = new DualQuaternion() as unknown as T
1089
+ out: T = new DualQuaternion() as DualQuaternion & T
1085
1090
  ): T {
1086
1091
  return rotateX(this, r, out);
1087
1092
  }
@@ -1092,9 +1097,9 @@ export default class DualQuaternion
1092
1097
  * @param out - The dual quaternion to store the result in.
1093
1098
  * @returns The rotated dual quaternion.
1094
1099
  */
1095
- public rotateY<T extends DualQuaternionLike>(
1100
+ public rotateY<T extends DualQuaternionLike = DualQuaternion>(
1096
1101
  r: number,
1097
- out = new DualQuaternion() as unknown as T
1102
+ out: T = new DualQuaternion() as DualQuaternion & T
1098
1103
  ): T {
1099
1104
  return rotateY(this, r, out);
1100
1105
  }
@@ -1105,9 +1110,9 @@ export default class DualQuaternion
1105
1110
  * @param out - The dual quaternion to store the result in.
1106
1111
  * @returns The rotated dual quaternion.
1107
1112
  */
1108
- public rotateZ<T extends DualQuaternionLike>(
1113
+ public rotateZ<T extends DualQuaternionLike = DualQuaternion>(
1109
1114
  r: number,
1110
- out = new DualQuaternion() as unknown as T
1115
+ out: T = new DualQuaternion() as DualQuaternion & T
1111
1116
  ): T {
1112
1117
  return rotateZ(this, r, out);
1113
1118
  }
@@ -1119,10 +1124,9 @@ export default class DualQuaternion
1119
1124
  * @returns The rotated dual quaternion.
1120
1125
  * @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
1121
1126
  */
1122
- public rotateByQuaternionAppend<T extends DualQuaternionLike>(
1123
- q: QuaternionLike,
1124
- out = new DualQuaternion() as unknown as T
1125
- ): T {
1127
+ public rotateByQuaternionAppend<
1128
+ T extends DualQuaternionLike = DualQuaternion
1129
+ >(q: QuaternionLike, out: T = new DualQuaternion() as DualQuaternion & T): T {
1126
1130
  return rotateByQuaternionAppend(this, q, out);
1127
1131
  }
1128
1132
 
@@ -1133,10 +1137,9 @@ export default class DualQuaternion
1133
1137
  * @returns The rotated dual quaternion.
1134
1138
  * @see [Quaternion](https://en.wikipedia.org/wiki/Quaternion)
1135
1139
  */
1136
- public rotateByQuaternionPrepend<T extends DualQuaternionLike>(
1137
- q: QuaternionLike,
1138
- out = new DualQuaternion() as unknown as T
1139
- ): T {
1140
+ public rotateByQuaternionPrepend<
1141
+ T extends DualQuaternionLike = DualQuaternion
1142
+ >(q: QuaternionLike, out: T = new DualQuaternion() as DualQuaternion & T): T {
1140
1143
  return rotateByQuaternionPrepend(q, this, out);
1141
1144
  }
1142
1145
 
@@ -1147,10 +1150,10 @@ export default class DualQuaternion
1147
1150
  * @param out - The dual quaternion to store the result in.
1148
1151
  * @returns A normalized dual quaternion.
1149
1152
  */
1150
- public rotateAroundAxis<T extends DualQuaternionLike>(
1153
+ public rotateAroundAxis<T extends DualQuaternionLike = DualQuaternion>(
1151
1154
  axis: Vector3Like,
1152
1155
  r: number,
1153
- out = new DualQuaternion() as unknown as T
1156
+ out: T = new DualQuaternion() as DualQuaternion & T
1154
1157
  ): T {
1155
1158
  return rotateAroundAxis(this, axis, r, out);
1156
1159
  }
@@ -1161,9 +1164,9 @@ export default class DualQuaternion
1161
1164
  * @param out - The dual quaternion to store the result in.
1162
1165
  * @returns The sum.
1163
1166
  */
1164
- public add<T extends DualQuaternionLike>(
1167
+ public add<T extends DualQuaternionLike = DualQuaternion>(
1165
1168
  dq: DualQuaternionLike,
1166
- out = new DualQuaternion() as unknown as T
1169
+ out: T = new DualQuaternion() as DualQuaternion & T
1167
1170
  ): T {
1168
1171
  return add(this, dq, out);
1169
1172
  }
@@ -1174,9 +1177,9 @@ export default class DualQuaternion
1174
1177
  * @param out - The dual quaternion to store the result in.
1175
1178
  * @returns The product.
1176
1179
  */
1177
- public multiply<T extends DualQuaternionLike>(
1180
+ public multiply<T extends DualQuaternionLike = DualQuaternion>(
1178
1181
  dq: DualQuaternionLike,
1179
- out = new DualQuaternion() as unknown as T
1182
+ out: T = new DualQuaternion() as DualQuaternion & T
1180
1183
  ): T {
1181
1184
  return multiply(this, dq, out);
1182
1185
  }
@@ -1187,9 +1190,9 @@ export default class DualQuaternion
1187
1190
  * @param out - The dual quaternion to store the result in.
1188
1191
  * @returns The product.
1189
1192
  */
1190
- public scale<T extends DualQuaternionLike>(
1193
+ public scale<T extends DualQuaternionLike = DualQuaternion>(
1191
1194
  s: number,
1192
- out = new DualQuaternion() as unknown as T
1195
+ out: T = new DualQuaternion() as DualQuaternion & T
1193
1196
  ): T {
1194
1197
  return scale(this, s, out);
1195
1198
  }
@@ -1211,10 +1214,10 @@ export default class DualQuaternion
1211
1214
  * @param out - The dual quaternion to store the result in.
1212
1215
  * @returns The interpolated value.
1213
1216
  */
1214
- public lerp<T extends DualQuaternionLike>(
1217
+ public lerp<T extends DualQuaternionLike = DualQuaternion>(
1215
1218
  dq: DualQuaternionLike,
1216
1219
  t: number,
1217
- out = new DualQuaternion() as unknown as T
1220
+ out: T = new DualQuaternion() as DualQuaternion & T
1218
1221
  ): T {
1219
1222
  return lerp(this, dq, t, out);
1220
1223
  }
@@ -1224,8 +1227,8 @@ export default class DualQuaternion
1224
1227
  * @param out - The dual quaternion to store the result in.
1225
1228
  * @returns The inverse.
1226
1229
  */
1227
- public invert<T extends DualQuaternionLike>(
1228
- out = new DualQuaternion() as unknown as T
1230
+ public invert<T extends DualQuaternionLike = DualQuaternion>(
1231
+ out: T = new DualQuaternion() as DualQuaternion & T
1229
1232
  ): T {
1230
1233
  return invert(this, out);
1231
1234
  }
@@ -1235,8 +1238,8 @@ export default class DualQuaternion
1235
1238
  * @param out - The dual quaternion to store the result in.
1236
1239
  * @returns The conjugate.
1237
1240
  */
1238
- public conjugate<T extends DualQuaternionLike>(
1239
- out = new DualQuaternion() as unknown as T
1241
+ public conjugate<T extends DualQuaternionLike = DualQuaternion>(
1242
+ out: T = new DualQuaternion() as DualQuaternion & T
1240
1243
  ): T {
1241
1244
  return conjugate(this, out);
1242
1245
  }
@@ -1256,8 +1259,8 @@ export default class DualQuaternion
1256
1259
  * @param out - The dual quaternion to store the result in.
1257
1260
  * @returns The normalized dual quaternion.
1258
1261
  */
1259
- public normalize<T extends DualQuaternionLike>(
1260
- out = new DualQuaternion() as unknown as T
1262
+ public normalize<T extends DualQuaternionLike = DualQuaternion>(
1263
+ out: T = new DualQuaternion() as DualQuaternion & T
1261
1264
  ): T {
1262
1265
  return normalize(this, out);
1263
1266
  }
@@ -184,7 +184,11 @@ export const copy = <T extends Matrix2Like>(matrix: Matrix2Like, out: T): T => {
184
184
  * @see [Matrix norm](https://en.wikipedia.org/wiki/Matrix_norm)
185
185
  */
186
186
  export const frob = (matrix: Matrix2Like): number => {
187
- return Math.hypot(matrix[0], matrix[1], matrix[2], matrix[3]);
187
+ const a0 = matrix[0];
188
+ const a1 = matrix[1];
189
+ const a2 = matrix[2];
190
+ const a3 = matrix[3];
191
+ return Math.sqrt(a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3);
188
192
  };
189
193
 
190
194
  /**
@@ -295,12 +299,13 @@ export const transpose = <T extends Matrix2Like>(
295
299
  const a1 = matrix[1];
296
300
  out[1] = matrix[2];
297
301
  out[2] = a1;
298
- } else {
299
- out[0] = matrix[0];
300
- out[1] = matrix[2];
301
- out[2] = matrix[1];
302
- out[3] = matrix[3];
302
+ return out;
303
303
  }
304
+
305
+ out[0] = matrix[0];
306
+ out[1] = matrix[2];
307
+ out[2] = matrix[1];
308
+ out[3] = matrix[3];
304
309
  return out;
305
310
  };
306
311
 
@@ -423,9 +428,9 @@ export default class Matrix2
423
428
  * @returns The transformation matrix.
424
429
  * @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
425
430
  */
426
- public static fromRotation<T extends Matrix2Like>(
431
+ public static fromRotation<T extends Matrix2Like = Matrix2>(
427
432
  r: number,
428
- out = new Matrix2() as unknown as T
433
+ out: T = new Matrix2() as Matrix2 & T
429
434
  ): T {
430
435
  return fromRotation(r, out);
431
436
  }
@@ -437,9 +442,9 @@ export default class Matrix2
437
442
  * @returns The transformation matrix.
438
443
  * @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
439
444
  */
440
- public static fromScaling<T extends Matrix2Like>(
445
+ public static fromScaling<T extends Matrix2Like = Matrix2>(
441
446
  vector: Vector2Like,
442
- out = new Matrix2() as unknown as T
447
+ out: T = new Matrix2() as Matrix2 & T
443
448
  ): T {
444
449
  return fromScaling(vector, out);
445
450
  }
@@ -453,12 +458,12 @@ export default class Matrix2
453
458
  * @param out - The matrix to store the result in.
454
459
  * @returns The matrix.
455
460
  */
456
- public static fromValues<T extends Matrix2Like>(
461
+ public static fromValues<T extends Matrix2Like = Matrix2>(
457
462
  c0r0: number,
458
463
  c0r1: number,
459
464
  c1r0: number,
460
465
  c1r1: number,
461
- out = new Matrix2() as unknown as T
466
+ out: T = new Matrix2() as Matrix2 & T
462
467
  ): T {
463
468
  return fromValues(c0r0, c0r1, c1r0, c1r1, out);
464
469
  }
@@ -520,9 +525,9 @@ export default class Matrix2
520
525
  * @returns The sum of the matrices.
521
526
  * @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
522
527
  */
523
- public add<T extends Matrix2Like>(
528
+ public add<T extends Matrix2Like = Matrix2>(
524
529
  matrix: Matrix2Like,
525
- out = new Matrix2() as unknown as T
530
+ out: T = new Matrix2() as Matrix2 & T
526
531
  ): T {
527
532
  return add(this, matrix, out);
528
533
  }
@@ -533,8 +538,8 @@ export default class Matrix2
533
538
  * @returns The adjugate of this matrix.
534
539
  * @see [Adjugate matrix](https://en.wikipedia.org/wiki/Adjugate_matrix)
535
540
  */
536
- public adjoint<T extends Matrix2Like>(
537
- out = new Matrix2() as unknown as T
541
+ public adjoint<T extends Matrix2Like = Matrix2>(
542
+ out: T = new Matrix2() as Matrix2 & T
538
543
  ): T {
539
544
  return adjoint(this, out);
540
545
  }
@@ -544,7 +549,9 @@ export default class Matrix2
544
549
  * @param out - The matrix to store the result in.
545
550
  * @returns The copy.
546
551
  */
547
- public clone<T extends Matrix2Like>(out = new Matrix2() as unknown as T): T {
552
+ public clone<T extends Matrix2Like = Matrix2>(
553
+ out: T = new Matrix2() as Matrix2 & T
554
+ ): T {
548
555
  return copy(this, out);
549
556
  }
550
557
 
@@ -572,9 +579,9 @@ export default class Matrix2
572
579
  * @returns The product of the matrices.
573
580
  * @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
574
581
  */
575
- public multiply<T extends Matrix2Like>(
582
+ public multiply<T extends Matrix2Like = Matrix2>(
576
583
  matrix: Matrix2Like,
577
- out = new Matrix2() as unknown as T
584
+ out: T = new Matrix2() as Matrix2 & T
578
585
  ): T {
579
586
  return multiply(this, matrix, out);
580
587
  }
@@ -586,9 +593,9 @@ export default class Matrix2
586
593
  * @returns The product of the matrix and the scalar value.
587
594
  * @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
588
595
  */
589
- public multiplyScalar<T extends Matrix2Like>(
596
+ public multiplyScalar<T extends Matrix2Like = Matrix2>(
590
597
  scalar: number,
591
- out = new Matrix2() as unknown as T
598
+ out: T = new Matrix2() as Matrix2 & T
592
599
  ): T {
593
600
  return multiplyScalar(this, scalar, out);
594
601
  }
@@ -602,10 +609,10 @@ export default class Matrix2
602
609
  * @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
603
610
  * @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
604
611
  */
605
- public multiplyScalarAndAdd<T extends Matrix2Like>(
612
+ public multiplyScalarAndAdd<T extends Matrix2Like = Matrix2>(
606
613
  matrix: Matrix2Like,
607
614
  scalar: number,
608
- out = new Matrix2() as unknown as T
615
+ out: T = new Matrix2() as Matrix2 & T
609
616
  ): T {
610
617
  return multiplyScalarAndAdd(this, matrix, scalar, out);
611
618
  }
@@ -617,9 +624,9 @@ export default class Matrix2
617
624
  * @returns The difference between the matrices.
618
625
  * @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
619
626
  */
620
- public subtract<T extends Matrix2Like>(
627
+ public subtract<T extends Matrix2Like = Matrix2>(
621
628
  matrix: Matrix2Like,
622
- out = new Matrix2() as unknown as T
629
+ out: T = new Matrix2() as Matrix2 & T
623
630
  ): T {
624
631
  return subtract(this, matrix, out);
625
632
  }
@@ -630,8 +637,8 @@ export default class Matrix2
630
637
  * @returns The transpose of this matrix.
631
638
  * @see [Transpose](https://en.wikipedia.org/wiki/Transpose)
632
639
  */
633
- public transpose<T extends Matrix2Like>(
634
- out = new Matrix2() as unknown as T
640
+ public transpose<T extends Matrix2Like = Matrix2>(
641
+ out: T = new Matrix2() as Matrix2 & T
635
642
  ): T {
636
643
  return transpose(this, out);
637
644
  }
@@ -659,7 +666,9 @@ export default class Matrix2
659
666
  * @returns The inverted matrix.
660
667
  * @see [Invertible matrix](https://en.wikipedia.org/wiki/Invertible_matrix)
661
668
  */
662
- public invert<T extends Matrix2Like>(out = new Matrix2() as unknown as T): T {
669
+ public invert<T extends Matrix2Like = Matrix2>(
670
+ out: T = new Matrix2() as Matrix2 & T
671
+ ): T {
663
672
  return invert(this, out);
664
673
  }
665
674
 
@@ -670,9 +679,9 @@ export default class Matrix2
670
679
  * @returns The rotated matrix.
671
680
  * @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
672
681
  */
673
- public rotate<T extends Matrix2Like>(
682
+ public rotate<T extends Matrix2Like = Matrix2>(
674
683
  r: number,
675
- out = new Matrix2() as unknown as T
684
+ out: T = new Matrix2() as Matrix2 & T
676
685
  ): T {
677
686
  return rotate(this, r, out);
678
687
  }
@@ -684,9 +693,9 @@ export default class Matrix2
684
693
  * @returns The scaled matrix.
685
694
  * @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
686
695
  */
687
- public scale<T extends Matrix2Like>(
696
+ public scale<T extends Matrix2Like = Matrix2>(
688
697
  vector: Vector2Like,
689
- out = new Matrix2() as unknown as T
698
+ out: T = new Matrix2() as Matrix2 & T
690
699
  ): T {
691
700
  return scale(this, vector, out);
692
701
  }