@lakuna/umath 2.0.0 → 3.0.1

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 (88) hide show
  1. package/LICENSE +1 -1
  2. package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
  3. package/dist/algorithms/greatestCommonDivisor.js +14 -4
  4. package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
  5. package/dist/index.d.ts +12 -12
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/linalg/DualQuaternion.d.ts +158 -158
  9. package/dist/linalg/DualQuaternion.d.ts.map +1 -1
  10. package/dist/linalg/DualQuaternion.js +173 -165
  11. package/dist/linalg/DualQuaternion.js.map +1 -1
  12. package/dist/linalg/Matrix.d.ts +24 -24
  13. package/dist/linalg/Matrix.d.ts.map +1 -1
  14. package/dist/linalg/Matrix2.d.ts +85 -85
  15. package/dist/linalg/Matrix2.d.ts.map +1 -1
  16. package/dist/linalg/Matrix2.js +92 -88
  17. package/dist/linalg/Matrix2.js.map +1 -1
  18. package/dist/linalg/Matrix3.d.ts +134 -134
  19. package/dist/linalg/Matrix3.d.ts.map +1 -1
  20. package/dist/linalg/Matrix3.js +147 -138
  21. package/dist/linalg/Matrix3.js.map +1 -1
  22. package/dist/linalg/Matrix4.d.ts +245 -246
  23. package/dist/linalg/Matrix4.d.ts.map +1 -1
  24. package/dist/linalg/Matrix4.js +272 -251
  25. package/dist/linalg/Matrix4.js.map +1 -1
  26. package/dist/linalg/Quaternion.d.ts +147 -146
  27. package/dist/linalg/Quaternion.d.ts.map +1 -1
  28. package/dist/linalg/Quaternion.js +175 -161
  29. package/dist/linalg/Quaternion.js.map +1 -1
  30. package/dist/linalg/SlowMatrix.d.ts +12 -12
  31. package/dist/linalg/SlowMatrix.d.ts.map +1 -1
  32. package/dist/linalg/SlowMatrix.js +12 -12
  33. package/dist/linalg/SlowMatrix.js.map +1 -1
  34. package/dist/linalg/SlowSquareMatrix.d.ts +7 -7
  35. package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
  36. package/dist/linalg/SlowSquareMatrix.js +15 -15
  37. package/dist/linalg/SlowSquareMatrix.js.map +1 -1
  38. package/dist/linalg/SlowVector.d.ts +77 -77
  39. package/dist/linalg/SlowVector.d.ts.map +1 -1
  40. package/dist/linalg/SlowVector.js +153 -153
  41. package/dist/linalg/SlowVector.js.map +1 -1
  42. package/dist/linalg/SquareMatrix.d.ts +8 -8
  43. package/dist/linalg/SquareMatrix.d.ts.map +1 -1
  44. package/dist/linalg/Vector.d.ts +85 -84
  45. package/dist/linalg/Vector.d.ts.map +1 -1
  46. package/dist/linalg/Vector2.d.ts +143 -143
  47. package/dist/linalg/Vector2.d.ts.map +1 -1
  48. package/dist/linalg/Vector2.js +145 -143
  49. package/dist/linalg/Vector2.js.map +1 -1
  50. package/dist/linalg/Vector3.d.ts +173 -173
  51. package/dist/linalg/Vector3.d.ts.map +1 -1
  52. package/dist/linalg/Vector3.js +176 -173
  53. package/dist/linalg/Vector3.js.map +1 -1
  54. package/dist/linalg/Vector4.d.ts +137 -137
  55. package/dist/linalg/Vector4.d.ts.map +1 -1
  56. package/dist/linalg/Vector4.js +144 -140
  57. package/dist/linalg/Vector4.js.map +1 -1
  58. package/dist/types/AxisAngle.d.ts +11 -1
  59. package/dist/types/AxisAngle.d.ts.map +1 -1
  60. package/dist/types/FieldOfView.d.ts +2 -2
  61. package/dist/types/FieldOfView.d.ts.map +1 -1
  62. package/dist/utility/BigNumber.d.ts +21 -11
  63. package/dist/utility/BigNumber.d.ts.map +1 -1
  64. package/dist/utility/BigNumber.js +49 -31
  65. package/dist/utility/BigNumber.js.map +1 -1
  66. package/dist/utility/createAxisAngleLike.d.ts.map +1 -1
  67. package/dist/utility/createAxisAngleLike.js.map +1 -1
  68. package/package.json +13 -12
  69. package/src/algorithms/greatestCommonDivisor.ts +19 -7
  70. package/src/index.ts +21 -14
  71. package/src/linalg/DualQuaternion.ts +264 -238
  72. package/src/linalg/Matrix.ts +31 -28
  73. package/src/linalg/Matrix2.ts +157 -137
  74. package/src/linalg/Matrix3.ts +222 -191
  75. package/src/linalg/Matrix4.ts +464 -412
  76. package/src/linalg/Quaternion.ts +267 -234
  77. package/src/linalg/SlowMatrix.ts +31 -27
  78. package/src/linalg/SlowSquareMatrix.ts +19 -18
  79. package/src/linalg/SlowVector.ts +175 -174
  80. package/src/linalg/SquareMatrix.ts +9 -9
  81. package/src/linalg/Vector.ts +91 -89
  82. package/src/linalg/Vector2.ts +250 -217
  83. package/src/linalg/Vector3.ts +309 -269
  84. package/src/linalg/Vector4.ts +246 -206
  85. package/src/types/AxisAngle.ts +13 -1
  86. package/src/types/FieldOfView.ts +3 -3
  87. package/src/utility/BigNumber.ts +71 -38
  88. package/src/utility/createAxisAngleLike.ts +1 -0
