@pawells/math-extended 1.0.5 → 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.
- package/README.md +5 -5
- package/build/angles.d.ts +43 -3
- package/build/angles.d.ts.map +1 -1
- package/build/angles.js +61 -34
- package/build/angles.js.map +1 -1
- package/build/clamp.d.ts +5 -3
- package/build/clamp.d.ts.map +1 -1
- package/build/clamp.js +5 -3
- package/build/clamp.js.map +1 -1
- package/build/interpolation.d.ts +444 -67
- package/build/interpolation.d.ts.map +1 -1
- package/build/interpolation.js +444 -67
- package/build/interpolation.js.map +1 -1
- package/build/matrices/_exports.d.ts +13 -0
- package/build/matrices/_exports.d.ts.map +1 -0
- package/build/matrices/_exports.js +13 -0
- package/build/matrices/_exports.js.map +1 -0
- package/build/matrices/arithmetic.d.ts +170 -181
- package/build/matrices/arithmetic.d.ts.map +1 -1
- package/build/matrices/arithmetic.js +192 -202
- package/build/matrices/arithmetic.js.map +1 -1
- package/build/matrices/asserts.d.ts +244 -116
- package/build/matrices/asserts.d.ts.map +1 -1
- package/build/matrices/asserts.js +291 -94
- package/build/matrices/asserts.js.map +1 -1
- package/build/matrices/core.d.ts +40 -41
- package/build/matrices/core.d.ts.map +1 -1
- package/build/matrices/core.js +12 -13
- package/build/matrices/core.js.map +1 -1
- package/build/matrices/decompositions.d.ts +121 -124
- package/build/matrices/decompositions.d.ts.map +1 -1
- package/build/matrices/decompositions.js +168 -226
- package/build/matrices/decompositions.js.map +1 -1
- package/build/matrices/index.d.ts +3 -2
- package/build/matrices/index.d.ts.map +1 -1
- package/build/matrices/index.js +5 -2
- package/build/matrices/index.js.map +1 -1
- package/build/matrices/linear-algebra.d.ts +18 -13
- package/build/matrices/linear-algebra.d.ts.map +1 -1
- package/build/matrices/linear-algebra.js +58 -23
- package/build/matrices/linear-algebra.js.map +1 -1
- package/build/matrices/normalization.d.ts +8 -8
- package/build/matrices/transformations.d.ts +184 -168
- package/build/matrices/transformations.d.ts.map +1 -1
- package/build/matrices/transformations.js +99 -83
- package/build/matrices/transformations.js.map +1 -1
- package/build/matrices/types.d.ts +12 -12
- package/build/matrices/types.d.ts.map +1 -1
- package/build/quaternions/_exports.d.ts +11 -0
- package/build/quaternions/_exports.d.ts.map +1 -0
- package/build/quaternions/_exports.js +11 -0
- package/build/quaternions/_exports.js.map +1 -0
- package/build/quaternions/asserts.d.ts +115 -7
- package/build/quaternions/asserts.d.ts.map +1 -1
- package/build/quaternions/asserts.js +162 -8
- package/build/quaternions/asserts.js.map +1 -1
- package/build/quaternions/conversions.d.ts +31 -21
- package/build/quaternions/conversions.d.ts.map +1 -1
- package/build/quaternions/conversions.js +28 -18
- package/build/quaternions/conversions.js.map +1 -1
- package/build/quaternions/core.d.ts +73 -41
- package/build/quaternions/core.d.ts.map +1 -1
- package/build/quaternions/core.js +84 -49
- package/build/quaternions/core.js.map +1 -1
- package/build/quaternions/index.d.ts +3 -2
- package/build/quaternions/index.d.ts.map +1 -1
- package/build/quaternions/index.js +5 -2
- package/build/quaternions/index.js.map +1 -1
- package/build/quaternions/interpolation.d.ts +15 -9
- package/build/quaternions/interpolation.d.ts.map +1 -1
- package/build/quaternions/interpolation.js +15 -9
- package/build/quaternions/interpolation.js.map +1 -1
- package/build/quaternions/predefined.d.ts +9 -3
- package/build/quaternions/predefined.d.ts.map +1 -1
- package/build/quaternions/predefined.js +9 -3
- package/build/quaternions/predefined.js.map +1 -1
- package/build/quaternions/types.d.ts +3 -3
- package/build/random.d.ts +5 -2
- package/build/random.d.ts.map +1 -1
- package/build/random.js +20 -17
- package/build/random.js.map +1 -1
- package/build/vectors/_exports.d.ts +10 -0
- package/build/vectors/_exports.d.ts.map +1 -0
- package/build/vectors/_exports.js +10 -0
- package/build/vectors/_exports.js.map +1 -0
- package/build/vectors/asserts.d.ts +153 -49
- package/build/vectors/asserts.d.ts.map +1 -1
- package/build/vectors/asserts.js +202 -52
- package/build/vectors/asserts.js.map +1 -1
- package/build/vectors/core.d.ts +216 -137
- package/build/vectors/core.d.ts.map +1 -1
- package/build/vectors/core.js +217 -158
- package/build/vectors/core.js.map +1 -1
- package/build/vectors/index.d.ts +1 -0
- package/build/vectors/index.d.ts.map +1 -1
- package/build/vectors/index.js +3 -0
- package/build/vectors/index.js.map +1 -1
- package/build/vectors/interpolation.d.ts +39 -27
- package/build/vectors/interpolation.d.ts.map +1 -1
- package/build/vectors/interpolation.js +39 -27
- package/build/vectors/interpolation.js.map +1 -1
- package/build/vectors/predefined.d.ts +48 -24
- package/build/vectors/predefined.d.ts.map +1 -1
- package/build/vectors/predefined.js +38 -18
- package/build/vectors/predefined.js.map +1 -1
- package/package.json +12 -15
|
@@ -18,9 +18,11 @@ const QUATERNION_LOG_TOLERANCE = 1e-6;
|
|
|
18
18
|
* @returns Interpolated and normalized quaternion
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const q1 = [0, 0, 0, 1];
|
|
23
|
+
* const q2 = [0, 0, 0.707, 0.707];
|
|
24
|
+
* const interpolated = QuaternionNLERP(q1, q2, 0.5);
|
|
25
|
+
* ```
|
|
24
26
|
*/
|
|
25
27
|
export function QuaternionNLERP(a, b, t) {
|
|
26
28
|
AssertNormalizedQuaternion(a);
|
|
@@ -52,9 +54,11 @@ export function QuaternionNLERP(a, b, t) {
|
|
|
52
54
|
* @returns Smoothly interpolated quaternion
|
|
53
55
|
*
|
|
54
56
|
* @example
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // Create a smooth path through multiple rotations
|
|
59
|
+
* const path = [q0, q1, q2, q3]; // Array of quaternions
|
|
60
|
+
* const smooth = QuaternionSQUAD(path[0], path[1], path[2], path[3], 0.5);
|
|
61
|
+
* ```
|
|
58
62
|
*/
|
|
59
63
|
export function QuaternionSQUAD(q0, q1, q2, q3, t) {
|
|
60
64
|
AssertNormalizedQuaternion(q0);
|
|
@@ -150,9 +154,11 @@ function quaternionExp(quaternion) {
|
|
|
150
154
|
* @returns Function that takes t ∈ [0, 1] and returns interpolated quaternion
|
|
151
155
|
*
|
|
152
156
|
* @example
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const path = [q1, q2, q3, q4];
|
|
159
|
+
* const interpolator = QuaternionCreatePath(path, 'slerp');
|
|
160
|
+
* const halfway = interpolator(0.5); // Interpolated quaternion at 50% along path
|
|
161
|
+
* ```
|
|
156
162
|
*/
|
|
157
163
|
export function QuaternionCreatePath(quaternions, method = 'slerp') {
|
|
158
164
|
AssertArray(quaternions, { minSize: 2 });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolation.js","sourceRoot":"","sources":["../../src/quaternions/interpolation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACxG,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAEtC
|
|
1
|
+
{"version":3,"file":"interpolation.js","sourceRoot":"","sources":["../../src/quaternions/interpolation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACxG,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,MAAM,wBAAwB,GAA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AAE,CAAC;YAChB,KAAK,OAAO;gBACX,OAAO,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;YAC1C,KAAK,OAAO,CAAC,CAAC,CAAC;gBACd,oEAAoE;gBACpE,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC;gBACtD,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;gBAExE,mCAAmC;gBACnC,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE;oBAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;gBAEjF,OAAO,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;YAClD,CAAC;YACD,KAAK,OAAO,CAAC;YACb;gBACC,OAAO,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;QAC3C,CAAC;IACF,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -10,7 +10,9 @@ import { TQuaternion } from './types.js';
|
|
|
10
10
|
* @returns Quaternion representing rotation around X-axis
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const q = QuaternionRotationX(Math.PI / 2); // 90° rotation around X-axis
|
|
15
|
+
* ```
|
|
14
16
|
*/
|
|
15
17
|
export declare function QuaternionRotationX(angle: number): TQuaternion;
|
|
16
18
|
/**
|
|
@@ -20,7 +22,9 @@ export declare function QuaternionRotationX(angle: number): TQuaternion;
|
|
|
20
22
|
* @returns Quaternion representing rotation around Y-axis
|
|
21
23
|
*
|
|
22
24
|
* @example
|
|
23
|
-
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const q = QuaternionRotationY(Math.PI / 4); // 45° rotation around Y-axis
|
|
27
|
+
* ```
|
|
24
28
|
*/
|
|
25
29
|
export declare function QuaternionRotationY(angle: number): TQuaternion;
|
|
26
30
|
/**
|
|
@@ -30,7 +34,9 @@ export declare function QuaternionRotationY(angle: number): TQuaternion;
|
|
|
30
34
|
* @returns Quaternion representing rotation around Z-axis
|
|
31
35
|
*
|
|
32
36
|
* @example
|
|
33
|
-
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const q = QuaternionRotationZ(Math.PI); // 180° rotation around Z-axis
|
|
39
|
+
* ```
|
|
34
40
|
*/
|
|
35
41
|
export declare function QuaternionRotationZ(angle: number): TQuaternion;
|
|
36
42
|
//# sourceMappingURL=predefined.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predefined.d.ts","sourceRoot":"","sources":["../../src/quaternions/predefined.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC
|
|
1
|
+
{"version":3,"file":"predefined.d.ts","sourceRoot":"","sources":["../../src/quaternions/predefined.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAE9D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAE9D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAE9D"}
|
|
@@ -10,7 +10,9 @@ import { QuaternionFromAxisAngle } from './core.js';
|
|
|
10
10
|
* @returns Quaternion representing rotation around X-axis
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const q = QuaternionRotationX(Math.PI / 2); // 90° rotation around X-axis
|
|
15
|
+
* ```
|
|
14
16
|
*/
|
|
15
17
|
export function QuaternionRotationX(angle) {
|
|
16
18
|
return QuaternionFromAxisAngle([1, 0, 0], angle);
|
|
@@ -22,7 +24,9 @@ export function QuaternionRotationX(angle) {
|
|
|
22
24
|
* @returns Quaternion representing rotation around Y-axis
|
|
23
25
|
*
|
|
24
26
|
* @example
|
|
25
|
-
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const q = QuaternionRotationY(Math.PI / 4); // 45° rotation around Y-axis
|
|
29
|
+
* ```
|
|
26
30
|
*/
|
|
27
31
|
export function QuaternionRotationY(angle) {
|
|
28
32
|
return QuaternionFromAxisAngle([0, 1, 0], angle);
|
|
@@ -34,7 +38,9 @@ export function QuaternionRotationY(angle) {
|
|
|
34
38
|
* @returns Quaternion representing rotation around Z-axis
|
|
35
39
|
*
|
|
36
40
|
* @example
|
|
37
|
-
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const q = QuaternionRotationZ(Math.PI); // 180° rotation around Z-axis
|
|
43
|
+
* ```
|
|
38
44
|
*/
|
|
39
45
|
export function QuaternionRotationZ(angle) {
|
|
40
46
|
return QuaternionFromAxisAngle([0, 0, 1], angle);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predefined.js","sourceRoot":"","sources":["../../src/quaternions/predefined.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAEpD
|
|
1
|
+
{"version":3,"file":"predefined.js","sourceRoot":"","sources":["../../src/quaternions/predefined.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAChD,OAAO,uBAAuB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAChD,OAAO,uBAAuB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAChD,OAAO,uBAAuB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* avoiding gimbal lock and providing smooth interpolation capabilities.
|
|
5
5
|
*/
|
|
6
6
|
import { TVector3, TVector4 } from '../vectors/types.js';
|
|
7
|
-
import {
|
|
7
|
+
import { TMatrix3 } from '../matrices/types.js';
|
|
8
8
|
/**
|
|
9
9
|
* Quaternion type representing a rotation in 3D space as [x, y, z, w].
|
|
10
10
|
* The first three components (x, y, z) represent the vector part (rotation axis scaled by sin(θ/2)),
|
|
@@ -37,7 +37,7 @@ export type TEulerAngles = TVector3;
|
|
|
37
37
|
export type TAxisAngle = TVector4;
|
|
38
38
|
/**
|
|
39
39
|
* Rotation matrix representation as a 3x3 matrix.
|
|
40
|
-
* Uses the standard
|
|
40
|
+
* Uses the standard TMatrix3 type for better integration with matrix operations.
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
43
|
* const identity: IRotationMatrix = [
|
|
@@ -46,7 +46,7 @@ export type TAxisAngle = TVector4;
|
|
|
46
46
|
* [0, 0, 1] // Third row
|
|
47
47
|
* ];
|
|
48
48
|
*/
|
|
49
|
-
export type TRotationMatrix =
|
|
49
|
+
export type TRotationMatrix = TMatrix3;
|
|
50
50
|
/**
|
|
51
51
|
* Union type representing any supported rotation representation.
|
|
52
52
|
* Useful for functions that can accept multiple rotation formats.
|
package/build/random.d.ts
CHANGED
|
@@ -32,10 +32,11 @@ export declare function RandomFloat(min: number, max: number): number;
|
|
|
32
32
|
export declare function RandomChoice<T>(array: T[]): T | undefined;
|
|
33
33
|
/**
|
|
34
34
|
* Randomly selects multiple elements from an array without replacement.
|
|
35
|
+
* Uses a partial Fisher-Yates shuffle, running only `count` iterations for O(count) time.
|
|
35
36
|
* @template T - The type of elements in the array
|
|
36
37
|
* @param array - Array to choose from
|
|
37
38
|
* @param count - Number of elements to select
|
|
38
|
-
* @returns Array of randomly selected elements, or empty array if invalid
|
|
39
|
+
* @returns Array of `count` unique randomly selected elements, or empty array if inputs are invalid
|
|
39
40
|
* @example RandomSample([1, 2, 3, 4, 5], 3) // Returns 3 unique numbers
|
|
40
41
|
* @example RandomSample(['a', 'b', 'c'], 2) // Returns 2 unique letters
|
|
41
42
|
*/
|
|
@@ -54,13 +55,15 @@ export declare function RandomShuffle<T>(array: T[], clone?: boolean): T[];
|
|
|
54
55
|
* Generates a random boolean value.
|
|
55
56
|
* @param probability - Probability of returning true (0.0 to 1.0, default: 0.5)
|
|
56
57
|
* @returns Random boolean based on probability
|
|
58
|
+
* @throws {RangeError} If probability is outside the range [0, 1]
|
|
57
59
|
* @example RandomBool() // 50% chance of true
|
|
58
60
|
* @example RandomBool(0.8) // 80% chance of true
|
|
59
61
|
*/
|
|
60
62
|
export declare function RandomBool(probability?: number): boolean;
|
|
61
63
|
/**
|
|
62
64
|
* Generates a random number following a normal (Gaussian) distribution.
|
|
63
|
-
* Uses the Box-Muller transform
|
|
65
|
+
* Uses the Box-Muller transform. The first uniform sample u1 is resampled
|
|
66
|
+
* until it is ≥ `Number.EPSILON` to avoid `log(0) = -Infinity`.
|
|
64
67
|
* @param mean - Mean of the distribution (default: 0)
|
|
65
68
|
* @param standardDeviation - Standard deviation of the distribution (default: 1)
|
|
66
69
|
* @returns Random number from normal distribution
|
package/build/random.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAI1D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAI5D;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAKzD;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,CAc9D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,CAAC,EAAE,CAWjE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,GAAE,MAAY,GAAG,OAAO,CAI7D;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,MAAU,EAAE,iBAAiB,GAAE,MAAU,GAAG,MAAM,CAUpF"}
|
package/build/random.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const BOX_MULLER_COEFFICIENT = -2;
|
|
2
|
+
const BOX_MULLER_MIN_U1 = Number.EPSILON; // Avoid log(0) = -Infinity in Box-Muller transform
|
|
2
3
|
/**
|
|
3
4
|
* Generates a random integer within the specified range (inclusive).
|
|
4
5
|
* @param min - Minimum value (inclusive)
|
|
@@ -46,29 +47,26 @@ export function RandomChoice(array) {
|
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
49
|
* Randomly selects multiple elements from an array without replacement.
|
|
50
|
+
* Uses a partial Fisher-Yates shuffle, running only `count` iterations for O(count) time.
|
|
49
51
|
* @template T - The type of elements in the array
|
|
50
52
|
* @param array - Array to choose from
|
|
51
53
|
* @param count - Number of elements to select
|
|
52
|
-
* @returns Array of randomly selected elements, or empty array if invalid
|
|
54
|
+
* @returns Array of `count` unique randomly selected elements, or empty array if inputs are invalid
|
|
53
55
|
* @example RandomSample([1, 2, 3, 4, 5], 3) // Returns 3 unique numbers
|
|
54
56
|
* @example RandomSample(['a', 'b', 'c'], 2) // Returns 2 unique letters
|
|
55
57
|
*/
|
|
56
58
|
export function RandomSample(array, count) {
|
|
57
59
|
if (array.length === 0 || count <= 0 || count > array.length)
|
|
58
60
|
return [];
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (element !== undefined) {
|
|
67
|
-
result.push(element);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
61
|
+
// Partial Fisher-Yates shuffle: O(count) guaranteed, no collision retries
|
|
62
|
+
const copy = [...array];
|
|
63
|
+
for (let i = 0; i < count; i++) {
|
|
64
|
+
const j = RandomInt(i, copy.length - 1);
|
|
65
|
+
const temp = copy[i];
|
|
66
|
+
copy[i] = copy[j];
|
|
67
|
+
copy[j] = temp;
|
|
70
68
|
}
|
|
71
|
-
return
|
|
69
|
+
return copy.slice(0, count);
|
|
72
70
|
}
|
|
73
71
|
/**
|
|
74
72
|
* Shuffles an array using the Fisher-Yates algorithm.
|
|
@@ -93,17 +91,19 @@ export function RandomShuffle(array, clone) {
|
|
|
93
91
|
* Generates a random boolean value.
|
|
94
92
|
* @param probability - Probability of returning true (0.0 to 1.0, default: 0.5)
|
|
95
93
|
* @returns Random boolean based on probability
|
|
94
|
+
* @throws {RangeError} If probability is outside the range [0, 1]
|
|
96
95
|
* @example RandomBool() // 50% chance of true
|
|
97
96
|
* @example RandomBool(0.8) // 80% chance of true
|
|
98
97
|
*/
|
|
99
98
|
export function RandomBool(probability = 0.5) {
|
|
100
99
|
if (probability < 0 || probability > 1)
|
|
101
|
-
|
|
100
|
+
throw new RangeError(`Probability must be between 0 and 1, got ${probability}`);
|
|
102
101
|
return Math.random() < probability;
|
|
103
102
|
}
|
|
104
103
|
/**
|
|
105
104
|
* Generates a random number following a normal (Gaussian) distribution.
|
|
106
|
-
* Uses the Box-Muller transform
|
|
105
|
+
* Uses the Box-Muller transform. The first uniform sample u1 is resampled
|
|
106
|
+
* until it is ≥ `Number.EPSILON` to avoid `log(0) = -Infinity`.
|
|
107
107
|
* @param mean - Mean of the distribution (default: 0)
|
|
108
108
|
* @param standardDeviation - Standard deviation of the distribution (default: 1)
|
|
109
109
|
* @returns Random number from normal distribution
|
|
@@ -111,8 +111,11 @@ export function RandomBool(probability = 0.5) {
|
|
|
111
111
|
* @example RandomNormal(100, 15) // IQ-like distribution (mean=100, std=15)
|
|
112
112
|
*/
|
|
113
113
|
export function RandomNormal(mean = 0, standardDeviation = 1) {
|
|
114
|
-
// Box-Muller transform
|
|
115
|
-
|
|
114
|
+
// Box-Muller transform — u1 must be > 0 to avoid log(0) = -Infinity
|
|
115
|
+
let u1 = Math.random();
|
|
116
|
+
while (u1 < BOX_MULLER_MIN_U1) {
|
|
117
|
+
u1 = Math.random();
|
|
118
|
+
}
|
|
116
119
|
const u2 = Math.random();
|
|
117
120
|
const z0 = Math.sqrt(BOX_MULLER_COEFFICIENT * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
|
|
118
121
|
return (z0 * standardDeviation) + mean;
|
package/build/random.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.js","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAG,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAG,CAAC,CAAC,CAAC;AAClC,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAA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AAI,CAAC,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE,GAAG,iBAAiB,EAAE,CAAC;QAC/B,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IACpB,CAAC;IACD,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAEzB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACzF,OAAO,CAAC,EAAE,GAAG,iBAAiB,CAAC,GAAG,IAAI,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Namespace re-exports for vector utilities.
|
|
3
|
+
* Provides grouped access to vector operations through namespace aliases.
|
|
4
|
+
*/
|
|
5
|
+
export * as Types from './types.js';
|
|
6
|
+
export * as Core from './core.js';
|
|
7
|
+
export * as Asserts from './asserts.js';
|
|
8
|
+
export * as Interpolation from './interpolation.js';
|
|
9
|
+
export * as Predefined from './predefined.js';
|
|
10
|
+
//# sourceMappingURL=_exports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_exports.d.ts","sourceRoot":"","sources":["../../src/vectors/_exports.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Namespace re-exports for vector utilities.
|
|
3
|
+
* Provides grouped access to vector operations through namespace aliases.
|
|
4
|
+
*/
|
|
5
|
+
export * as Types from './types.js';
|
|
6
|
+
export * as Core from './core.js';
|
|
7
|
+
export * as Asserts from './asserts.js';
|
|
8
|
+
export * as Interpolation from './interpolation.js';
|
|
9
|
+
export * as Predefined from './predefined.js';
|
|
10
|
+
//# sourceMappingURL=_exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_exports.js","sourceRoot":"","sources":["../../src/vectors/_exports.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC"}
|
|
@@ -14,7 +14,7 @@ export type TAssertVectorArgs = IAssertNumberArgs & IAssertArrayArgs;
|
|
|
14
14
|
* Extended configuration for validating multiple vectors.
|
|
15
15
|
* Includes all single vector options plus multi-vector constraints.
|
|
16
16
|
*/
|
|
17
|
-
interface IAssertVectorsArgs extends TAssertVectorArgs {
|
|
17
|
+
export interface IAssertVectorsArgs extends TAssertVectorArgs {
|
|
18
18
|
/**
|
|
19
19
|
* Minimum vector size allowed.
|
|
20
20
|
* If specified, vectors must have at least this many components.
|
|
@@ -48,21 +48,28 @@ type TAssertVectorValueArgs = IAssertNumberArgs;
|
|
|
48
48
|
* Thrown when vector assertions fail or vector operations encounter invalid data.
|
|
49
49
|
*
|
|
50
50
|
* @example
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
* ```typescript
|
|
52
|
+
* try {
|
|
53
|
+
* AssertVector("not a vector");
|
|
54
|
+
* } catch (error) {
|
|
55
|
+
* if (error instanceof VectorError) {
|
|
56
|
+
* console.log("Vector validation failed:", error.message);
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
58
60
|
*/
|
|
59
61
|
export declare class VectorError extends Error {
|
|
62
|
+
readonly code: string;
|
|
60
63
|
/**
|
|
61
64
|
* Creates a new VectorError instance.
|
|
62
65
|
*
|
|
63
|
-
* @param message -
|
|
66
|
+
* @param message - Error message describing the validation failure
|
|
67
|
+
* @param options - Optional error context
|
|
68
|
+
* @param options.cause - Original error that caused this error
|
|
64
69
|
*/
|
|
65
|
-
constructor(message?:
|
|
70
|
+
constructor(message: string, options?: {
|
|
71
|
+
cause?: unknown;
|
|
72
|
+
});
|
|
66
73
|
}
|
|
67
74
|
/**
|
|
68
75
|
* Validates that an unknown value is a valid vector (array of numbers).
|
|
@@ -76,16 +83,16 @@ export declare class VectorError extends Error {
|
|
|
76
83
|
* @throws {VectorError} If the value is not a valid vector meeting all constraints
|
|
77
84
|
*
|
|
78
85
|
* @example
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
* ```typescript
|
|
87
|
+
* ```typescript
|
|
88
|
+
* // Basic validation — passes silently for a valid vector
|
|
89
|
+
* AssertVector([1, 2, 3]);
|
|
90
|
+
* // Validate with size constraint
|
|
91
|
+
* AssertVector([1, 2], { size: 2 });
|
|
92
|
+
* // Throws VectorError for non-array input
|
|
93
|
+
* AssertVector("not a vector"); // throws VectorError
|
|
94
|
+
* ```
|
|
95
|
+
* ```
|
|
89
96
|
*/
|
|
90
97
|
export declare function AssertVector(vector: unknown, args?: TAssertVectorArgs, exception?: IAssertVectorException): asserts vector is TVector;
|
|
91
98
|
/**
|
|
@@ -96,11 +103,13 @@ export declare function AssertVector(vector: unknown, args?: TAssertVectorArgs,
|
|
|
96
103
|
* @throws {VectorError} If the value is not a 2-component vector
|
|
97
104
|
*
|
|
98
105
|
* @example
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
* ```typescript
|
|
107
|
+
* ```typescript
|
|
108
|
+
* AssertVector2([1, 2]); // passes
|
|
109
|
+
* AssertVector2([1, 2, 3]); // throws — too many components
|
|
110
|
+
* AssertVector2("not a vec"); // throws
|
|
111
|
+
* ```
|
|
112
|
+
* ```
|
|
104
113
|
*/
|
|
105
114
|
export declare function AssertVector2(vector: unknown, exception?: IAssertVectorException): asserts vector is TVector2;
|
|
106
115
|
/**
|
|
@@ -111,11 +120,13 @@ export declare function AssertVector2(vector: unknown, exception?: IAssertVector
|
|
|
111
120
|
* @throws {VectorError} If the value is not a 3-component vector
|
|
112
121
|
*
|
|
113
122
|
* @example
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
* ```typescript
|
|
124
|
+
* ```typescript
|
|
125
|
+
* AssertVector3([1, 2, 3]); // passes
|
|
126
|
+
* AssertVector3([1, 2]); // throws — too few components
|
|
127
|
+
* AssertVector3(null); // throws
|
|
128
|
+
* ```
|
|
129
|
+
* ```
|
|
119
130
|
*/
|
|
120
131
|
export declare function AssertVector3(vector: unknown, exception?: IAssertVectorException): asserts vector is TVector3;
|
|
121
132
|
/**
|
|
@@ -126,11 +137,13 @@ export declare function AssertVector3(vector: unknown, exception?: IAssertVector
|
|
|
126
137
|
* @throws {VectorError} If the value is not a 4-component vector
|
|
127
138
|
*
|
|
128
139
|
* @example
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
* ```typescript
|
|
141
|
+
* ```typescript
|
|
142
|
+
* AssertVector4([1, 2, 3, 4]); // passes
|
|
143
|
+
* AssertVector4([1, 2, 3]); // throws — too few components
|
|
144
|
+
* AssertVector4(undefined); // throws
|
|
145
|
+
* ```
|
|
146
|
+
* ```
|
|
134
147
|
*/
|
|
135
148
|
export declare function AssertVector4(vector: unknown, exception?: IAssertVectorException): asserts vector is TVector4;
|
|
136
149
|
/**
|
|
@@ -145,13 +158,15 @@ export declare function AssertVector4(vector: unknown, exception?: IAssertVector
|
|
|
145
158
|
* @throws {VectorError} If the value is not a valid number or violates any constraint
|
|
146
159
|
*
|
|
147
160
|
* @example
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
161
|
+
* ```typescript
|
|
162
|
+
* ```typescript
|
|
163
|
+
* AssertVectorValue(3.14); // passes
|
|
164
|
+
* AssertVectorValue(3.14, { finite: true }); // passes
|
|
165
|
+
* AssertVectorValue(Infinity, { finite: true }); // throws
|
|
166
|
+
* AssertVectorValue(NaN); // throws
|
|
167
|
+
* AssertVectorValue(5, { gte: 0, lte: 10 }); // passes
|
|
168
|
+
* ```
|
|
169
|
+
* ```
|
|
155
170
|
*/
|
|
156
171
|
export declare function AssertVectorValue(value: unknown, args?: TAssertVectorValueArgs, exception?: IAssertVectorException): asserts value is number;
|
|
157
172
|
/**
|
|
@@ -165,18 +180,107 @@ export declare function AssertVectorValue(value: unknown, args?: TAssertVectorVa
|
|
|
165
180
|
* @throws {VectorError} If the array is empty, any vector is invalid, or sizes
|
|
166
181
|
* differ when `sameSize` is `true`
|
|
167
182
|
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* // Validate an array of 3D vectors
|
|
186
|
+
* AssertVectors([[1, 2, 3], [4, 5, 6]]);
|
|
187
|
+
* // Require all vectors to share the same length
|
|
188
|
+
* AssertVectors([[1, 2], [3, 4]], { sameSize: true });
|
|
189
|
+
* // Throws because vectors have different sizes
|
|
190
|
+
* AssertVectors([[1, 2], [1, 2, 3]], { sameSize: true }); // throws
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export declare function AssertVectors(vectors: unknown[], args?: IAssertVectorsArgs, exception?: IAssertVectorException): void;
|
|
194
|
+
/**
|
|
195
|
+
* Validates that an unknown value is a valid vector without throwing an error.
|
|
196
|
+
*
|
|
197
|
+
* This function performs the same validation as AssertVector but returns
|
|
198
|
+
* a boolean instead of throwing an exception, making it suitable for
|
|
199
|
+
* conditional logic where exceptions are not desired.
|
|
200
|
+
*
|
|
201
|
+
* @param vector - The value to validate as a vector
|
|
202
|
+
* @param args - Validation configuration options
|
|
203
|
+
* @returns true if the vector is valid, false otherwise
|
|
204
|
+
*
|
|
168
205
|
* @example
|
|
169
206
|
* ```typescript
|
|
170
|
-
*
|
|
171
|
-
*
|
|
207
|
+
* if (ValidateVector([1, 2, 3])) {
|
|
208
|
+
* // Process the valid vector
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export declare function ValidateVector(vector: unknown, args?: TAssertVectorArgs): vector is TVector;
|
|
213
|
+
/**
|
|
214
|
+
* Validates that an unknown value is a valid 2D vector without throwing an error.
|
|
172
215
|
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
216
|
+
* @param vector - The value to validate as a 2D vector
|
|
217
|
+
* @returns true if the vector is valid, false otherwise
|
|
175
218
|
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* if (ValidateVector2([1, 2])) {
|
|
222
|
+
* // Process the valid 2D vector
|
|
223
|
+
* }
|
|
178
224
|
* ```
|
|
179
225
|
*/
|
|
180
|
-
export declare function
|
|
226
|
+
export declare function ValidateVector2(vector: unknown): vector is TVector2;
|
|
227
|
+
/**
|
|
228
|
+
* Validates that an unknown value is a valid 3D vector without throwing an error.
|
|
229
|
+
*
|
|
230
|
+
* @param vector - The value to validate as a 3D vector
|
|
231
|
+
* @returns true if the vector is valid, false otherwise
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* if (ValidateVector3([1, 2, 3])) {
|
|
236
|
+
* // Process the valid 3D vector
|
|
237
|
+
* }
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
export declare function ValidateVector3(vector: unknown): vector is TVector3;
|
|
241
|
+
/**
|
|
242
|
+
* Validates that an unknown value is a valid 4D vector without throwing an error.
|
|
243
|
+
*
|
|
244
|
+
* @param vector - The value to validate as a 4D vector
|
|
245
|
+
* @returns true if the vector is valid, false otherwise
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* if (ValidateVector4([1, 2, 3, 4])) {
|
|
250
|
+
* // Process the valid 4D vector
|
|
251
|
+
* }
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
export declare function ValidateVector4(vector: unknown): vector is TVector4;
|
|
255
|
+
/**
|
|
256
|
+
* Validates that an unknown value is a valid vector element without throwing an error.
|
|
257
|
+
*
|
|
258
|
+
* @param value - The value to validate as a vector element
|
|
259
|
+
* @param args - Validation configuration options
|
|
260
|
+
* @returns true if the value is valid, false otherwise
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```typescript
|
|
264
|
+
* if (ValidateVectorValue(1.5)) {
|
|
265
|
+
* // Process the valid element
|
|
266
|
+
* }
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
export declare function ValidateVectorValue(value: unknown, args?: TAssertVectorValueArgs): value is number;
|
|
270
|
+
/**
|
|
271
|
+
* Validates that an unknown value is an array of valid vectors without throwing an error.
|
|
272
|
+
*
|
|
273
|
+
* @param vectors - The value to validate as an array of vectors
|
|
274
|
+
* @param args - Validation configuration options
|
|
275
|
+
* @returns true if all vectors are valid, false otherwise
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* if (ValidateVectors([v1, v2, v3])) {
|
|
280
|
+
* // Process the valid vector array
|
|
281
|
+
* }
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
export declare function ValidateVectors(vectors: unknown[], args?: IAssertVectorsArgs): boolean;
|
|
181
285
|
export {};
|
|
182
286
|
//# sourceMappingURL=asserts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asserts.d.ts","sourceRoot":"","sources":["../../src/vectors/asserts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAuC,MAAM,4BAA4B,CAAC;AACxI,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,gBAAgB,CAAC;AAErE;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"asserts.d.ts","sourceRoot":"","sources":["../../src/vectors/asserts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAuC,MAAM,4BAA4B,CAAC;AACxI,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,gBAAgB,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC5D;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AACD;;;GAGG;AACH,UAAU,sBAAuB,SAAQ,gBAAgB;IACxD;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AACD,KAAK,sBAAsB,GAAG,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAE,MAAM,CAAkB;IAE9C;;;;;;OAMG;gBACS,OAAO,EAAE,MAAM,EAAE,OAAO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