@lakuna/umath 3.0.0 → 4.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.
- package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
- package/dist/algorithms/hypergeometricPmf.js +5 -1
- package/dist/algorithms/hypergeometricPmf.js.map +1 -1
- package/dist/algorithms/primeFactorization.d.ts +1 -1
- package/dist/algorithms/primeFactorization.d.ts.map +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +46 -46
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +7 -7
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +25 -25
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +35 -35
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +64 -59
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +17 -11
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +50 -48
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +11 -12
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +8 -8
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SlowVector.d.ts +15 -15
- package/dist/linalg/SlowVector.d.ts.map +1 -1
- package/dist/linalg/SlowVector.js.map +1 -1
- package/dist/linalg/Vector.d.ts +14 -14
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +51 -51
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +60 -60
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +45 -45
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/utility/BigNumber.d.ts +5 -5
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +13 -6
- package/dist/utility/BigNumber.js.map +1 -1
- package/package.json +36 -36
- package/src/algorithms/hypergeometricPmf.ts +2 -0
- package/src/algorithms/primeFactorization.ts +1 -1
- package/src/index.ts +0 -5
- package/src/linalg/DualQuaternion.ts +69 -58
- package/src/linalg/Matrix.ts +10 -7
- package/src/linalg/Matrix2.ts +43 -32
- package/src/linalg/Matrix3.ts +53 -41
- package/src/linalg/Matrix4.ts +127 -94
- package/src/linalg/Quaternion.ts +90 -75
- package/src/linalg/SlowMatrix.ts +12 -9
- package/src/linalg/SlowSquareMatrix.ts +1 -1
- package/src/linalg/SlowVector.ts +16 -16
- package/src/linalg/Vector.ts +14 -14
- package/src/linalg/Vector2.ts +104 -76
- package/src/linalg/Vector3.ts +125 -92
- package/src/linalg/Vector4.ts +93 -62
- package/src/utility/BigNumber.ts +22 -11
- package/dist/types/AxisAngle.d.ts +0 -12
- package/dist/types/AxisAngle.d.ts.map +0 -1
- package/dist/types/AxisAngle.js +0 -2
- package/dist/types/AxisAngle.js.map +0 -1
- package/dist/types/FieldOfView.d.ts +0 -15
- package/dist/types/FieldOfView.d.ts.map +0 -1
- package/dist/types/FieldOfView.js +0 -2
- package/dist/types/FieldOfView.js.map +0 -1
- package/dist/utility/createAxisAngleLike.d.ts +0 -10
- package/dist/utility/createAxisAngleLike.d.ts.map +0 -1
- package/dist/utility/createAxisAngleLike.js +0 -10
- package/dist/utility/createAxisAngleLike.js.map +0 -1
- package/src/types/AxisAngle.ts +0 -13
- package/src/types/FieldOfView.ts +0 -17
- package/src/utility/createAxisAngleLike.ts +0 -14
package/src/linalg/Quaternion.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type AxisAngle from "../types/AxisAngle.js";
|
|
2
|
-
|
|
3
1
|
import radiansToDegrees from "../algorithms/radiansToDegrees.js";
|
|
4
|
-
import createAxisAngleLike from "../utility/createAxisAngleLike.js";
|
|
5
2
|
import epsilon from "../utility/epsilon.js";
|
|
6
3
|
import {
|
|
7
4
|
createMatrix3Like,
|
|
@@ -89,8 +86,8 @@ export const fromValues: <T extends QuaternionLike>(
|
|
|
89
86
|
* @public
|
|
90
87
|
*/
|
|
91
88
|
export const add: <T extends QuaternionLike>(
|
|
92
|
-
a: QuaternionLike
|
|
93
|
-
b: QuaternionLike
|
|
89
|
+
a: Readonly<QuaternionLike>,
|
|
90
|
+
b: Readonly<QuaternionLike>,
|
|
94
91
|
out: T
|
|
95
92
|
) => T = vector4Add;
|
|
96
93
|
|
|
@@ -102,7 +99,7 @@ export const add: <T extends QuaternionLike>(
|
|
|
102
99
|
* @public
|
|
103
100
|
*/
|
|
104
101
|
export const copy: <T extends QuaternionLike>(
|
|
105
|
-
quaternion: QuaternionLike
|
|
102
|
+
quaternion: Readonly<QuaternionLike>,
|
|
106
103
|
out: T
|
|
107
104
|
) => T = vector4Copy;
|
|
108
105
|
|
|
@@ -113,7 +110,10 @@ export const copy: <T extends QuaternionLike>(
|
|
|
113
110
|
* @returns The dot product.
|
|
114
111
|
* @public
|
|
115
112
|
*/
|
|
116
|
-
export const dot: (
|
|
113
|
+
export const dot: (
|
|
114
|
+
a: Readonly<QuaternionLike>,
|
|
115
|
+
b: Readonly<QuaternionLike>
|
|
116
|
+
) => number = vector4Dot;
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
119
|
* Determine whether or not two unit quaternions point in roughly the same direction.
|
|
@@ -122,8 +122,10 @@ export const dot: (a: QuaternionLike, b: QuaternionLike) => number = vector4Dot;
|
|
|
122
122
|
* @returns Whether or not the unit quaternions point in the same direction.
|
|
123
123
|
* @public
|
|
124
124
|
*/
|
|
125
|
-
export const equals = (
|
|
126
|
-
|
|
125
|
+
export const equals = (
|
|
126
|
+
a: Readonly<QuaternionLike>,
|
|
127
|
+
b: Readonly<QuaternionLike>
|
|
128
|
+
): boolean => Math.abs(dot(a, b)) >= 1 - epsilon;
|
|
127
129
|
|
|
128
130
|
/**
|
|
129
131
|
* Determine whether or not two quaternions are exactly equivalent.
|
|
@@ -132,8 +134,10 @@ export const equals = (a: QuaternionLike, b: QuaternionLike): boolean =>
|
|
|
132
134
|
* @returns Whether or not the quaternions are equivalent.
|
|
133
135
|
* @public
|
|
134
136
|
*/
|
|
135
|
-
export const exactEquals: (
|
|
136
|
-
|
|
137
|
+
export const exactEquals: (
|
|
138
|
+
a: Readonly<QuaternionLike>,
|
|
139
|
+
b: Readonly<QuaternionLike>
|
|
140
|
+
) => boolean = vector4ExactEquals;
|
|
137
141
|
|
|
138
142
|
/**
|
|
139
143
|
* Calculate the magnitude (length) of a quaternion.
|
|
@@ -141,7 +145,7 @@ export const exactEquals: (a: QuaternionLike, b: QuaternionLike) => boolean =
|
|
|
141
145
|
* @returns The magnitude.
|
|
142
146
|
* @public
|
|
143
147
|
*/
|
|
144
|
-
export const getMagnitude: (quaternion: QuaternionLike) => number =
|
|
148
|
+
export const getMagnitude: (quaternion: Readonly<QuaternionLike>) => number =
|
|
145
149
|
vector4GetMagnitude;
|
|
146
150
|
|
|
147
151
|
/**
|
|
@@ -150,8 +154,9 @@ export const getMagnitude: (quaternion: QuaternionLike) => number =
|
|
|
150
154
|
* @returns The squared magnitude.
|
|
151
155
|
* @public
|
|
152
156
|
*/
|
|
153
|
-
export const getSquaredMagnitude: (
|
|
154
|
-
|
|
157
|
+
export const getSquaredMagnitude: (
|
|
158
|
+
quaternion: Readonly<QuaternionLike>
|
|
159
|
+
) => number = vector4GetSquaredMagnitude;
|
|
155
160
|
|
|
156
161
|
/**
|
|
157
162
|
* Perform a linear interpolation between two quaternions.
|
|
@@ -164,8 +169,8 @@ export const getSquaredMagnitude: (quaternion: QuaternionLike) => number =
|
|
|
164
169
|
* @public
|
|
165
170
|
*/
|
|
166
171
|
export const lerp: <T extends QuaternionLike>(
|
|
167
|
-
a: QuaternionLike
|
|
168
|
-
b: QuaternionLike
|
|
172
|
+
a: Readonly<QuaternionLike>,
|
|
173
|
+
b: Readonly<QuaternionLike>,
|
|
169
174
|
t: number,
|
|
170
175
|
out: T
|
|
171
176
|
) => T = vector4Lerp;
|
|
@@ -178,7 +183,7 @@ export const lerp: <T extends QuaternionLike>(
|
|
|
178
183
|
* @public
|
|
179
184
|
*/
|
|
180
185
|
export const normalize: <T extends QuaternionLike>(
|
|
181
|
-
quaternion: QuaternionLike
|
|
186
|
+
quaternion: Readonly<QuaternionLike>,
|
|
182
187
|
out: T
|
|
183
188
|
) => T = vector4Normalize;
|
|
184
189
|
|
|
@@ -191,7 +196,7 @@ export const normalize: <T extends QuaternionLike>(
|
|
|
191
196
|
* @public
|
|
192
197
|
*/
|
|
193
198
|
export const scale: <T extends QuaternionLike>(
|
|
194
|
-
quaternion: QuaternionLike
|
|
199
|
+
quaternion: Readonly<QuaternionLike>,
|
|
195
200
|
scalar: number,
|
|
196
201
|
out: T
|
|
197
202
|
) => T = vector4Scale;
|
|
@@ -206,7 +211,7 @@ export const scale: <T extends QuaternionLike>(
|
|
|
206
211
|
* @public
|
|
207
212
|
*/
|
|
208
213
|
export const fromMatrix3 = <T extends QuaternionLike>(
|
|
209
|
-
matrix: Matrix3Like
|
|
214
|
+
matrix: Readonly<Matrix3Like>,
|
|
210
215
|
out: T
|
|
211
216
|
): T => {
|
|
212
217
|
const m0 = matrix[0];
|
|
@@ -540,7 +545,7 @@ const doubleRatio = 360 / Math.PI;
|
|
|
540
545
|
* @public
|
|
541
546
|
*/
|
|
542
547
|
export const toEuler = <T extends Vector3Like>(
|
|
543
|
-
quaternion: QuaternionLike
|
|
548
|
+
quaternion: Readonly<QuaternionLike>,
|
|
544
549
|
out: T
|
|
545
550
|
): T => {
|
|
546
551
|
const x = quaternion[0];
|
|
@@ -585,9 +590,9 @@ const im3 = createMatrix3Like();
|
|
|
585
590
|
* @public
|
|
586
591
|
*/
|
|
587
592
|
export const fromAxes = <T extends QuaternionLike>(
|
|
588
|
-
view: Vector3Like
|
|
589
|
-
right: Vector3Like
|
|
590
|
-
up: Vector3Like
|
|
593
|
+
view: Readonly<Vector3Like>,
|
|
594
|
+
right: Readonly<Vector3Like>,
|
|
595
|
+
up: Readonly<Vector3Like>,
|
|
591
596
|
out: T
|
|
592
597
|
): T =>
|
|
593
598
|
normalize(
|
|
@@ -621,14 +626,14 @@ export const identity = <T extends QuaternionLike>(out: T): T =>
|
|
|
621
626
|
/**
|
|
622
627
|
* Calculate the axis and angle that represent a quaternion.
|
|
623
628
|
* @param quaternion - The quaternion.
|
|
624
|
-
* @param out - The axis
|
|
629
|
+
* @param out - The axis to store the result in.
|
|
625
630
|
* @returns The axis and angle.
|
|
626
631
|
* @public
|
|
627
632
|
*/
|
|
628
|
-
export const getAxisAngle = <T extends
|
|
629
|
-
quaternion: QuaternionLike
|
|
633
|
+
export const getAxisAngle = <T extends Vector3Like>(
|
|
634
|
+
quaternion: Readonly<QuaternionLike>,
|
|
630
635
|
out: T
|
|
631
|
-
): T => {
|
|
636
|
+
): [T, number] => {
|
|
632
637
|
const r = Math.acos(quaternion[3]) * 2;
|
|
633
638
|
const s = Math.sin(r / 2);
|
|
634
639
|
|
|
@@ -637,25 +642,26 @@ export const getAxisAngle = <T extends AxisAngle>(
|
|
|
637
642
|
quaternion[0] / s,
|
|
638
643
|
quaternion[1] / s,
|
|
639
644
|
quaternion[2] / s,
|
|
640
|
-
out
|
|
645
|
+
out
|
|
641
646
|
);
|
|
642
647
|
} else {
|
|
643
|
-
vector3FromValues(1, 0, 0, out
|
|
648
|
+
vector3FromValues(1, 0, 0, out);
|
|
644
649
|
}
|
|
645
650
|
|
|
646
|
-
out
|
|
647
|
-
return out;
|
|
651
|
+
return [out, r];
|
|
648
652
|
};
|
|
649
653
|
|
|
650
654
|
/**
|
|
651
655
|
* Set the axis and angle that represent a quaternion.
|
|
652
|
-
* @param
|
|
656
|
+
* @param axis - The axis.
|
|
657
|
+
* @param angle - The angle.
|
|
653
658
|
* @param out - The quaternion to store the result in.
|
|
654
659
|
* @returns The quaternion.
|
|
655
660
|
* @public
|
|
656
661
|
*/
|
|
657
662
|
export const setAxisAngle = <T extends QuaternionLike>(
|
|
658
|
-
|
|
663
|
+
axis: Readonly<Vector3Like>,
|
|
664
|
+
angle: number,
|
|
659
665
|
out: T
|
|
660
666
|
): T => {
|
|
661
667
|
const r = angle / 2;
|
|
@@ -671,7 +677,10 @@ export const setAxisAngle = <T extends QuaternionLike>(
|
|
|
671
677
|
* @returns The angular distance in radians.
|
|
672
678
|
* @public
|
|
673
679
|
*/
|
|
674
|
-
export const getAngle = (
|
|
680
|
+
export const getAngle = (
|
|
681
|
+
a: Readonly<QuaternionLike>,
|
|
682
|
+
b: Readonly<QuaternionLike>
|
|
683
|
+
): number => {
|
|
675
684
|
const dp = dot(a, b);
|
|
676
685
|
return Math.acos(2 * dp * dp - 1);
|
|
677
686
|
};
|
|
@@ -685,8 +694,8 @@ export const getAngle = (a: QuaternionLike, b: QuaternionLike): number => {
|
|
|
685
694
|
* @public
|
|
686
695
|
*/
|
|
687
696
|
export const multiply = <T extends QuaternionLike>(
|
|
688
|
-
a: QuaternionLike
|
|
689
|
-
b: QuaternionLike
|
|
697
|
+
a: Readonly<QuaternionLike>,
|
|
698
|
+
b: Readonly<QuaternionLike>,
|
|
690
699
|
out: T
|
|
691
700
|
): T => {
|
|
692
701
|
const ax = a[0];
|
|
@@ -717,7 +726,7 @@ export const multiply = <T extends QuaternionLike>(
|
|
|
717
726
|
* @public
|
|
718
727
|
*/
|
|
719
728
|
export const rotateX = <T extends QuaternionLike>(
|
|
720
|
-
quaternion: QuaternionLike
|
|
729
|
+
quaternion: Readonly<QuaternionLike>,
|
|
721
730
|
radians: number,
|
|
722
731
|
out: T
|
|
723
732
|
): T => {
|
|
@@ -748,7 +757,7 @@ export const rotateX = <T extends QuaternionLike>(
|
|
|
748
757
|
* @public
|
|
749
758
|
*/
|
|
750
759
|
export const rotateY = <T extends QuaternionLike>(
|
|
751
|
-
quaternion: QuaternionLike
|
|
760
|
+
quaternion: Readonly<QuaternionLike>,
|
|
752
761
|
radians: number,
|
|
753
762
|
out: T
|
|
754
763
|
): T => {
|
|
@@ -779,7 +788,7 @@ export const rotateY = <T extends QuaternionLike>(
|
|
|
779
788
|
* @public
|
|
780
789
|
*/
|
|
781
790
|
export const rotateZ = <T extends QuaternionLike>(
|
|
782
|
-
quaternion: QuaternionLike
|
|
791
|
+
quaternion: Readonly<QuaternionLike>,
|
|
783
792
|
radians: number,
|
|
784
793
|
out: T
|
|
785
794
|
): T => {
|
|
@@ -809,7 +818,7 @@ export const rotateZ = <T extends QuaternionLike>(
|
|
|
809
818
|
* @public
|
|
810
819
|
*/
|
|
811
820
|
export const calculateW = <T extends QuaternionLike>(
|
|
812
|
-
quaternion: QuaternionLike
|
|
821
|
+
quaternion: Readonly<QuaternionLike>,
|
|
813
822
|
out: T
|
|
814
823
|
): T => {
|
|
815
824
|
const x = quaternion[0];
|
|
@@ -834,7 +843,7 @@ export const calculateW = <T extends QuaternionLike>(
|
|
|
834
843
|
* @public
|
|
835
844
|
*/
|
|
836
845
|
export const exp = <T extends QuaternionLike>(
|
|
837
|
-
quaternion: QuaternionLike
|
|
846
|
+
quaternion: Readonly<QuaternionLike>,
|
|
838
847
|
out: T
|
|
839
848
|
): T => {
|
|
840
849
|
const x = quaternion[0];
|
|
@@ -856,7 +865,7 @@ export const exp = <T extends QuaternionLike>(
|
|
|
856
865
|
* @public
|
|
857
866
|
*/
|
|
858
867
|
export const ln = <T extends QuaternionLike>(
|
|
859
|
-
quaternion: QuaternionLike
|
|
868
|
+
quaternion: Readonly<QuaternionLike>,
|
|
860
869
|
out: T
|
|
861
870
|
): T => {
|
|
862
871
|
const x = quaternion[0];
|
|
@@ -880,7 +889,7 @@ export const ln = <T extends QuaternionLike>(
|
|
|
880
889
|
* @public
|
|
881
890
|
*/
|
|
882
891
|
export const pow = <T extends QuaternionLike>(
|
|
883
|
-
quaternion: QuaternionLike
|
|
892
|
+
quaternion: Readonly<QuaternionLike>,
|
|
884
893
|
scalar: number,
|
|
885
894
|
out: T
|
|
886
895
|
): T => exp(scale(ln(quaternion, out), scalar, out), out);
|
|
@@ -896,8 +905,8 @@ export const pow = <T extends QuaternionLike>(
|
|
|
896
905
|
* @public
|
|
897
906
|
*/
|
|
898
907
|
export const slerp = <T extends QuaternionLike>(
|
|
899
|
-
a: QuaternionLike
|
|
900
|
-
b: QuaternionLike
|
|
908
|
+
a: Readonly<QuaternionLike>,
|
|
909
|
+
b: Readonly<QuaternionLike>,
|
|
901
910
|
t: number,
|
|
902
911
|
out: T
|
|
903
912
|
): T => {
|
|
@@ -976,7 +985,7 @@ export const random = <T extends QuaternionLike>(out: T): T => {
|
|
|
976
985
|
* @public
|
|
977
986
|
*/
|
|
978
987
|
export const invert = <T extends QuaternionLike>(
|
|
979
|
-
quaternion: QuaternionLike
|
|
988
|
+
quaternion: Readonly<QuaternionLike>,
|
|
980
989
|
out: T
|
|
981
990
|
): T => {
|
|
982
991
|
const a0 = quaternion[0];
|
|
@@ -1000,7 +1009,7 @@ export const invert = <T extends QuaternionLike>(
|
|
|
1000
1009
|
* @public
|
|
1001
1010
|
*/
|
|
1002
1011
|
export const conjugate = <T extends QuaternionLike>(
|
|
1003
|
-
quaternion: QuaternionLike
|
|
1012
|
+
quaternion: Readonly<QuaternionLike>,
|
|
1004
1013
|
out: T
|
|
1005
1014
|
): T =>
|
|
1006
1015
|
fromValues(
|
|
@@ -1028,10 +1037,10 @@ const controlPointTwo = createQuaternionLike();
|
|
|
1028
1037
|
* @public
|
|
1029
1038
|
*/
|
|
1030
1039
|
export const sqlerp = <T extends QuaternionLike>(
|
|
1031
|
-
a: QuaternionLike
|
|
1032
|
-
b: QuaternionLike
|
|
1033
|
-
c: QuaternionLike
|
|
1034
|
-
d: QuaternionLike
|
|
1040
|
+
a: Readonly<QuaternionLike>,
|
|
1041
|
+
b: Readonly<QuaternionLike>,
|
|
1042
|
+
c: Readonly<QuaternionLike>,
|
|
1043
|
+
d: Readonly<QuaternionLike>,
|
|
1035
1044
|
t: number,
|
|
1036
1045
|
out: T
|
|
1037
1046
|
): T =>
|
|
@@ -1060,8 +1069,8 @@ const iv3 = createVector3Like();
|
|
|
1060
1069
|
* @public
|
|
1061
1070
|
*/
|
|
1062
1071
|
export const fromRotationTo = <T extends QuaternionLike>(
|
|
1063
|
-
a: Vector3Like
|
|
1064
|
-
b: Vector3Like
|
|
1072
|
+
a: Readonly<Vector3Like>,
|
|
1073
|
+
b: Readonly<Vector3Like>,
|
|
1065
1074
|
out: T
|
|
1066
1075
|
): T => {
|
|
1067
1076
|
const dp = vector3Dot(a, b);
|
|
@@ -1072,7 +1081,7 @@ export const fromRotationTo = <T extends QuaternionLike>(
|
|
|
1072
1081
|
vector3Cross(yAxis, a, iv3);
|
|
1073
1082
|
}
|
|
1074
1083
|
vector3Normalize(iv3, iv3);
|
|
1075
|
-
return setAxisAngle(
|
|
1084
|
+
return setAxisAngle(iv3, Math.PI, out);
|
|
1076
1085
|
}
|
|
1077
1086
|
|
|
1078
1087
|
if (dp > 1 - epsilon) {
|
|
@@ -1106,12 +1115,15 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1106
1115
|
public 3: number;
|
|
1107
1116
|
|
|
1108
1117
|
/** The axis and angle that represent this quaternion. */
|
|
1109
|
-
public get axisAngle():
|
|
1110
|
-
return getAxisAngle(this,
|
|
1118
|
+
public get axisAngle(): readonly [Readonly<Vector3Like>, number] {
|
|
1119
|
+
return getAxisAngle(this, createVector3Like());
|
|
1111
1120
|
}
|
|
1112
1121
|
|
|
1113
|
-
public set axisAngle(
|
|
1114
|
-
|
|
1122
|
+
public set axisAngle([axis, angle]: readonly [
|
|
1123
|
+
Readonly<Vector3Like>,
|
|
1124
|
+
number
|
|
1125
|
+
]) {
|
|
1126
|
+
setAxisAngle(axis, angle, this);
|
|
1115
1127
|
}
|
|
1116
1128
|
|
|
1117
1129
|
/** Get the magnitude (length) of this quaternion. */
|
|
@@ -1141,9 +1153,9 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1141
1153
|
* @returns The quaternion.
|
|
1142
1154
|
*/
|
|
1143
1155
|
public static fromAxes(
|
|
1144
|
-
view: Vector3Like
|
|
1145
|
-
right: Vector3Like
|
|
1146
|
-
up: Vector3Like
|
|
1156
|
+
view: Readonly<Vector3Like>,
|
|
1157
|
+
right: Readonly<Vector3Like>,
|
|
1158
|
+
up: Readonly<Vector3Like>
|
|
1147
1159
|
): Quaternion {
|
|
1148
1160
|
return fromAxes(view, right, up, new Quaternion());
|
|
1149
1161
|
}
|
|
@@ -1166,7 +1178,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1166
1178
|
* @returns The quaternion.
|
|
1167
1179
|
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1168
1180
|
*/
|
|
1169
|
-
public static fromMatrix3(matrix: Matrix3Like): Quaternion {
|
|
1181
|
+
public static fromMatrix3(matrix: Readonly<Matrix3Like>): Quaternion {
|
|
1170
1182
|
return fromMatrix3(matrix, new Quaternion());
|
|
1171
1183
|
}
|
|
1172
1184
|
|
|
@@ -1176,7 +1188,10 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1176
1188
|
* @param b - The second unit vector.
|
|
1177
1189
|
* @returns The unit quaternion.
|
|
1178
1190
|
*/
|
|
1179
|
-
public static fromRotationTo(
|
|
1191
|
+
public static fromRotationTo(
|
|
1192
|
+
a: Readonly<Vector3Like>,
|
|
1193
|
+
b: Readonly<Vector3Like>
|
|
1194
|
+
): Quaternion {
|
|
1180
1195
|
return fromRotationTo(a, b, new Quaternion());
|
|
1181
1196
|
}
|
|
1182
1197
|
|
|
@@ -1202,7 +1217,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1202
1217
|
* @param quaternion - The other quaternion.
|
|
1203
1218
|
* @returns The sum of the quaternions.
|
|
1204
1219
|
*/
|
|
1205
|
-
public add(quaternion: QuaternionLike): Quaternion {
|
|
1220
|
+
public add(quaternion: Readonly<QuaternionLike>): Quaternion {
|
|
1206
1221
|
return add(this, quaternion, new Quaternion());
|
|
1207
1222
|
}
|
|
1208
1223
|
|
|
@@ -1235,7 +1250,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1235
1250
|
* @param quaternion - The quaternion to copy.
|
|
1236
1251
|
* @returns This quaternion.
|
|
1237
1252
|
*/
|
|
1238
|
-
public copy(quaternion: QuaternionLike): this {
|
|
1253
|
+
public copy(quaternion: Readonly<QuaternionLike>): this {
|
|
1239
1254
|
return copy(quaternion, this);
|
|
1240
1255
|
}
|
|
1241
1256
|
|
|
@@ -1244,7 +1259,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1244
1259
|
* @param quaternion - The other quaternion.
|
|
1245
1260
|
* @returns The dot product.
|
|
1246
1261
|
*/
|
|
1247
|
-
public dot(quaternion: QuaternionLike): number {
|
|
1262
|
+
public dot(quaternion: Readonly<QuaternionLike>): number {
|
|
1248
1263
|
return dot(this, quaternion);
|
|
1249
1264
|
}
|
|
1250
1265
|
|
|
@@ -1253,7 +1268,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1253
1268
|
* @param quaternion - The other quaternion.
|
|
1254
1269
|
* @returns Whether or not the quaternions are equivalent.
|
|
1255
1270
|
*/
|
|
1256
|
-
public equals(quaternion: QuaternionLike): boolean {
|
|
1271
|
+
public equals(quaternion: Readonly<QuaternionLike>): boolean {
|
|
1257
1272
|
return equals(this, quaternion);
|
|
1258
1273
|
}
|
|
1259
1274
|
|
|
@@ -1262,7 +1277,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1262
1277
|
* @param quaternion - The other quaternion.
|
|
1263
1278
|
* @returns Whether or not the quaternions are equivalent.
|
|
1264
1279
|
*/
|
|
1265
|
-
public exactEquals(quaternion: QuaternionLike): boolean {
|
|
1280
|
+
public exactEquals(quaternion: Readonly<QuaternionLike>): boolean {
|
|
1266
1281
|
return exactEquals(this, quaternion);
|
|
1267
1282
|
}
|
|
1268
1283
|
|
|
@@ -1279,7 +1294,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1279
1294
|
* @param quaternion - The other unit quaternion.
|
|
1280
1295
|
* @returns The angular distance in radians.
|
|
1281
1296
|
*/
|
|
1282
|
-
public getAngle(quaternion: QuaternionLike): number {
|
|
1297
|
+
public getAngle(quaternion: Readonly<QuaternionLike>): number {
|
|
1283
1298
|
return getAngle(this, quaternion);
|
|
1284
1299
|
}
|
|
1285
1300
|
|
|
@@ -1305,7 +1320,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1305
1320
|
* @param t - The interpolation amount (in `[0,1]`).
|
|
1306
1321
|
* @returns The interpolated quaternion.
|
|
1307
1322
|
*/
|
|
1308
|
-
public lerp(quaternion: QuaternionLike
|
|
1323
|
+
public lerp(quaternion: Readonly<QuaternionLike>, t: number): Quaternion {
|
|
1309
1324
|
return lerp(this, quaternion, t, new Quaternion());
|
|
1310
1325
|
}
|
|
1311
1326
|
|
|
@@ -1322,7 +1337,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1322
1337
|
* @param quaternion - The other quaternion.
|
|
1323
1338
|
* @returns The product.
|
|
1324
1339
|
*/
|
|
1325
|
-
public multiply(quaternion: QuaternionLike): Quaternion {
|
|
1340
|
+
public multiply(quaternion: Readonly<QuaternionLike>): Quaternion {
|
|
1326
1341
|
return multiply(this, quaternion, new Quaternion());
|
|
1327
1342
|
}
|
|
1328
1343
|
|
|
@@ -1394,7 +1409,7 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1394
1409
|
* @returns The interpolated quaternion.
|
|
1395
1410
|
* @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
|
|
1396
1411
|
*/
|
|
1397
|
-
public slerp(quaternion: QuaternionLike
|
|
1412
|
+
public slerp(quaternion: Readonly<QuaternionLike>, t: number): Quaternion {
|
|
1398
1413
|
return slerp(this, quaternion, t, new Quaternion());
|
|
1399
1414
|
}
|
|
1400
1415
|
|
|
@@ -1408,9 +1423,9 @@ export default class Quaternion extends Float32Array implements QuaternionLike {
|
|
|
1408
1423
|
* @see {@link https://en.wikipedia.org/wiki/Slerp | Slerp}
|
|
1409
1424
|
*/
|
|
1410
1425
|
public sqlerp(
|
|
1411
|
-
a: QuaternionLike
|
|
1412
|
-
b: QuaternionLike
|
|
1413
|
-
quaternion: QuaternionLike
|
|
1426
|
+
a: Readonly<QuaternionLike>,
|
|
1427
|
+
b: Readonly<QuaternionLike>,
|
|
1428
|
+
quaternion: Readonly<QuaternionLike>,
|
|
1414
1429
|
t: number
|
|
1415
1430
|
): Quaternion {
|
|
1416
1431
|
return sqlerp(this, a, b, quaternion, t, new Quaternion());
|
package/src/linalg/SlowMatrix.ts
CHANGED
|
@@ -20,7 +20,7 @@ interface SizedMatrixLike extends MatrixLike {
|
|
|
20
20
|
* Determine whether the given `MatrixLike` has size information.
|
|
21
21
|
* @internal
|
|
22
22
|
*/
|
|
23
|
-
const isSized = (matrix: MatrixLike): matrix is SizedMatrixLike =>
|
|
23
|
+
const isSized = (matrix: Readonly<MatrixLike>): matrix is SizedMatrixLike =>
|
|
24
24
|
"width" in matrix &&
|
|
25
25
|
typeof matrix.width === "number" &&
|
|
26
26
|
"height" in matrix &&
|
|
@@ -50,7 +50,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
50
50
|
* Create a variable-size matrix from the given columns.
|
|
51
51
|
* @param cols - The columns in the matrix.
|
|
52
52
|
*/
|
|
53
|
-
public constructor(...cols: number[][]) {
|
|
53
|
+
public constructor(...cols: readonly (readonly number[])[]) {
|
|
54
54
|
super(cols.flat());
|
|
55
55
|
|
|
56
56
|
this.width = cols.length;
|
|
@@ -70,7 +70,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
70
70
|
* @returns The sum of the matrices.
|
|
71
71
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
72
72
|
*/
|
|
73
|
-
public add(matrix: MatrixLike): SlowMatrix {
|
|
73
|
+
public add(matrix: Readonly<MatrixLike>): SlowMatrix {
|
|
74
74
|
if (
|
|
75
75
|
!isSized(matrix) ||
|
|
76
76
|
this.width !== matrix.width ||
|
|
@@ -110,7 +110,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
110
110
|
* @param matrix - The matrix to copy.
|
|
111
111
|
* @returns This matrix.
|
|
112
112
|
*/
|
|
113
|
-
public copy(matrix: MatrixLike): this {
|
|
113
|
+
public copy(matrix: Readonly<MatrixLike>): this {
|
|
114
114
|
if (
|
|
115
115
|
!isSized(matrix) ||
|
|
116
116
|
this.width !== matrix.width ||
|
|
@@ -131,7 +131,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
131
131
|
* @param matrix - The other matrix.
|
|
132
132
|
* @returns Whether or not the matrices are equivalent.
|
|
133
133
|
*/
|
|
134
|
-
public equals(matrix: MatrixLike): boolean {
|
|
134
|
+
public equals(matrix: Readonly<MatrixLike>): boolean {
|
|
135
135
|
if (
|
|
136
136
|
!isSized(matrix) ||
|
|
137
137
|
this.width !== matrix.width ||
|
|
@@ -154,7 +154,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
154
154
|
* @param matrix - The other matrix.
|
|
155
155
|
* @returns Whether the matrices are equivalent.
|
|
156
156
|
*/
|
|
157
|
-
public exactEquals(matrix: MatrixLike): boolean {
|
|
157
|
+
public exactEquals(matrix: Readonly<MatrixLike>): boolean {
|
|
158
158
|
if (
|
|
159
159
|
!isSized(matrix) ||
|
|
160
160
|
this.width !== matrix.width ||
|
|
@@ -178,7 +178,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
178
178
|
* @returns The product of the matrices.
|
|
179
179
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
|
|
180
180
|
*/
|
|
181
|
-
public multiply(matrix: MatrixLike): SlowMatrix {
|
|
181
|
+
public multiply(matrix: Readonly<MatrixLike>): SlowMatrix {
|
|
182
182
|
if (!isSized(matrix) || this.width !== matrix.height) {
|
|
183
183
|
throw new MatrixSizeError();
|
|
184
184
|
}
|
|
@@ -227,7 +227,10 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
227
227
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
228
228
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_multiplication | Matrix multiplication}
|
|
229
229
|
*/
|
|
230
|
-
public multiplyScalarAndAdd(
|
|
230
|
+
public multiplyScalarAndAdd(
|
|
231
|
+
matrix: Readonly<MatrixLike>,
|
|
232
|
+
scalar: number
|
|
233
|
+
): SlowMatrix {
|
|
231
234
|
if (
|
|
232
235
|
!isSized(matrix) ||
|
|
233
236
|
this.width !== matrix.width ||
|
|
@@ -253,7 +256,7 @@ export default class SlowMatrix extends Float32Array implements Matrix {
|
|
|
253
256
|
* @returns The difference between the matrices.
|
|
254
257
|
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
255
258
|
*/
|
|
256
|
-
public subtract(matrix: MatrixLike): SlowMatrix {
|
|
259
|
+
public subtract(matrix: Readonly<MatrixLike>): SlowMatrix {
|
|
257
260
|
if (
|
|
258
261
|
!isSized(matrix) ||
|
|
259
262
|
this.width !== matrix.width ||
|
|
@@ -43,7 +43,7 @@ export default class SlowSquareMatrix
|
|
|
43
43
|
* @param cols - The columns in the matrix.
|
|
44
44
|
* @see {@link https://en.wikipedia.org/wiki/Square_matrix | Square matrix}
|
|
45
45
|
*/
|
|
46
|
-
public constructor(...cols: number[][]) {
|
|
46
|
+
public constructor(...cols: readonly (readonly number[])[]) {
|
|
47
47
|
super(...cols);
|
|
48
48
|
|
|
49
49
|
// Ensure that every column is the same height and that the height is equal to the width.
|