@@ -1,163 +1,164 @@
1
- /**
2
- * An object that could be interpreted as a vector.
3
- * @public
4
- */
5
- export type VectorLike = Record<number, number>;
1
+ import type { Vector4Like } from "./Vector4.js";
6
2
  /**
7
3
  * A quantity with magnitude and direction.
8
4
  * @see {@link https://en.wikipedia.org/wiki/Euclidean_vector | Euclidean vector}
9
5
  * @public
10
6
  */
11
7
  export default interface Vector extends VectorLike {
12
- /**
13
- * Determine whether this vector is roughly equivalent to another.
14
- * @param vector - The other vector.
15
- * @returns Whether the vectors are equivalent.
16
- */
17
- equals(vector: VectorLike): boolean;
18
- /**
19
- * Determine whether this vector is exactly equivalent to another.
20
- * @param vector - The other vector.
21
- * @returns Whether the vectors are equivalent.
22
- */
23
- exactEquals(vector: VectorLike): boolean;
24
8
  /**
25
9
  * Add two vectors of the same size.
26
10
  * @param vector - The other vector.
27
11
  * @returns The sum of the vectors.
28
12
  */
29
- add(vector: VectorLike): VectorLike;
13
+ add: (vector: Readonly<Vector4Like>) => VectorLike;
14
+ /**
15
+ * Round up the components of this vector.
16
+ * @returns The rounded vector.
17
+ */
18
+ ceil: () => VectorLike;
30
19
  /**
31
20
  * Create a copy of this vector.
32
21
  * @returns A copy of this vector.
33
22
  */
34
- clone(): VectorLike;
23
+ clone: () => VectorLike;
35
24
  /**
36
25
  * Copy the values of another vector into this one.
37
26
  * @param vector - The vector to copy.
38
27
  * @returns This vector.
39
28
  */
40
- copy(vector: VectorLike): this;
29
+ copy: (vector: Readonly<Vector4Like>) => this;
41
30
  /**
42
- * Multiply this vector by another.
31
+ * Calculate the Euclidean distance between this vector and another.
43
32
  * @param vector - The other vector.
44
- * @returns The product of the vectors.
33
+ * @returns The distance.
45
34
  */
46
- multiply(vector: VectorLike): VectorLike;
35
+ distance: (vector: Readonly<Vector4Like>) => number;
47
36
  /**
48
37
  * Divide this vector by another.
49
38
  * @param vector - The other vector.
50
39
  * @returns The quotient of the vectors.
51
40
  */
52
- divide(vector: VectorLike): VectorLike;
41
+ divide: (vector: Readonly<Vector4Like>) => VectorLike;
53
42
  /**
54
- * Subtract another vector from this one.
43
+ * Calculate the dot product of this and another vector.
55
44
  * @param vector - The other vector.
56
- * @returns The difference between the vectors.
45
+ * @returns The dot product.
46
+ * @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
57
47
  */
58
- subtract(vector: VectorLike): VectorLike;
48
+ dot: (vector: Readonly<Vector4Like>) => number;
59
49
  /**
60
- * Round up the components of this vector.
61
- * @returns The rounded vector.
50
+ * Determine whether this vector is roughly equivalent to another.
51
+ * @param vector - The other vector.
52
+ * @returns Whether the vectors are equivalent.
53
+ */
54
+ equals: (vector: Readonly<Vector4Like>) => boolean;
55
+ /**
56
+ * Determine whether this vector is exactly equivalent to another.
57
+ * @param vector - The other vector.
58
+ * @returns Whether the vectors are equivalent.
62
59
  */
63
- ceil(): VectorLike;
60
+ exactEquals: (vector: Readonly<Vector4Like>) => boolean;
64
61
  /**
65
62
  * Round down the components of this vector.
66
63
  * @returns The rounded vector.
67
64
  */
68
- floor(): VectorLike;
65
+ floor: () => VectorLike;
69
66
  /**
70
- * Round the components of this vector.
71
- * @returns The rounded vector.
67
+ * Calculate the multiplicative inverse of the components of this vector.
68
+ * @returns The inverted vector.
72
69
  */
73
- round(): VectorLike;
70
+ invert: () => VectorLike;
74
71
  /**
75
- * Return the minimum of this and another vector.
72
+ * Perform a linear interpolation between this and another vector.
76
73
  * @param vector - The other vector.
77
- * @returns The minimum.
74
+ * @param t - The interpolation amount (in `[0,1]`).
75
+ * @returns The interpolated vector.
78
76
  */
79
- min(vector: VectorLike): VectorLike;
77
+ lerp: (vector: Readonly<Vector4Like>, t: number) => VectorLike;
78
+ /** Get the magnitude (length) of this vector. */
79
+ get magnitude(): number;
80
80
  /**
81
81
  * Return the maximum of this and another vector.
82
82
  * @param vector - The other vector.
83
83
  * @returns The maximum.
84
84
  */
85
- max(vector: VectorLike): VectorLike;
85
+ max: (vector: Readonly<Vector4Like>) => VectorLike;
86
+ /**
87
+ * Return the minimum of this and another vector.
88
+ * @param vector - The other vector.
89
+ * @returns The minimum.
90
+ */
91
+ min: (vector: Readonly<Vector4Like>) => VectorLike;
92
+ /**
93
+ * Multiply this vector by another.
94
+ * @param vector - The other vector.
95
+ * @returns The product of the vectors.
96
+ */
97
+ multiply: (vector: Readonly<Vector4Like>) => VectorLike;
98
+ /**
99
+ * Negate this vector.
100
+ * @returns The negated vector.
101
+ */
102
+ negate: () => VectorLike;
103
+ /**
104
+ * Normalize this vector.
105
+ * @returns The normalized vector.
106
+ * @see {@link https://en.wikipedia.org/wiki/Unit_vector | Unit vector}
107
+ */
108
+ normalize: () => VectorLike;
86
109
  /**
87
110
  * Raise each component of this vector to the given power.
88
111
  * @param exponent - The exponent (power) to raise each component to.
89
112
  * @returns The power (result of the exponentiation).
90
113
  */
91
- pow(exponent: number): VectorLike;
114
+ pow: (exponent: number) => VectorLike;
115
+ /**
116
+ * Set this vector to a random value with the given magnitude.
117
+ * @param magnitude - The magnitude.
118
+ * @returns This vector.
119
+ */
120
+ random: (magnitude: number) => this;
121
+ /**
122
+ * Round the components of this vector.
123
+ * @returns The rounded vector.
124
+ */
125
+ round: () => VectorLike;
92
126
  /**
93
127
  * Scale this vector by a scalar.
94
128
  * @param scalar - The scalar.
95
129
  * @returns The scaled vector.
96
130
  */
97
- scale(scalar: number): VectorLike;
131
+ scale: (scalar: number) => VectorLike;
98
132
  /**
99
133
  * Add another vector to this one after scaling the other by a scalar.
100
134
  * @param vector - The other vector.
101
135
  * @param scalar - The scalar.
102
136
  * @returns The sum.
103
137
  */
104
- scaleAndAdd(vector: VectorLike, scalar: number): VectorLike;
105
- /**
106
- * Calculate the Euclidean distance between this vector and another.
107
- * @param vector - The other vector.
108
- * @returns The distance.
109
- */
110
- distance(vector: VectorLike): number;
138
+ scaleAndAdd: (vector: Readonly<Vector4Like>, scalar: number) => VectorLike;
111
139
  /**
112
140
  * Calculate the squared Euclidean distance between this vector and another.
113
141
  * @param vector - The other vector.
114
142
  * @returns The squared distance.
115
143
  */
116
- squaredDistance(vector: VectorLike): number;
117
- /** Get the magnitude (length) of this vector. */
118
- get magnitude(): number;
144
+ squaredDistance: (vector: Readonly<Vector4Like>) => number;
119
145
  /** Get the squared magnitude (length) of this vector. */
120
146
  get squaredMagnitude(): number;
121
147
  /**
122
- * Negate this vector.
123
- * @returns The negated vector.
124
- */
125
- negate(): VectorLike;
126
- /**
127
- * Calculate the multiplicative inverse of the components of this vector.
128
- * @returns The inverted vector.
129
- */
130
- invert(): VectorLike;
131
- /**
132
- * Normalize this vector.
133
- * @returns The normalized vector.
134
- * @see {@link https://en.wikipedia.org/wiki/Unit_vector | Unit vector}
135
- */
136
- normalize(): VectorLike;
137
- /**
138
- * Calculate the dot product of this and another vector.
139
- * @param vector - The other vector.
140
- * @returns The dot product.
141
- * @see {@link https://en.wikipedia.org/wiki/Dot_product | Dot product}
142
- */
143
- dot(vector: VectorLike): number;
144
- /**
145
- * Perform a linear interpolation between this and another vector.
148
+ * Subtract another vector from this one.
146
149
  * @param vector - The other vector.
147
- * @param t - The interpolation amount (in `[0,1]`).
148
- * @returns The interpolated vector.
149
- */
150
- lerp(vector: VectorLike, t: number): VectorLike;
151
- /**
152
- * Set this vector to a random value with the given magnitude.
153
- * @param magnitude - The magnitude.
154
- * @returns This vector.
150
+ * @returns The difference between the vectors.
155
151
  */
156
- random(magnitude: number): this;
152
+ subtract: (vector: Readonly<Vector4Like>) => VectorLike;
157
153
  /**
158
154
  * Set this to the zero vector.
159
155
  * @returns This vector.
160
156
  */
161
- zero(): this;
157
+ zero: () => this;
162
158
  }
159
+ /**
160
+ * An object that could be interpreted as a vector.
161
+ * @public
162
+ */
163
+ export type VectorLike = Record<number, number>;
163
164
  //# sourceMappingURL=Vector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Vector.d.ts","sourceRoot":"","sources":["../../src/linalg/Vector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,MAAO,SAAQ,UAAU;IACjD;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC;IAEpC;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC;IAEzC;;;;OAIG;IACH,GAAG,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;IAEpC;;;OAGG;IACH,KAAK,IAAI,UAAU,CAAC;IAEpB;;;;OAIG;IACH,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAE/B;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;IAEzC;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;IAEvC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;IAEzC;;;OAGG;IACH,IAAI,IAAI,UAAU,CAAC;IAEnB;;;OAGG;IACH,KAAK,IAAI,U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