@pawells/math-extended 2.0.0 → 3.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 +15 -21
- package/build/clamp.d.ts +5 -5
- package/build/clamp.js +5 -5
- package/build/core.d.ts +23 -0
- package/build/core.d.ts.map +1 -0
- package/build/core.js +25 -0
- package/build/core.js.map +1 -0
- package/build/index.d.ts +1 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -6
- package/build/index.js.map +1 -1
- package/build/interpolation.d.ts +158 -171
- package/build/interpolation.d.ts.map +1 -1
- package/build/interpolation.js +162 -181
- package/build/interpolation.js.map +1 -1
- package/build/matrices/arithmetic.d.ts +132 -132
- package/build/matrices/arithmetic.d.ts.map +1 -1
- package/build/matrices/arithmetic.js +194 -226
- package/build/matrices/arithmetic.js.map +1 -1
- package/build/matrices/asserts.d.ts +30 -408
- package/build/matrices/asserts.d.ts.map +1 -1
- package/build/matrices/asserts.js +98 -542
- package/build/matrices/asserts.js.map +1 -1
- package/build/matrices/core.d.ts +117 -46
- package/build/matrices/core.d.ts.map +1 -1
- package/build/matrices/core.js +127 -103
- package/build/matrices/core.js.map +1 -1
- package/build/matrices/decompositions.d.ts +95 -96
- package/build/matrices/decompositions.d.ts.map +1 -1
- package/build/matrices/decompositions.js +119 -160
- package/build/matrices/decompositions.js.map +1 -1
- package/build/matrices/index.d.ts +0 -1
- package/build/matrices/index.d.ts.map +1 -1
- package/build/matrices/index.js +0 -3
- package/build/matrices/index.js.map +1 -1
- package/build/matrices/linear-algebra.d.ts +45 -8
- package/build/matrices/linear-algebra.d.ts.map +1 -1
- package/build/matrices/linear-algebra.js +76 -32
- package/build/matrices/linear-algebra.js.map +1 -1
- package/build/matrices/normalization.d.ts +29 -8
- package/build/matrices/normalization.d.ts.map +1 -1
- package/build/matrices/normalization.js +32 -23
- package/build/matrices/normalization.js.map +1 -1
- package/build/matrices/transformations.d.ts +116 -148
- package/build/matrices/transformations.d.ts.map +1 -1
- package/build/matrices/transformations.js +69 -91
- package/build/matrices/transformations.js.map +1 -1
- package/build/matrices/types.d.ts +32 -60
- package/build/matrices/types.d.ts.map +1 -1
- package/build/matrices/types.js +63 -1
- package/build/matrices/types.js.map +1 -1
- package/build/quaternions/asserts.d.ts +29 -38
- package/build/quaternions/asserts.d.ts.map +1 -1
- package/build/quaternions/asserts.js +61 -77
- package/build/quaternions/asserts.js.map +1 -1
- package/build/quaternions/conversions.d.ts +26 -26
- package/build/quaternions/conversions.d.ts.map +1 -1
- package/build/quaternions/conversions.js +24 -24
- package/build/quaternions/core.d.ts +70 -69
- package/build/quaternions/core.d.ts.map +1 -1
- package/build/quaternions/core.js +71 -71
- package/build/quaternions/core.js.map +1 -1
- package/build/quaternions/index.d.ts +0 -1
- package/build/quaternions/index.d.ts.map +1 -1
- package/build/quaternions/index.js +0 -2
- package/build/quaternions/index.js.map +1 -1
- package/build/quaternions/interpolation.d.ts +16 -16
- package/build/quaternions/interpolation.d.ts.map +1 -1
- package/build/quaternions/interpolation.js +21 -21
- package/build/quaternions/interpolation.js.map +1 -1
- package/build/quaternions/predefined.d.ts +10 -10
- package/build/quaternions/predefined.d.ts.map +1 -1
- package/build/quaternions/predefined.js +9 -9
- package/build/quaternions/types.d.ts +23 -12
- package/build/quaternions/types.d.ts.map +1 -1
- package/build/quaternions/types.js +51 -1
- package/build/quaternions/types.js.map +1 -1
- package/build/random.d.ts +66 -20
- package/build/random.d.ts.map +1 -1
- package/build/random.js +73 -20
- package/build/random.js.map +1 -1
- package/build/vectors/asserts.d.ts +50 -220
- package/build/vectors/asserts.d.ts.map +1 -1
- package/build/vectors/asserts.js +141 -327
- package/build/vectors/asserts.js.map +1 -1
- package/build/vectors/core.d.ts +182 -229
- package/build/vectors/core.d.ts.map +1 -1
- package/build/vectors/core.js +234 -288
- package/build/vectors/core.js.map +1 -1
- package/build/vectors/index.d.ts +0 -1
- package/build/vectors/index.d.ts.map +1 -1
- package/build/vectors/index.js +0 -2
- package/build/vectors/index.js.map +1 -1
- package/build/vectors/interpolation.d.ts +40 -40
- package/build/vectors/interpolation.d.ts.map +1 -1
- package/build/vectors/interpolation.js +75 -86
- package/build/vectors/interpolation.js.map +1 -1
- package/build/vectors/predefined.d.ts +31 -7
- package/build/vectors/predefined.d.ts.map +1 -1
- package/build/vectors/predefined.js +30 -6
- package/build/vectors/predefined.js.map +1 -1
- package/build/vectors/types.d.ts +26 -4
- package/build/vectors/types.d.ts.map +1 -1
- package/build/vectors/types.js +50 -1
- package/build/vectors/types.js.map +1 -1
- package/package.json +3 -2
- package/build/matrices/_exports.d.ts +0 -13
- package/build/matrices/_exports.d.ts.map +0 -1
- package/build/matrices/_exports.js +0 -13
- package/build/matrices/_exports.js.map +0 -1
- package/build/quaternions/_exports.d.ts +0 -11
- package/build/quaternions/_exports.d.ts.map +0 -1
- package/build/quaternions/_exports.js +0 -11
- package/build/quaternions/_exports.js.map +0 -1
- package/build/vectors/_exports.d.ts +0 -10
- package/build/vectors/_exports.d.ts.map +0 -1
- package/build/vectors/_exports.js +0 -10
- package/build/vectors/_exports.js.map +0 -1
|
@@ -2,25 +2,7 @@
|
|
|
2
2
|
* Assertion utilities for quaternion validation and error handling.
|
|
3
3
|
* Provides runtime type checking and validation for quaternion operations.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import { TQuaternion, TEulerAngles, TAxisAngle, TRotationMatrix } from './types.js';
|
|
7
|
-
/**
|
|
8
|
-
* Custom error class for quaternion-specific validation errors.
|
|
9
|
-
* Extends the base VectorError to maintain consistency with vector operations.
|
|
10
|
-
*/
|
|
11
|
-
export declare class QuaternionError extends VectorError {
|
|
12
|
-
readonly code: string;
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new QuaternionError instance.
|
|
15
|
-
*
|
|
16
|
-
* @param message - Error message describing the validation failure
|
|
17
|
-
* @param options - Optional error context
|
|
18
|
-
* @param options.cause - Original error that caused this error
|
|
19
|
-
*/
|
|
20
|
-
constructor(message: string, options?: {
|
|
21
|
-
cause?: unknown;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
5
|
+
import { type TQuaternion, type TEulerAngles, type TAxisAngle, type TRotationMatrix } from './types.js';
|
|
24
6
|
/**
|
|
25
7
|
* Validates that a value is a proper quaternion.
|
|
26
8
|
* A valid quaternion must be an array of exactly 4 finite numbers.
|
|
@@ -30,13 +12,22 @@ export declare class QuaternionError extends VectorError {
|
|
|
30
12
|
* @throws {QuaternionError} If the quaternion is invalid
|
|
31
13
|
*
|
|
32
14
|
* @example
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
15
|
+
* ```typescript
|
|
16
|
+
* AssertQuaternion([0, 0, 0, 1]); // Valid - passes silently
|
|
17
|
+
* AssertQuaternion([1, 2, 3]); // Throws QuaternionError - wrong length
|
|
18
|
+
* AssertQuaternion([1, 2, 3, NaN]); // Throws QuaternionError - contains NaN
|
|
19
|
+
* ```
|
|
38
20
|
*/
|
|
39
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Error thrown when quaternion validation fails.
|
|
23
|
+
*/
|
|
24
|
+
export declare class QuaternionError extends Error {
|
|
25
|
+
readonly code: string;
|
|
26
|
+
constructor(message: string, options?: {
|
|
27
|
+
cause?: unknown;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export declare function AssertQuaternion(quaternion: unknown): asserts quaternion is TQuaternion;
|
|
40
31
|
/**
|
|
41
32
|
* Validates that a quaternion is normalized (unit quaternion).
|
|
42
33
|
* A unit quaternion has a magnitude of 1 and represents a valid rotation.
|
|
@@ -46,10 +37,10 @@ export declare function AssertQuaternion(quaternion: unknown, options?: Record<s
|
|
|
46
37
|
* @throws {QuaternionError} If the quaternion is not normalized
|
|
47
38
|
*
|
|
48
39
|
* @example
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
* ```typescript
|
|
41
|
+
* AssertNormalizedQuaternion([0, 0, 0, 1]); // Valid unit quaternion
|
|
42
|
+
* AssertNormalizedQuaternion([1, 1, 1, 1]); // Throws - not normalized
|
|
43
|
+
* ```
|
|
53
44
|
*/
|
|
54
45
|
export declare function AssertNormalizedQuaternion(quaternion: TQuaternion, tolerance?: number): void;
|
|
55
46
|
/**
|
|
@@ -60,7 +51,7 @@ export declare function AssertNormalizedQuaternion(quaternion: TQuaternion, tole
|
|
|
60
51
|
* @param options - Validation options
|
|
61
52
|
* @throws {QuaternionError} If the Euler angles are invalid
|
|
62
53
|
*/
|
|
63
|
-
export declare function AssertEulerAngles(euler: unknown
|
|
54
|
+
export declare function AssertEulerAngles(euler: unknown): asserts euler is TEulerAngles;
|
|
64
55
|
/**
|
|
65
56
|
* Validates that a value is proper axis-angle representation.
|
|
66
57
|
* Axis-angle must be an array of exactly 4 finite numbers.
|
|
@@ -69,7 +60,7 @@ export declare function AssertEulerAngles(euler: unknown, options?: Record<strin
|
|
|
69
60
|
* @param options - Validation options
|
|
70
61
|
* @throws {QuaternionError} If the axis-angle is invalid
|
|
71
62
|
*/
|
|
72
|
-
export declare function AssertAxisAngle(axisAngle: unknown
|
|
63
|
+
export declare function AssertAxisAngle(axisAngle: unknown): asserts axisAngle is TAxisAngle;
|
|
73
64
|
/**
|
|
74
65
|
* Validates that a value is a proper rotation matrix.
|
|
75
66
|
* Rotation matrix must be a 3x3 matrix (TMatrix3).
|
|
@@ -78,7 +69,7 @@ export declare function AssertAxisAngle(axisAngle: unknown, options?: Record<str
|
|
|
78
69
|
* @param options - Validation options
|
|
79
70
|
* @throws {QuaternionError} If the rotation matrix is invalid
|
|
80
71
|
*/
|
|
81
|
-
export declare function AssertRotationMatrix(matrix: unknown
|
|
72
|
+
export declare function AssertRotationMatrix(matrix: unknown): asserts matrix is TRotationMatrix;
|
|
82
73
|
/**
|
|
83
74
|
* Validates that multiple quaternions are all valid.
|
|
84
75
|
* Convenience function for batch validation.
|
|
@@ -87,7 +78,7 @@ export declare function AssertRotationMatrix(matrix: unknown, options?: Record<s
|
|
|
87
78
|
* @param options - Validation options
|
|
88
79
|
* @throws {QuaternionError} If any quaternion is invalid
|
|
89
80
|
*/
|
|
90
|
-
export declare function AssertQuaternions(quaternions: unknown[]
|
|
81
|
+
export declare function AssertQuaternions(quaternions: unknown[]): asserts quaternions is TQuaternion[];
|
|
91
82
|
/**
|
|
92
83
|
* Validates that an unknown value is a valid quaternion without throwing an error.
|
|
93
84
|
*
|
|
@@ -106,7 +97,7 @@ export declare function AssertQuaternions(quaternions: unknown[], options?: Reco
|
|
|
106
97
|
* }
|
|
107
98
|
* ```
|
|
108
99
|
*/
|
|
109
|
-
export declare function ValidateQuaternion(quaternion: unknown
|
|
100
|
+
export declare function ValidateQuaternion(quaternion: unknown): quaternion is TQuaternion;
|
|
110
101
|
/**
|
|
111
102
|
* Validates that a quaternion is normalized (magnitude = 1) without throwing an error.
|
|
112
103
|
*
|
|
@@ -136,7 +127,7 @@ export declare function ValidateNormalizedQuaternion(quaternion: TQuaternion, to
|
|
|
136
127
|
* }
|
|
137
128
|
* ```
|
|
138
129
|
*/
|
|
139
|
-
export declare function ValidateEulerAngles(euler: unknown
|
|
130
|
+
export declare function ValidateEulerAngles(euler: unknown): euler is TEulerAngles;
|
|
140
131
|
/**
|
|
141
132
|
* Validates that an unknown value is a valid axis-angle representation without throwing an error.
|
|
142
133
|
*
|
|
@@ -151,7 +142,7 @@ export declare function ValidateEulerAngles(euler: unknown, options?: Record<str
|
|
|
151
142
|
* }
|
|
152
143
|
* ```
|
|
153
144
|
*/
|
|
154
|
-
export declare function ValidateAxisAngle(axisAngle: unknown
|
|
145
|
+
export declare function ValidateAxisAngle(axisAngle: unknown): axisAngle is TAxisAngle;
|
|
155
146
|
/**
|
|
156
147
|
* Validates that an unknown value is a valid rotation matrix without throwing an error.
|
|
157
148
|
*
|
|
@@ -166,7 +157,7 @@ export declare function ValidateAxisAngle(axisAngle: unknown, options?: Record<s
|
|
|
166
157
|
* }
|
|
167
158
|
* ```
|
|
168
159
|
*/
|
|
169
|
-
export declare function ValidateRotationMatrix(matrix: unknown
|
|
160
|
+
export declare function ValidateRotationMatrix(matrix: unknown): matrix is TRotationMatrix;
|
|
170
161
|
/**
|
|
171
162
|
* Validates that an unknown value is an array of valid quaternions without throwing an error.
|
|
172
163
|
*
|
|
@@ -181,5 +172,5 @@ export declare function ValidateRotationMatrix(matrix: unknown, options?: Record
|
|
|
181
172
|
* }
|
|
182
173
|
* ```
|
|
183
174
|
*/
|
|
184
|
-
export declare function ValidateQuaternions(quaternions: unknown[]
|
|
175
|
+
export declare function ValidateQuaternions(quaternions: unknown[]): quaternions is TQuaternion[];
|
|
185
176
|
//# sourceMappingURL=asserts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asserts.d.ts","sourceRoot":"","sources":["../../src/quaternions/asserts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"asserts.d.ts","sourceRoot":"","sources":["../../src/quaternions/asserts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAExG;;;;;;;;;;;;;;GAcG;AACH;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACzC,SAAgB,IAAI,EAAE,MAAM,CAAsB;gBAEtC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAO1D;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,IAAI,WAAW,CAcvF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,WAAW,EAAE,SAAS,GAAE,MAAa,GAAG,IAAI,CAclG;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,CAe/E;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,IAAI,UAAU,CAenF;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,IAAI,eAAe,CA0BvF;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,WAAW,IAAI,WAAW,EAAE,CAe9F;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,IAAI,WAAW,CAOjF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,WAAW,EAAE,SAAS,GAAE,MAAa,GAAG,OAAO,CAOvG;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAOzE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,IAAI,UAAU,CAO7E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,eAAe,CAOjF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,OAAO,EAAE,GAAG,WAAW,IAAI,WAAW,EAAE,CAOxF"}
|
|
@@ -2,25 +2,6 @@
|
|
|
2
2
|
* Assertion utilities for quaternion validation and error handling.
|
|
3
3
|
* Provides runtime type checking and validation for quaternion operations.
|
|
4
4
|
*/
|
|
5
|
-
import { AssertVector, VectorError } from '../vectors/asserts.js';
|
|
6
|
-
/**
|
|
7
|
-
* Custom error class for quaternion-specific validation errors.
|
|
8
|
-
* Extends the base VectorError to maintain consistency with vector operations.
|
|
9
|
-
*/
|
|
10
|
-
export class QuaternionError extends VectorError {
|
|
11
|
-
code = 'QUATERNION_ERROR';
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new QuaternionError instance.
|
|
14
|
-
*
|
|
15
|
-
* @param message - Error message describing the validation failure
|
|
16
|
-
* @param options - Optional error context
|
|
17
|
-
* @param options.cause - Original error that caused this error
|
|
18
|
-
*/
|
|
19
|
-
constructor(message, options) {
|
|
20
|
-
super(message, options);
|
|
21
|
-
this.name = 'QuaternionError';
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
5
|
/**
|
|
25
6
|
* Validates that a value is a proper quaternion.
|
|
26
7
|
* A valid quaternion must be an array of exactly 4 finite numbers.
|
|
@@ -30,28 +11,36 @@ export class QuaternionError extends VectorError {
|
|
|
30
11
|
* @throws {QuaternionError} If the quaternion is invalid
|
|
31
12
|
*
|
|
32
13
|
* @example
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
14
|
+
* ```typescript
|
|
15
|
+
* AssertQuaternion([0, 0, 0, 1]); // Valid - passes silently
|
|
16
|
+
* AssertQuaternion([1, 2, 3]); // Throws QuaternionError - wrong length
|
|
17
|
+
* AssertQuaternion([1, 2, 3, NaN]); // Throws QuaternionError - contains NaN
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when quaternion validation fails.
|
|
38
22
|
*/
|
|
39
|
-
export
|
|
23
|
+
export class QuaternionError extends Error {
|
|
24
|
+
code = 'QUATERNION_ERROR';
|
|
25
|
+
constructor(message, options) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = 'QuaternionError';
|
|
28
|
+
if (options?.cause) {
|
|
29
|
+
this.cause = options.cause;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function AssertQuaternion(quaternion) {
|
|
40
34
|
if (!Array.isArray(quaternion)) {
|
|
41
35
|
throw new QuaternionError('Quaternion must be an array');
|
|
42
36
|
}
|
|
43
37
|
if (quaternion.length !== 4) {
|
|
44
38
|
throw new QuaternionError(`Quaternion must have exactly 4 components, got ${quaternion.length}`);
|
|
45
39
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
if (error instanceof VectorError) {
|
|
52
|
-
throw new QuaternionError(error.message);
|
|
40
|
+
for (let i = 0; i < 4; i++) {
|
|
41
|
+
if (typeof quaternion[i] !== 'number' || Number.isNaN(quaternion[i])) {
|
|
42
|
+
throw new QuaternionError(`Quaternion component ${i} must be a number (not ${typeof quaternion[i]})`);
|
|
53
43
|
}
|
|
54
|
-
throw error;
|
|
55
44
|
}
|
|
56
45
|
}
|
|
57
46
|
/**
|
|
@@ -63,13 +52,17 @@ export function AssertQuaternion(quaternion, options = {}) {
|
|
|
63
52
|
* @throws {QuaternionError} If the quaternion is not normalized
|
|
64
53
|
*
|
|
65
54
|
* @example
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
* ```typescript
|
|
56
|
+
* AssertNormalizedQuaternion([0, 0, 0, 1]); // Valid unit quaternion
|
|
57
|
+
* AssertNormalizedQuaternion([1, 1, 1, 1]); // Throws - not normalized
|
|
58
|
+
* ```
|
|
70
59
|
*/
|
|
71
60
|
export function AssertNormalizedQuaternion(quaternion, tolerance = 1e-6) {
|
|
72
61
|
AssertQuaternion(quaternion);
|
|
62
|
+
// Type guard to establish type narrowing for TypeScript
|
|
63
|
+
if (!Array.isArray(quaternion) || quaternion.length !== 4) {
|
|
64
|
+
throw new QuaternionError('Quaternion must be an array of 4 numbers');
|
|
65
|
+
}
|
|
73
66
|
const [x, y, z, w] = quaternion;
|
|
74
67
|
const magnitude = Math.sqrt((x * x) + (y * y) + (z * z) + (w * w));
|
|
75
68
|
if (Math.abs(magnitude - 1) > tolerance) {
|
|
@@ -84,21 +77,18 @@ export function AssertNormalizedQuaternion(quaternion, tolerance = 1e-6) {
|
|
|
84
77
|
* @param options - Validation options
|
|
85
78
|
* @throws {QuaternionError} If the Euler angles are invalid
|
|
86
79
|
*/
|
|
87
|
-
export function AssertEulerAngles(euler
|
|
80
|
+
export function AssertEulerAngles(euler) {
|
|
88
81
|
if (!Array.isArray(euler)) {
|
|
89
82
|
throw new QuaternionError('Euler angles must be an array');
|
|
90
83
|
}
|
|
91
84
|
if (euler.length !== 3) {
|
|
92
85
|
throw new QuaternionError(`Euler angles must have exactly 3 components, got ${euler.length}`);
|
|
93
86
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (error instanceof VectorError) {
|
|
99
|
-
throw new QuaternionError(`Invalid Euler angles: ${error.message}`);
|
|
87
|
+
// Validate each element is a number (NaN is rejected, but Infinity is allowed)
|
|
88
|
+
for (let i = 0; i < 3; i++) {
|
|
89
|
+
if (typeof euler[i] !== 'number' || Number.isNaN(euler[i])) {
|
|
90
|
+
throw new QuaternionError(`Invalid Euler angles: component ${i} must be a number (not ${typeof euler[i]})`);
|
|
100
91
|
}
|
|
101
|
-
throw error;
|
|
102
92
|
}
|
|
103
93
|
}
|
|
104
94
|
/**
|
|
@@ -109,21 +99,18 @@ export function AssertEulerAngles(euler, options = {}) {
|
|
|
109
99
|
* @param options - Validation options
|
|
110
100
|
* @throws {QuaternionError} If the axis-angle is invalid
|
|
111
101
|
*/
|
|
112
|
-
export function AssertAxisAngle(axisAngle
|
|
102
|
+
export function AssertAxisAngle(axisAngle) {
|
|
113
103
|
if (!Array.isArray(axisAngle)) {
|
|
114
104
|
throw new QuaternionError('Axis-angle must be an array');
|
|
115
105
|
}
|
|
116
106
|
if (axisAngle.length !== 4) {
|
|
117
107
|
throw new QuaternionError(`Axis-angle must have exactly 4 components, got ${axisAngle.length}`);
|
|
118
108
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (error instanceof VectorError) {
|
|
124
|
-
throw new QuaternionError(`Invalid axis-angle: ${error.message}`);
|
|
109
|
+
// Validate each element is a number (NaN is rejected, but Infinity is allowed)
|
|
110
|
+
for (let i = 0; i < 4; i++) {
|
|
111
|
+
if (typeof axisAngle[i] !== 'number' || Number.isNaN(axisAngle[i])) {
|
|
112
|
+
throw new QuaternionError(`Invalid axis-angle: component ${i} must be a number (not ${typeof axisAngle[i]})`);
|
|
125
113
|
}
|
|
126
|
-
throw error;
|
|
127
114
|
}
|
|
128
115
|
}
|
|
129
116
|
/**
|
|
@@ -134,7 +121,7 @@ export function AssertAxisAngle(axisAngle, options = {}) {
|
|
|
134
121
|
* @param options - Validation options
|
|
135
122
|
* @throws {QuaternionError} If the rotation matrix is invalid
|
|
136
123
|
*/
|
|
137
|
-
export function AssertRotationMatrix(matrix
|
|
124
|
+
export function AssertRotationMatrix(matrix) {
|
|
138
125
|
if (!Array.isArray(matrix)) {
|
|
139
126
|
throw new QuaternionError('Rotation matrix must be an array');
|
|
140
127
|
}
|
|
@@ -149,14 +136,11 @@ export function AssertRotationMatrix(matrix, options = {}) {
|
|
|
149
136
|
if (matrix[i].length !== 3) {
|
|
150
137
|
throw new QuaternionError(`Rotation matrix row ${i} must have exactly 3 elements, got ${matrix[i].length}`);
|
|
151
138
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (error instanceof VectorError) {
|
|
157
|
-
throw new QuaternionError(`Invalid rotation matrix row ${i}: ${error.message}`);
|
|
139
|
+
// Validate each element is a number (NaN is rejected, but Infinity is allowed)
|
|
140
|
+
for (let j = 0; j < 3; j++) {
|
|
141
|
+
if (typeof matrix[i][j] !== 'number' || Number.isNaN(matrix[i][j])) {
|
|
142
|
+
throw new QuaternionError(`Invalid rotation matrix row ${i}: component ${j} must be a number (not ${typeof matrix[i][j]})`);
|
|
158
143
|
}
|
|
159
|
-
throw error;
|
|
160
144
|
}
|
|
161
145
|
}
|
|
162
146
|
}
|
|
@@ -168,19 +152,19 @@ export function AssertRotationMatrix(matrix, options = {}) {
|
|
|
168
152
|
* @param options - Validation options
|
|
169
153
|
* @throws {QuaternionError} If any quaternion is invalid
|
|
170
154
|
*/
|
|
171
|
-
export function AssertQuaternions(quaternions
|
|
155
|
+
export function AssertQuaternions(quaternions) {
|
|
172
156
|
if (!Array.isArray(quaternions)) {
|
|
173
157
|
throw new QuaternionError('Quaternions must be an array');
|
|
174
158
|
}
|
|
175
159
|
for (let i = 0; i < quaternions.length; i++) {
|
|
176
160
|
try {
|
|
177
|
-
AssertQuaternion(quaternions[i]
|
|
161
|
+
AssertQuaternion(quaternions[i]);
|
|
178
162
|
}
|
|
179
163
|
catch (error) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
164
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
165
|
+
throw new QuaternionError(`Invalid quaternion at index ${i}: ${message}`, {
|
|
166
|
+
cause: error instanceof Error ? error : undefined,
|
|
167
|
+
});
|
|
184
168
|
}
|
|
185
169
|
}
|
|
186
170
|
}
|
|
@@ -202,9 +186,9 @@ export function AssertQuaternions(quaternions, options = {}) {
|
|
|
202
186
|
* }
|
|
203
187
|
* ```
|
|
204
188
|
*/
|
|
205
|
-
export function ValidateQuaternion(quaternion
|
|
189
|
+
export function ValidateQuaternion(quaternion) {
|
|
206
190
|
try {
|
|
207
|
-
AssertQuaternion(quaternion
|
|
191
|
+
AssertQuaternion(quaternion);
|
|
208
192
|
return true;
|
|
209
193
|
}
|
|
210
194
|
catch {
|
|
@@ -248,9 +232,9 @@ export function ValidateNormalizedQuaternion(quaternion, tolerance = 1e-6) {
|
|
|
248
232
|
* }
|
|
249
233
|
* ```
|
|
250
234
|
*/
|
|
251
|
-
export function ValidateEulerAngles(euler
|
|
235
|
+
export function ValidateEulerAngles(euler) {
|
|
252
236
|
try {
|
|
253
|
-
AssertEulerAngles(euler
|
|
237
|
+
AssertEulerAngles(euler);
|
|
254
238
|
return true;
|
|
255
239
|
}
|
|
256
240
|
catch {
|
|
@@ -271,9 +255,9 @@ export function ValidateEulerAngles(euler, options = {}) {
|
|
|
271
255
|
* }
|
|
272
256
|
* ```
|
|
273
257
|
*/
|
|
274
|
-
export function ValidateAxisAngle(axisAngle
|
|
258
|
+
export function ValidateAxisAngle(axisAngle) {
|
|
275
259
|
try {
|
|
276
|
-
AssertAxisAngle(axisAngle
|
|
260
|
+
AssertAxisAngle(axisAngle);
|
|
277
261
|
return true;
|
|
278
262
|
}
|
|
279
263
|
catch {
|
|
@@ -294,9 +278,9 @@ export function ValidateAxisAngle(axisAngle, options = {}) {
|
|
|
294
278
|
* }
|
|
295
279
|
* ```
|
|
296
280
|
*/
|
|
297
|
-
export function ValidateRotationMatrix(matrix
|
|
281
|
+
export function ValidateRotationMatrix(matrix) {
|
|
298
282
|
try {
|
|
299
|
-
AssertRotationMatrix(matrix
|
|
283
|
+
AssertRotationMatrix(matrix);
|
|
300
284
|
return true;
|
|
301
285
|
}
|
|
302
286
|
catch {
|
|
@@ -317,9 +301,9 @@ export function ValidateRotationMatrix(matrix, options = {}) {
|
|
|
317
301
|
* }
|
|
318
302
|
* ```
|
|
319
303
|
*/
|
|
320
|
-
export function ValidateQuaternions(quaternions
|
|
304
|
+
export function ValidateQuaternions(quaternions) {
|
|
321
305
|
try {
|
|
322
|
-
AssertQuaternions(quaternions
|
|
306
|
+
AssertQuaternions(quaternions);
|
|
323
307
|
return true;
|
|
324
308
|
}
|
|
325
309
|
catch {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asserts.js","sourceRoot":"","sources":["../../src/quaternions/asserts.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"asserts.js","sourceRoot":"","sources":["../../src/quaternions/asserts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;;;;;GAcG;AACH;;GAEG;AACH,M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AM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAsB;IACzD,IAAI,CAAC;QACJ,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Conversion utilities for quaternions and various rotation representations.
|
|
3
3
|
* Provides comprehensive conversion between different rotation formats.
|
|
4
4
|
*/
|
|
5
|
-
import { TMatrix4 } from '../matrices/types.js';
|
|
6
|
-
import { TQuaternion, TRotationMatrix } from './types.js';
|
|
5
|
+
import type { TMatrix4 } from '../matrices/types.js';
|
|
6
|
+
import type { TQuaternion, TRotationMatrix } from './types.js';
|
|
7
7
|
/**
|
|
8
8
|
* Converts a quaternion to a 3x3 rotation matrix.
|
|
9
9
|
* The matrix is returned as a proper TMatrix3 type.
|
|
@@ -12,11 +12,11 @@ import { TQuaternion, TRotationMatrix } from './types.js';
|
|
|
12
12
|
* @returns 3x3 rotation matrix as TMatrix3
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const q = [0, 0, 0.707, 0.707]; // 90° rotation around Z-axis
|
|
17
|
+
* const matrix = QuaternionToRotationMatrix(q);
|
|
18
|
+
* // matrix represents rotation that transforms +X to +Y
|
|
19
|
+
* ```
|
|
20
20
|
*/
|
|
21
21
|
export declare function QuaternionToRotationMatrix(quaternion: TQuaternion): TRotationMatrix;
|
|
22
22
|
/**
|
|
@@ -27,11 +27,11 @@ export declare function QuaternionToRotationMatrix(quaternion: TQuaternion): TRo
|
|
|
27
27
|
* @returns Normalized quaternion representing the same rotation
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const identityMatrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
|
|
32
|
+
* const q = QuaternionFromRotationMatrix(identityMatrix);
|
|
33
|
+
* console.log(q); // [0, 0, 0, 1] (identity quaternion)
|
|
34
|
+
* ```
|
|
35
35
|
*/
|
|
36
36
|
export declare function QuaternionFromRotationMatrix(matrix: TRotationMatrix): TQuaternion;
|
|
37
37
|
/**
|
|
@@ -43,11 +43,11 @@ export declare function QuaternionFromRotationMatrix(matrix: TRotationMatrix): T
|
|
|
43
43
|
* @returns 4x4 transformation matrix as a flat array of 16 elements (row-major)
|
|
44
44
|
*
|
|
45
45
|
* @example
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const q = [0, 0, 0, 1]; // Identity quaternion
|
|
48
|
+
* const matrix4x4 = QuaternionToTransformationMatrix(q);
|
|
49
|
+
* // Returns identity 4x4 matrix
|
|
50
|
+
* ```
|
|
51
51
|
*/
|
|
52
52
|
export declare function QuaternionToTransformationMatrix(quaternion: TQuaternion): TMatrix4;
|
|
53
53
|
/**
|
|
@@ -58,11 +58,11 @@ export declare function QuaternionToTransformationMatrix(quaternion: TQuaternion
|
|
|
58
58
|
* @returns Normalized quaternion representing the rotation component
|
|
59
59
|
*
|
|
60
60
|
* @example
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const transformMatrix = [1, 0, 0, 5, 0, 1, 0, 10, 0, 0, 1, 15, 0, 0, 0, 1];
|
|
63
|
+
* const q = QuaternionFromTransformationMatrix(transformMatrix);
|
|
64
|
+
* // Extracts rotation (identity in this case), ignores translation [5, 10, 15]
|
|
65
|
+
* ```
|
|
66
66
|
*/
|
|
67
67
|
export declare function QuaternionFromTransformationMatrix(matrix: TMatrix4): TQuaternion;
|
|
68
68
|
/**
|
|
@@ -74,10 +74,10 @@ export declare function QuaternionFromTransformationMatrix(matrix: TMatrix4): TQ
|
|
|
74
74
|
* @returns True if the matrix is a valid rotation matrix
|
|
75
75
|
*
|
|
76
76
|
* @example
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const matrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; // Identity matrix
|
|
79
|
+
* console.log(IsValidRotationMatrix(matrix)); // true
|
|
80
|
+
* ```
|
|
81
81
|
*/
|
|
82
82
|
export declare function IsValidRotationMatrix(matrix: TRotationMatrix, tolerance?: number): boolean;
|
|
83
83
|
//# sourceMappingURL=conversions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversions.d.ts","sourceRoot":"","sources":["../../src/quaternions/conversions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"conversions.d.ts","sourceRoot":"","sources":["../../src/quaternions/conversions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI/D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,WAAW,GAAG,eAAe,CAmBnF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,eAAe,GAAG,WAAW,CAyCjF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gCAAgC,CAAC,UAAU,EAAE,WAAW,GAAG,QAAQ,CAUlF;AACD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,QAAQ,GAAG,WAAW,CAShF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,EAAE,SAAS,GAAE,MAAa,GAAG,OAAO,CAkChG"}
|
|
@@ -12,11 +12,11 @@ const SHEPPERD_QUARTER = 0.25;
|
|
|
12
12
|
* @returns 3x3 rotation matrix as TMatrix3
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const q = [0, 0, 0.707, 0.707]; // 90° rotation around Z-axis
|
|
17
|
+
* const matrix = QuaternionToRotationMatrix(q);
|
|
18
|
+
* // matrix represents rotation that transforms +X to +Y
|
|
19
|
+
* ```
|
|
20
20
|
*/
|
|
21
21
|
export function QuaternionToRotationMatrix(quaternion) {
|
|
22
22
|
AssertNormalizedQuaternion(quaternion);
|
|
@@ -44,11 +44,11 @@ export function QuaternionToRotationMatrix(quaternion) {
|
|
|
44
44
|
* @returns Normalized quaternion representing the same rotation
|
|
45
45
|
*
|
|
46
46
|
* @example
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const identityMatrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
|
|
49
|
+
* const q = QuaternionFromRotationMatrix(identityMatrix);
|
|
50
|
+
* console.log(q); // [0, 0, 0, 1] (identity quaternion)
|
|
51
|
+
* ```
|
|
52
52
|
*/
|
|
53
53
|
export function QuaternionFromRotationMatrix(matrix) {
|
|
54
54
|
AssertRotationMatrix(matrix);
|
|
@@ -101,11 +101,11 @@ export function QuaternionFromRotationMatrix(matrix) {
|
|
|
101
101
|
* @returns 4x4 transformation matrix as a flat array of 16 elements (row-major)
|
|
102
102
|
*
|
|
103
103
|
* @example
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const q = [0, 0, 0, 1]; // Identity quaternion
|
|
106
|
+
* const matrix4x4 = QuaternionToTransformationMatrix(q);
|
|
107
|
+
* // Returns identity 4x4 matrix
|
|
108
|
+
* ```
|
|
109
109
|
*/
|
|
110
110
|
export function QuaternionToTransformationMatrix(quaternion) {
|
|
111
111
|
const rotationMatrix = QuaternionToRotationMatrix(quaternion);
|
|
@@ -125,11 +125,11 @@ export function QuaternionToTransformationMatrix(quaternion) {
|
|
|
125
125
|
* @returns Normalized quaternion representing the rotation component
|
|
126
126
|
*
|
|
127
127
|
* @example
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const transformMatrix = [1, 0, 0, 5, 0, 1, 0, 10, 0, 0, 1, 15, 0, 0, 0, 1];
|
|
130
|
+
* const q = QuaternionFromTransformationMatrix(transformMatrix);
|
|
131
|
+
* // Extracts rotation (identity in this case), ignores translation [5, 10, 15]
|
|
132
|
+
* ```
|
|
133
133
|
*/
|
|
134
134
|
export function QuaternionFromTransformationMatrix(matrix) {
|
|
135
135
|
// Extract 3x3 rotation matrix from 4x4 transformation matrix
|
|
@@ -149,10 +149,10 @@ export function QuaternionFromTransformationMatrix(matrix) {
|
|
|
149
149
|
* @returns True if the matrix is a valid rotation matrix
|
|
150
150
|
*
|
|
151
151
|
* @example
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const matrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; // Identity matrix
|
|
154
|
+
* console.log(IsValidRotationMatrix(matrix)); // true
|
|
155
|
+
* ```
|
|
156
156
|
*/
|
|
157
157
|
export function IsValidRotationMatrix(matrix, tolerance = 1e-6) {
|
|
158
158
|
AssertRotationMatrix(matrix);
|