rhodonite 0.19.10 → 0.20.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.
Files changed (65) hide show
  1. package/README.md +32 -2
  2. package/VERSION-FILE +1 -1
  3. package/dist/esm/foundation/components/Skeletal/SkeletalComponent.d.ts +138 -45
  4. package/dist/esm/foundation/core/Component.d.ts +63 -3
  5. package/dist/esm/foundation/core/ComponentMemoryRegistry.d.ts +59 -1
  6. package/dist/esm/foundation/core/Config.d.ts +8 -7
  7. package/dist/esm/foundation/definitions/BoneDataType.d.ts +12 -1
  8. package/dist/esm/foundation/importer/BoneDataTypeDetector.d.ts +31 -0
  9. package/dist/esm/foundation/importer/index.d.ts +1 -0
  10. package/dist/esm/foundation/math/AbstractMatrix.d.ts +3 -2
  11. package/dist/esm/foundation/math/AbstractQuaternion.d.ts +2 -1
  12. package/dist/esm/foundation/math/IMatrix.d.ts +2 -2
  13. package/dist/esm/foundation/math/IQuaternion.d.ts +4 -4
  14. package/dist/esm/foundation/math/LogQuaternion.d.ts +110 -38
  15. package/dist/esm/foundation/math/MathUtil.d.ts +55 -0
  16. package/dist/esm/foundation/math/Matrix22.d.ts +176 -30
  17. package/dist/esm/foundation/math/Matrix33.d.ts +206 -38
  18. package/dist/esm/foundation/math/Matrix44.d.ts +222 -39
  19. package/dist/esm/foundation/math/MutableMatrix22.d.ts +125 -130
  20. package/dist/esm/foundation/math/MutableMatrix33.d.ts +148 -162
  21. package/dist/esm/foundation/math/MutableMatrix44.d.ts +159 -183
  22. package/dist/esm/foundation/math/MutableQuaternion.d.ts +241 -132
  23. package/dist/esm/foundation/math/MutableScalar.d.ts +11 -12
  24. package/dist/esm/foundation/math/MutableVector2.d.ts +30 -31
  25. package/dist/esm/foundation/math/MutableVector3.d.ts +28 -26
  26. package/dist/esm/foundation/math/MutableVector4.d.ts +37 -37
  27. package/dist/esm/foundation/math/Quaternion.d.ts +529 -36
  28. package/dist/esm/foundation/math/Scalar.d.ts +13 -14
  29. package/dist/esm/foundation/math/Vector2.d.ts +38 -38
  30. package/dist/esm/foundation/math/Vector3.d.ts +55 -54
  31. package/dist/esm/foundation/math/Vector4.d.ts +54 -55
  32. package/dist/esm/index.js +691 -686
  33. package/dist/esm/types/glTF2.d.ts +7 -0
  34. package/dist/esmdev/foundation/components/Skeletal/SkeletalComponent.d.ts +138 -45
  35. package/dist/esmdev/foundation/core/Component.d.ts +63 -3
  36. package/dist/esmdev/foundation/core/ComponentMemoryRegistry.d.ts +59 -1
  37. package/dist/esmdev/foundation/core/Config.d.ts +8 -7
  38. package/dist/esmdev/foundation/definitions/BoneDataType.d.ts +12 -1
  39. package/dist/esmdev/foundation/importer/BoneDataTypeDetector.d.ts +31 -0
  40. package/dist/esmdev/foundation/importer/index.d.ts +1 -0
  41. package/dist/esmdev/foundation/math/AbstractMatrix.d.ts +3 -2
  42. package/dist/esmdev/foundation/math/AbstractQuaternion.d.ts +2 -1
  43. package/dist/esmdev/foundation/math/IMatrix.d.ts +2 -2
  44. package/dist/esmdev/foundation/math/IQuaternion.d.ts +4 -4
  45. package/dist/esmdev/foundation/math/LogQuaternion.d.ts +110 -38
  46. package/dist/esmdev/foundation/math/MathUtil.d.ts +55 -0
  47. package/dist/esmdev/foundation/math/Matrix22.d.ts +176 -30
  48. package/dist/esmdev/foundation/math/Matrix33.d.ts +206 -38
  49. package/dist/esmdev/foundation/math/Matrix44.d.ts +222 -39
  50. package/dist/esmdev/foundation/math/MutableMatrix22.d.ts +125 -130
  51. package/dist/esmdev/foundation/math/MutableMatrix33.d.ts +148 -162
  52. package/dist/esmdev/foundation/math/MutableMatrix44.d.ts +159 -183
  53. package/dist/esmdev/foundation/math/MutableQuaternion.d.ts +241 -132
  54. package/dist/esmdev/foundation/math/MutableScalar.d.ts +11 -12
  55. package/dist/esmdev/foundation/math/MutableVector2.d.ts +30 -31
  56. package/dist/esmdev/foundation/math/MutableVector3.d.ts +28 -26
  57. package/dist/esmdev/foundation/math/MutableVector4.d.ts +37 -37
  58. package/dist/esmdev/foundation/math/Quaternion.d.ts +529 -36
  59. package/dist/esmdev/foundation/math/Scalar.d.ts +13 -14
  60. package/dist/esmdev/foundation/math/Vector2.d.ts +38 -38
  61. package/dist/esmdev/foundation/math/Vector3.d.ts +55 -54
  62. package/dist/esmdev/foundation/math/Vector4.d.ts +54 -55
  63. package/dist/esmdev/index.js +4994 -2723
  64. package/dist/esmdev/types/glTF2.d.ts +7 -0
  65. package/package.json +12 -10
@@ -6,8 +6,8 @@ import type { IMutableVector2, IMutableVector3, IMutableVector4, IVector, IVecto
6
6
  * Provides read-only access to matrix data and basic mathematical operations.
7
7
  */
8
8
  export interface IMatrix {
9
- /** Internal typed array storing matrix data in column-major order */
10
- _v: Float32Array;
9
+ /** Internal typed array storing matrix data in column-major order (Float32Array or Float64Array) */
10
+ _v: TypedArray;
11
11
  /** Returns the class name of the matrix implementation */
12
12
  readonly className: string;
13
13
  /**
@@ -10,8 +10,8 @@ import type { Vector3 } from './Vector3';
10
10
  export interface IQuaternion {
11
11
  /** The class name identifier */
12
12
  readonly className: string;
13
- /** Internal Float32Array storage for quaternion components */
14
- _v: Float32Array;
13
+ /** Internal typed array storage for quaternion components (Float32Array or Float64Array) */
14
+ _v: TypedArray;
15
15
  /** The x component (i quaternion basis) */
16
16
  readonly x: number;
17
17
  /** The y component (j quaternion basis) */
@@ -287,8 +287,8 @@ export interface IMutableQuaternion extends IQuaternion {
287
287
  export interface ILogQuaternion {
288
288
  /** The class name identifier */
289
289
  readonly className: string;
290
- /** Internal Float32Array storage for logarithmic quaternion components */
291
- readonly _v: Float32Array;
290
+ /** Internal typed array storage for logarithmic quaternion components (Float32Array or Float64Array) */
291
+ readonly _v: TypedArray;
292
292
  /** The x component of the logarithmic quaternion */
293
293
  readonly x: number;
294
294
  /** The y component of the logarithmic quaternion */
@@ -1,19 +1,26 @@
1
- import type { Array3 } from '../../types/CommonTypes';
1
+ import type { Array3, FloatTypedArrayConstructor, TypedArray } from '../../types/CommonTypes';
2
2
  import type { ILogQuaternion, IQuaternion } from './IQuaternion';
3
3
  import type { IVector3 } from './IVector';
4
- import { Quaternion } from './Quaternion';
5
4
  /**
6
- * Represents a logarithm of a quaternion, which provides a more compact representation
7
- * for quaternion interpolation and mathematical operations. A log quaternion stores
8
- * only the x, y, z components as the w component is implicitly 1.
5
+ * Generic base class for logarithms of quaternions.
6
+ *
7
+ * A log quaternion provides a more compact representation for quaternion
8
+ * interpolation and mathematical operations. It stores only the x, y, z
9
+ * components, as the w component is implicitly 1.
10
+ *
11
+ * @template T - The typed array constructor (Float32Array or Float64Array)
12
+ * @internal
9
13
  */
10
- export declare class LogQuaternion implements ILogQuaternion {
11
- _v: Float32Array;
14
+ export declare class LogQuaternion_<T extends FloatTypedArrayConstructor> implements ILogQuaternion {
15
+ _v: TypedArray;
12
16
  /**
13
- * Creates a new LogQuaternion instance.
14
- * @param x - Float32Array containing the x, y, z components
17
+ * Creates a new LogQuaternion_ instance.
18
+ * @param v - Typed array containing the x, y, z components
19
+ * @param _options - Configuration object containing the typed array constructor
15
20
  */
16
- constructor(x: Float32Array);
21
+ constructor(v: TypedArray, _options: {
22
+ type: T;
23
+ });
17
24
  /**
18
25
  * Gets the x component of the log quaternion.
19
26
  * @returns The x component value
@@ -35,53 +42,118 @@ export declare class LogQuaternion implements ILogQuaternion {
35
42
  */
36
43
  get w(): number;
37
44
  /**
38
- * Creates a LogQuaternion from an existing Float32Array.
39
- * @param array - Float32Array containing the x, y, z components
40
- * @returns A new LogQuaternion instance
45
+ * Gets the class name identifier.
46
+ * @returns The string 'LogQuaternion'
41
47
  */
42
- static fromFloat32Array(array: Float32Array): LogQuaternion;
48
+ get className(): string;
43
49
  /**
44
- * Creates a LogQuaternion from a 3-element array by copying the values.
50
+ * Creates a log quaternion that directly uses the given typed array (no copy).
51
+ * @param array - Typed array containing the x, y, z components
52
+ * @param type - The typed array constructor to use
53
+ * @returns A new log quaternion
54
+ */
55
+ static _fromTypedArray(array: TypedArray, type: FloatTypedArrayConstructor): ILogQuaternion;
56
+ /**
57
+ * Creates a log quaternion from a 3-element array by copying the values.
45
58
  * @param array - Array of 3 numbers representing x, y, z components
46
- * @returns A new Quaternion instance (note: this should return LogQuaternion)
59
+ * @param type - The typed array constructor to use
60
+ * @returns A new log quaternion
47
61
  */
48
- static fromCopyArray3(array: Array3<number>): Quaternion;
62
+ static _fromCopyArray3(array: Array3<number>, type: FloatTypedArrayConstructor): ILogQuaternion;
49
63
  /**
50
- * Creates a LogQuaternion from an array by copying the first 3 values.
64
+ * Creates a log quaternion from an array by copying the first 3 values.
51
65
  * @param array - Array of numbers (only first 3 elements are used)
52
- * @returns A new Quaternion instance (note: this should return LogQuaternion)
66
+ * @param type - The typed array constructor to use
67
+ * @returns A new log quaternion
53
68
  */
54
- static fromCopyArray(array: Array<number>): Quaternion;
69
+ static _fromCopyArray(array: Array<number>, type: FloatTypedArrayConstructor): ILogQuaternion;
55
70
  /**
56
- * Creates a LogQuaternion from individual x, y, z component values.
71
+ * Creates a log quaternion from individual x, y, z component values.
57
72
  * @param x - The x component
58
73
  * @param y - The y component
59
74
  * @param z - The z component
60
- * @returns A new Quaternion instance (note: this should return LogQuaternion)
75
+ * @param type - The typed array constructor to use
76
+ * @returns A new log quaternion
61
77
  */
62
- static fromCopy3(x: number, y: number, z: number): Quaternion;
78
+ static _fromCopy3(x: number, y: number, z: number, type: FloatTypedArrayConstructor): ILogQuaternion;
63
79
  /**
64
- * Creates a LogQuaternion by copying from another LogQuaternion.
65
- * @param quat - The source LogQuaternion to copy from
66
- * @returns A new Quaternion instance (note: this should return LogQuaternion)
80
+ * Creates a log quaternion from a 3D vector by copying its components.
81
+ * @param vec - The source vector to copy from
82
+ * @param type - The typed array constructor to use
83
+ * @returns A new log quaternion
67
84
  */
68
- static fromCopyLogQuaternion(quat: ILogQuaternion): Quaternion;
85
+ static _fromCopyVector3(vec: IVector3, type: FloatTypedArrayConstructor): ILogQuaternion;
69
86
  /**
70
- * Creates a LogQuaternion from a 3D vector by copying its components.
71
- * @param vec - The source IVector3 to copy from
72
- * @returns A new Quaternion instance (note: this should return LogQuaternion)
87
+ * Creates a log quaternion by copying from another log quaternion.
88
+ * @param quat - The source log quaternion to copy from
89
+ * @param type - The typed array constructor to use
90
+ * @returns A new log quaternion
73
91
  */
74
- static fromCopyVector4(vec: IVector3): Quaternion;
92
+ static _fromCopyLogQuaternion(quat: ILogQuaternion, type: FloatTypedArrayConstructor): ILogQuaternion;
75
93
  /**
76
94
  * Converts a regular quaternion to its logarithmic form.
77
- * Uses the formula: log(q) = (θ/sin(θ)) * (x, y, z) where θ = acos(w)
78
- * @param x - The source quaternion to convert
79
- * @returns A new LogQuaternion representing the logarithm of the input quaternion
95
+ *
96
+ * Uses the formula `log(q) = (θ / sin(θ)) * (x, y, z)` where `θ = acos(w)`.
97
+ * When θ is 0 (identity rotation) the result is a zero log quaternion. When
98
+ * θ is close to π the logarithm is not representable and a zero log
99
+ * quaternion is returned instead of `Infinity`/`NaN`.
100
+ *
101
+ * @param quat - The source quaternion to convert
102
+ * @param type - The typed array constructor to use
103
+ * @returns A new log quaternion representing the logarithm of the input quaternion
80
104
  */
81
- static fromCopyQuaternion(x: IQuaternion): LogQuaternion;
105
+ static _fromCopyQuaternion(quat: IQuaternion, type: FloatTypedArrayConstructor): ILogQuaternion;
106
+ }
107
+ /**
108
+ * Logarithm of a quaternion with 32-bit float components.
109
+ */
110
+ export declare class LogQuaternion extends LogQuaternion_<Float32ArrayConstructor> {
82
111
  /**
83
- * Gets the class name identifier.
84
- * @returns The string 'LogQuaternion'
112
+ * Creates a new LogQuaternion instance.
113
+ * @param v - The typed array containing the x, y, z components
85
114
  */
86
- get className(): string;
115
+ constructor(v: TypedArray);
116
+ /** Creates a log quaternion that directly uses the given Float32Array (no copy). */
117
+ static fromFloat32Array(array: Float32Array): LogQuaternion;
118
+ /** Creates a log quaternion from a 3-element array by copying the values. */
119
+ static fromCopyArray3(array: Array3<number>): LogQuaternion;
120
+ /** Creates a log quaternion from an array by copying the first 3 values. */
121
+ static fromCopyArray(array: Array<number>): LogQuaternion;
122
+ /** Creates a log quaternion from individual x, y, z component values. */
123
+ static fromCopy3(x: number, y: number, z: number): LogQuaternion;
124
+ /** Creates a log quaternion from a 3D vector by copying its components. */
125
+ static fromCopyVector3(vec: IVector3): LogQuaternion;
126
+ /** Creates a log quaternion by copying from another log quaternion. */
127
+ static fromCopyLogQuaternion(quat: ILogQuaternion): LogQuaternion;
128
+ /** Converts a regular quaternion to its logarithmic form. */
129
+ static fromCopyQuaternion(quat: IQuaternion): LogQuaternion;
87
130
  }
131
+ /**
132
+ * Logarithm of a quaternion with 64-bit float components.
133
+ * Use this implementation when higher numerical precision is required.
134
+ */
135
+ export declare class LogQuaternionD extends LogQuaternion_<Float64ArrayConstructor> {
136
+ /**
137
+ * Creates a new LogQuaternionD instance.
138
+ * @param v - The typed array containing the x, y, z components
139
+ */
140
+ constructor(v: TypedArray);
141
+ /** Creates a log quaternion that directly uses the given Float64Array (no copy). */
142
+ static fromFloat64Array(array: Float64Array): LogQuaternionD;
143
+ /** Creates a log quaternion from a 3-element array by copying the values. */
144
+ static fromCopyArray3(array: Array3<number>): LogQuaternionD;
145
+ /** Creates a log quaternion from an array by copying the first 3 values. */
146
+ static fromCopyArray(array: Array<number>): LogQuaternionD;
147
+ /** Creates a log quaternion from individual x, y, z component values. */
148
+ static fromCopy3(x: number, y: number, z: number): LogQuaternionD;
149
+ /** Creates a log quaternion from a 3D vector by copying its components. */
150
+ static fromCopyVector3(vec: IVector3): LogQuaternionD;
151
+ /** Creates a log quaternion by copying from another log quaternion. */
152
+ static fromCopyLogQuaternion(quat: ILogQuaternion): LogQuaternionD;
153
+ /** Converts a regular quaternion to its logarithmic form. */
154
+ static fromCopyQuaternion(quat: IQuaternion): LogQuaternionD;
155
+ }
156
+ /**
157
+ * Alias for the 32-bit (Float32Array) implementation, making the precision explicit.
158
+ */
159
+ export { LogQuaternion as LogQuaternionF };
@@ -13,6 +13,30 @@ declare function radianToDegree(rad: number): number;
13
13
  * @returns The angle in radians
14
14
  */
15
15
  declare function degreeToRadian(deg: number): number;
16
+ /**
17
+ * Encode a quaternion (x, y, z, w) into a 64-bit log-quaternion.
18
+ * Returns [lo, hi] as unsigned 32-bit integers.
19
+ */
20
+ export declare function encodeLogQuat(qx: number, qy: number, qz: number, qw: number): number[];
21
+ /**
22
+ * Checks whether a determinant should be treated as zero.
23
+ *
24
+ * A plain `det === 0` test only catches exactly singular matrices. In practice
25
+ * a matrix whose determinant is tiny compared with its scale is just as
26
+ * dangerous, because its inverse amplifies rounding errors into garbage.
27
+ *
28
+ * @param det - The determinant of the matrix
29
+ * @param scale - The product of the row norms of the matrix (Hadamard bound)
30
+ * @param epsilon - The relative tolerance (defaults to the Float32 threshold)
31
+ * @returns True if the matrix should be considered singular
32
+ */
33
+ declare function isSingularDet(det: number, scale: number, epsilon?: number): boolean;
34
+ /**
35
+ * Returns the relative singularity tolerance for a typed array element size.
36
+ * @param bytesPerElement - 4 for Float32Array, 8 for Float64Array
37
+ * @returns The relative tolerance to use
38
+ */
39
+ declare function getSingularEpsilon(bytesPerElement: number): number;
16
40
  /**
17
41
  * Converts a 32-bit floating point number to a 16-bit half-precision float.
18
42
  * This implementation is based on the OpenEXR half-precision format with additional rounding.
@@ -44,6 +68,29 @@ declare function isPowerOfTwoTexture(width: Size, height: Size): boolean;
44
68
  * @returns A 2-element array containing the packed values
45
69
  */
46
70
  declare function packNormalizedVec4ToVec2(x: number, y: number, z: number, w: number, criteria: number): number[];
71
+ declare function packSnormVec4ToUVec2(x: number, y: number, z: number, w: number): number[];
72
+ /**
73
+ * Checks whether the given three scale components are (almost) uniform.
74
+ * The signs are ignored (only the magnitudes are compared).
75
+ *
76
+ * @param x - The x component of the scale
77
+ * @param y - The y component of the scale
78
+ * @param z - The z component of the scale
79
+ * @returns True if the scale is uniform
80
+ */
81
+ declare function isUniformScale(x: number, y: number, z: number): boolean;
82
+ /**
83
+ * Encodes the magnitude of a uniform scale for the Vec4x1 bone data type.
84
+ *
85
+ * The scale is stored as log2(scale) / 16 in a snorm16 value, and shaders decode it with exp2(value * 16).
86
+ * The relative error is therefore constant (at most about 1.7e-4) over 2^-16 .. 2^16, and 1.0 is exact.
87
+ * Scales out of the range are clamped by the snorm packing: a zero scale (often used to hide a part of a mesh)
88
+ * becomes 2^-16, which keeps the mesh invisible while keeping the skinning matrix invertible for normals.
89
+ *
90
+ * @param scale - The magnitude of the uniform scale (>= 0)
91
+ * @returns The value to be packed as snorm16 (it may be out of [-1, 1]; the packing clamps it)
92
+ */
93
+ declare function encodeVec4x1Scale(scale: number): number;
47
94
  /**
48
95
  * Calculates the cumulative distribution function (CDF) for a Gaussian distribution.
49
96
  * @param x - The value at which to evaluate the CDF
@@ -138,10 +185,18 @@ declare function computeGaussianDistributionRatioWhoseSumIsOne({ kernelSize, var
138
185
  export declare const MathUtil: Readonly<{
139
186
  radianToDegree: typeof radianToDegree;
140
187
  degreeToRadian: typeof degreeToRadian;
188
+ encodeLogQuat: typeof encodeLogQuat;
189
+ isSingularDet: typeof isSingularDet;
190
+ getSingularEpsilon: typeof getSingularEpsilon;
191
+ SINGULAR_EPSILON: 0.000001;
192
+ SINGULAR_EPSILON_FLOAT64: 1e-12;
141
193
  toHalfFloat: typeof toHalfFloat;
142
194
  isPowerOfTwo: typeof isPowerOfTwo;
143
195
  isPowerOfTwoTexture: typeof isPowerOfTwoTexture;
144
196
  packNormalizedVec4ToVec2: typeof packNormalizedVec4ToVec2;
197
+ packSnormVec4ToUVec2: typeof packSnormVec4ToUVec2;
198
+ isUniformScale: typeof isUniformScale;
199
+ encodeVec4x1Scale: typeof encodeVec4x1Scale;
145
200
  convertToStringAsGLSLFloat: typeof convertToStringAsGLSLFloat;
146
201
  nearZeroToZero: typeof nearZeroToZero;
147
202
  gaussianCdf: typeof gaussianCdf;
@@ -1,9 +1,8 @@
1
1
  import type { Array4 } from '../../types';
2
+ import type { FloatTypedArrayConstructor, TypedArray } from '../../types/CommonTypes';
2
3
  import { AbstractMatrix } from './AbstractMatrix';
3
- import type { IMatrix22 } from './IMatrix';
4
+ import type { IMatrix22, IMutableMatrix22 } from './IMatrix';
4
5
  import type { IVector2 } from './IVector';
5
- import type { Matrix33 } from './Matrix33';
6
- import type { MutableMatrix22 } from './MutableMatrix22';
7
6
  import type { MutableVector2 } from './MutableVector2';
8
7
  import { Vector2 } from './Vector2';
9
8
  /**
@@ -31,13 +30,16 @@ import { Vector2 } from './Vector2';
31
30
  * const scale = Matrix22.scale(Vector2.fromCopyArray2([2, 3]));
32
31
  * ```
33
32
  */
34
- export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
33
+ export declare class Matrix22_<T extends FloatTypedArrayConstructor> extends AbstractMatrix implements IMatrix22 {
35
34
  /**
36
- * Creates a new Matrix22 instance.
35
+ * Creates a new Matrix22_ instance.
37
36
  *
38
- * @param m - Float32Array containing matrix values in column-major order
37
+ * @param m - Typed array containing matrix values in column-major order
38
+ * @param _options - Configuration object containing the typed array constructor
39
39
  */
40
- constructor(m: Float32Array);
40
+ constructor(m: TypedArray, _options: {
41
+ type: T;
42
+ });
41
43
  /**
42
44
  * Gets the matrix element at row 0, column 0.
43
45
  *
@@ -109,7 +111,7 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
109
111
  * // | 0 0 |
110
112
  * ```
111
113
  */
112
- static zero(): Matrix22;
114
+ static _zero(type: FloatTypedArrayConstructor): IMatrix22;
113
115
  /**
114
116
  * Creates a 2x2 identity matrix.
115
117
  *
@@ -123,14 +125,14 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
123
125
  * // | 0 1 |
124
126
  * ```
125
127
  */
126
- static identity(): Matrix22;
128
+ static _identity(type: FloatTypedArrayConstructor): IMatrix22;
127
129
  /**
128
130
  * Creates a dummy matrix with empty data.
129
131
  * Used as a placeholder when no valid matrix data is available.
130
132
  *
131
133
  * @returns A new Matrix22 with empty Float32Array
132
134
  */
133
- static dummy(): Matrix22;
135
+ static _dummy(type: FloatTypedArrayConstructor): IMatrix22;
134
136
  /**
135
137
  * Creates the transpose of the given matrix.
136
138
  * The transpose swaps rows and columns: (i,j) becomes (j,i).
@@ -147,7 +149,18 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
147
149
  * // | 3 4 | | 2 4 |
148
150
  * ```
149
151
  */
150
- static transpose(mat: IMatrix22): Matrix22;
152
+ static _transpose(mat: IMatrix22, type: FloatTypedArrayConstructor): IMatrix22;
153
+ /**
154
+ * Attempts to create the inverse of the given matrix.
155
+ *
156
+ * Unlike `invert`, this method never returns a matrix filled with
157
+ * `Infinity`/`NaN`: it returns `null` when the matrix is numerically
158
+ * singular (see {@link MathUtil.isSingularDet}).
159
+ *
160
+ * @param mat - The matrix to invert
161
+ * @returns A new Matrix22, or null if the matrix is not invertible
162
+ */
163
+ static _tryInvert(mat: IMatrix22, type: FloatTypedArrayConstructor): IMatrix22 | null;
151
164
  /**
152
165
  * Creates the inverse of the given matrix.
153
166
  *
@@ -157,9 +170,13 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
157
170
  * where A = | a b | and det(A) = ad - bc
158
171
  * | c d |
159
172
  *
173
+ * If the matrix is numerically singular, an identity matrix is returned
174
+ * instead of dividing by zero. Use {@link Matrix22.tryInvert} when the
175
+ * caller needs to detect the failure.
176
+ *
160
177
  * @param mat - The matrix to invert
161
- * @returns A new Matrix22 that is the inverse of the input matrix
162
- * @throws Error if the matrix is singular (determinant is 0)
178
+ * @returns A new Matrix22 that is the inverse of the input matrix,
179
+ * or the identity matrix if the input is singular
163
180
  *
164
181
  * @example
165
182
  * ```typescript
@@ -170,17 +187,32 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
170
187
  * // | 0 0.5 |
171
188
  * ```
172
189
  */
173
- static invert(mat: IMatrix22): Matrix22;
190
+ static _invert(mat: IMatrix22, type: FloatTypedArrayConstructor): IMatrix22;
191
+ /**
192
+ * Attempts to calculate the inverse of the given matrix and stores the
193
+ * result in the output matrix.
194
+ *
195
+ * The output matrix is left untouched when the input is numerically
196
+ * singular, which lets callers keep the previous valid value.
197
+ *
198
+ * @param mat - The matrix to invert
199
+ * @param outMat - The mutable matrix to store the result
200
+ * @returns True if the inversion succeeded, false if the matrix is singular
201
+ */
202
+ static _tryInvertTo(mat: IMatrix22, outMat: IMutableMatrix22): boolean;
174
203
  /**
175
204
  * Calculates the inverse of the given matrix and stores the result in the output matrix.
176
205
  * This method avoids creating a new matrix instance for better performance.
177
206
  *
207
+ * If the matrix is numerically singular, the output matrix is set to the
208
+ * identity matrix instead of being filled with `Infinity`/`NaN`.
209
+ * Use {@link Matrix22.tryInvertTo} when the caller needs to detect the failure.
210
+ *
178
211
  * @param mat - The matrix to invert
179
212
  * @param outMat - The mutable matrix to store the result
180
- * @returns The output matrix containing the inverse
181
- * @throws Error if the matrix is singular (determinant is 0)
213
+ * @returns The output matrix containing the inverse, or the identity matrix if the input is singular
182
214
  */
183
- static invertTo(mat: Matrix22, outMat: MutableMatrix22): MutableMatrix22;
215
+ static _invertTo(mat: IMatrix22, outMat: IMutableMatrix22): IMutableMatrix22;
184
216
  /**
185
217
  * Creates a 2D rotation matrix for the given angle.
186
218
  *
@@ -197,7 +229,7 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
197
229
  * const rotation = Matrix22.rotate(Math.PI / 2);
198
230
  * ```
199
231
  */
200
- static rotate(radian: number): Matrix22;
232
+ static _rotate(radian: number, type: FloatTypedArrayConstructor): IMatrix22;
201
233
  /**
202
234
  * Creates a 2D scaling matrix from a 2D vector.
203
235
  *
@@ -214,7 +246,7 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
214
246
  * // Creates a matrix that scales x by 2 and y by 3
215
247
  * ```
216
248
  */
217
- static scale(vec: IVector2): Matrix22;
249
+ static _scale(vec: IVector2, type: FloatTypedArrayConstructor): IMatrix22;
218
250
  /**
219
251
  * Multiplies two 2x2 matrices and returns the result.
220
252
  * Matrix multiplication is not commutative: A * B ≠ B * A in general.
@@ -230,7 +262,7 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
230
262
  * const result = Matrix22.multiply(a, b); // Scale then rotate
231
263
  * ```
232
264
  */
233
- static multiply(l_mat: IMatrix22, r_mat: IMatrix22): Matrix22;
265
+ static _multiply(l_mat: IMatrix22, r_mat: IMatrix22, type: FloatTypedArrayConstructor): IMatrix22;
234
266
  /**
235
267
  * Multiplies two matrices and stores the result in the output matrix.
236
268
  * This method avoids creating a new matrix instance for better performance.
@@ -243,7 +275,7 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
243
275
  * @param outMat - The mutable matrix to store the result
244
276
  * @returns The output matrix containing the product
245
277
  */
246
- static multiplyTo(l_mat: Matrix33, r_mat: Matrix33, outMat: MutableMatrix22): MutableMatrix22;
278
+ static _multiplyTo(l_mat: IMatrix22, r_mat: IMatrix22, outMat: IMutableMatrix22): IMutableMatrix22;
247
279
  /**
248
280
  * Returns a string representation of the matrix in a readable format.
249
281
  *
@@ -401,7 +433,7 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
401
433
  * // | 3 4 |
402
434
  * ```
403
435
  */
404
- static fromCopy4RowMajor(m00: number, m01: number, m10: number, m11: number): Matrix22;
436
+ static _fromCopy4RowMajor(m00: number, m01: number, m10: number, m11: number, type: FloatTypedArrayConstructor): IMatrix22;
405
437
  /**
406
438
  * Creates a new Matrix22 from individual components in column-major order.
407
439
  *
@@ -417,7 +449,7 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
417
449
  * @param m11 - Element at row 1, column 1
418
450
  * @returns A new Matrix22 with the specified values
419
451
  */
420
- static fromCopy4ColumnMajor(m00: number, m10: number, m01: number, m11: number): Matrix22;
452
+ static _fromCopy4ColumnMajor(m00: number, m10: number, m01: number, m11: number, type: FloatTypedArrayConstructor): IMatrix22;
421
453
  /**
422
454
  * Creates a new Matrix22 that directly uses the provided Float32Array.
423
455
  * The array is used as-is without copying, so modifications to the array
@@ -426,35 +458,35 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
426
458
  * @param float32Array - Float32Array containing matrix values in column-major order
427
459
  * @returns A new Matrix22 using the provided array
428
460
  */
429
- static fromFloat32ArrayColumnMajor(float32Array: Float32Array): Matrix22;
461
+ static _fromTypedArrayColumnMajor(array: TypedArray, type: FloatTypedArrayConstructor): IMatrix22;
430
462
  /**
431
463
  * Creates a new Matrix22 by copying values from a Float32Array in column-major order.
432
464
  *
433
465
  * @param float32Array - Float32Array containing matrix values in column-major order
434
466
  * @returns A new Matrix22 with copied values
435
467
  */
436
- static fromCopyFloat32ArrayColumnMajor(float32Array: Float32Array): Matrix22;
468
+ static _fromCopyTypedArrayColumnMajor(array: TypedArray, type: FloatTypedArrayConstructor): IMatrix22;
437
469
  /**
438
470
  * Creates a new Matrix22 by copying values from a Float32Array in row-major order.
439
471
  *
440
472
  * @param array - Float32Array containing matrix values in row-major order
441
473
  * @returns A new Matrix22 with values converted to column-major order
442
474
  */
443
- static fromCopyFloat32ArrayRowMajor(array: Float32Array): Matrix22;
475
+ static _fromCopyTypedArrayRowMajor(array: TypedArray, type: FloatTypedArrayConstructor): IMatrix22;
444
476
  /**
445
477
  * Creates a new Matrix22 by copying values from another IMatrix22.
446
478
  *
447
479
  * @param mat - The matrix to copy from
448
480
  * @returns A new Matrix22 with copied values
449
481
  */
450
- static fromCopyMatrix22(mat: IMatrix22): Matrix22;
482
+ static _fromCopyMatrix22(mat: IMatrix22, type: FloatTypedArrayConstructor): IMatrix22;
451
483
  /**
452
484
  * Creates a new Matrix22 from a 4-element array in column-major order.
453
485
  *
454
486
  * @param array - Array4 containing exactly 4 numbers in column-major order
455
487
  * @returns A new Matrix22 with the array values
456
488
  */
457
- static fromCopyArray9ColumnMajor(array: Array4<number>): Matrix22;
489
+ static _fromCopyArray4ColumnMajor(array: Array4<number>, type: FloatTypedArrayConstructor): IMatrix22;
458
490
  /**
459
491
  * Creates a new Matrix22 from a variable-length array in column-major order.
460
492
  * Only the first 4 elements are used.
@@ -462,14 +494,14 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
462
494
  * @param array - Array containing matrix values in column-major order
463
495
  * @returns A new Matrix22 with the first 4 array values
464
496
  */
465
- static fromCopyArrayColumnMajor(array: Array<number>): Matrix22;
497
+ static _fromCopyArrayColumnMajor(array: Array<number>, type: FloatTypedArrayConstructor): IMatrix22;
466
498
  /**
467
499
  * Creates a new Matrix22 from a 4-element array in row-major order.
468
500
  *
469
501
  * @param array - Array4 containing exactly 4 numbers in row-major order
470
502
  * @returns A new Matrix22 with values converted to column-major order
471
503
  */
472
- static fromCopyArray9RowMajor(array: Array4<number>): Matrix22;
504
+ static _fromCopyArray4RowMajor(array: Array4<number>, type: FloatTypedArrayConstructor): IMatrix22;
473
505
  /**
474
506
  * Creates a new Matrix22 from a variable-length array in row-major order.
475
507
  * Only the first 4 elements are used.
@@ -477,5 +509,119 @@ export declare class Matrix22 extends AbstractMatrix implements IMatrix22 {
477
509
  * @param array - Array containing matrix values in row-major order
478
510
  * @returns A new Matrix22 with values converted to column-major order
479
511
  */
512
+ static _fromCopyArrayRowMajor(array: Array<number>, type: FloatTypedArrayConstructor): IMatrix22;
513
+ }
514
+ /**
515
+ * Immutable 2x2 matrix with 32-bit float components.
516
+ * This is the standard precision implementation for most 2D graphics operations.
517
+ */
518
+ export declare class Matrix22 extends Matrix22_<Float32ArrayConstructor> {
519
+ /**
520
+ * Creates a new Matrix22 instance.
521
+ * @param m - The typed array containing the matrix components
522
+ */
523
+ constructor(m: TypedArray);
524
+ /** Creates a zero matrix. */
525
+ static zero(): Matrix22;
526
+ /** Creates an identity matrix. */
527
+ static identity(): Matrix22;
528
+ /** Creates a dummy matrix with an empty array. */
529
+ static dummy(): Matrix22;
530
+ /** Creates the transpose of the given matrix. */
531
+ static transpose(mat: IMatrix22): Matrix22;
532
+ /** Attempts to invert the given matrix, returning null when it is singular. */
533
+ static tryInvert(mat: IMatrix22): Matrix22 | null;
534
+ /** Creates the inverse of the given matrix (identity when singular). */
535
+ static invert(mat: IMatrix22): Matrix22;
536
+ /** Attempts to invert the given matrix into outMat. */
537
+ static tryInvertTo<T extends IMutableMatrix22>(mat: IMatrix22, outMat: T): boolean;
538
+ /** Inverts the given matrix into outMat (identity when singular). */
539
+ static invertTo<T extends IMutableMatrix22>(mat: IMatrix22, outMat: T): T;
540
+ /** Creates a 2D rotation matrix. */
541
+ static rotate(radian: number): Matrix22;
542
+ /** Creates a 2D scaling matrix. */
543
+ static scale(vec: IVector2): Matrix22;
544
+ /** Multiplies two 2x2 matrices. */
545
+ static multiply(l_mat: IMatrix22, r_mat: IMatrix22): Matrix22;
546
+ /** Multiplies two matrices and stores the result in outMat. */
547
+ static multiplyTo<T extends IMutableMatrix22>(l_mat: IMatrix22, r_mat: IMatrix22, outMat: T): T;
548
+ /** Creates a matrix from row-major components. */
549
+ static fromCopy4RowMajor(m00: number, m01: number, m10: number, m11: number): Matrix22;
550
+ /** Creates a matrix from column-major components. */
551
+ static fromCopy4ColumnMajor(m00: number, m10: number, m01: number, m11: number): Matrix22;
552
+ /** Creates a matrix that directly uses the given Float32Array. */
553
+ static fromFloat32ArrayColumnMajor(array: Float32Array): Matrix22;
554
+ /** Creates a matrix by copying a Float32Array in column-major order. */
555
+ static fromCopyFloat32ArrayColumnMajor(array: Float32Array): Matrix22;
556
+ /** Creates a matrix by copying a Float32Array in row-major order. */
557
+ static fromCopyFloat32ArrayRowMajor(array: Float32Array): Matrix22;
558
+ /** Creates a matrix by copying another matrix. */
559
+ static fromCopyMatrix22(mat: IMatrix22): Matrix22;
560
+ /** Creates a matrix from a 4-element array in column-major order. */
561
+ static fromCopyArray9ColumnMajor(array: Array4<number>): Matrix22;
562
+ /** Creates a matrix from an array in column-major order. */
563
+ static fromCopyArrayColumnMajor(array: Array<number>): Matrix22;
564
+ /** Creates a matrix from a 4-element array in row-major order. */
565
+ static fromCopyArray9RowMajor(array: Array4<number>): Matrix22;
566
+ /** Creates a matrix from an array in row-major order. */
480
567
  static fromCopyArrayRowMajor(array: Array<number>): Matrix22;
481
568
  }
569
+ /**
570
+ * Immutable 2x2 matrix with 64-bit float components.
571
+ * Use this implementation when higher numerical precision is required.
572
+ */
573
+ export declare class Matrix22D extends Matrix22_<Float64ArrayConstructor> {
574
+ /**
575
+ * Creates a new Matrix22D instance.
576
+ * @param m - The typed array containing the matrix components
577
+ */
578
+ private constructor();
579
+ /** Creates a zero matrix. */
580
+ static zero(): Matrix22D;
581
+ /** Creates an identity matrix. */
582
+ static identity(): Matrix22D;
583
+ /** Creates a dummy matrix with an empty array. */
584
+ static dummy(): Matrix22D;
585
+ /** Creates the transpose of the given matrix. */
586
+ static transpose(mat: IMatrix22): Matrix22D;
587
+ /** Attempts to invert the given matrix, returning null when it is singular. */
588
+ static tryInvert(mat: IMatrix22): Matrix22D | null;
589
+ /** Creates the inverse of the given matrix (identity when singular). */
590
+ static invert(mat: IMatrix22): Matrix22D;
591
+ /** Attempts to invert the given matrix into outMat. */
592
+ static tryInvertTo<T extends IMutableMatrix22>(mat: IMatrix22, outMat: T): boolean;
593
+ /** Inverts the given matrix into outMat (identity when singular). */
594
+ static invertTo<T extends IMutableMatrix22>(mat: IMatrix22, outMat: T): T;
595
+ /** Creates a 2D rotation matrix. */
596
+ static rotate(radian: number): Matrix22D;
597
+ /** Creates a 2D scaling matrix. */
598
+ static scale(vec: IVector2): Matrix22D;
599
+ /** Multiplies two 2x2 matrices. */
600
+ static multiply(l_mat: IMatrix22, r_mat: IMatrix22): Matrix22D;
601
+ /** Multiplies two matrices and stores the result in outMat. */
602
+ static multiplyTo<T extends IMutableMatrix22>(l_mat: IMatrix22, r_mat: IMatrix22, outMat: T): T;
603
+ /** Creates a matrix from row-major components. */
604
+ static fromCopy4RowMajor(m00: number, m01: number, m10: number, m11: number): Matrix22D;
605
+ /** Creates a matrix from column-major components. */
606
+ static fromCopy4ColumnMajor(m00: number, m10: number, m01: number, m11: number): Matrix22D;
607
+ /** Creates a matrix that directly uses the given Float64Array. */
608
+ static fromFloat64ArrayColumnMajor(array: Float64Array): Matrix22D;
609
+ /** Creates a matrix by copying a Float64Array in column-major order. */
610
+ static fromCopyFloat64ArrayColumnMajor(array: Float64Array): Matrix22D;
611
+ /** Creates a matrix by copying a Float64Array in row-major order. */
612
+ static fromCopyFloat64ArrayRowMajor(array: Float64Array): Matrix22D;
613
+ /** Creates a matrix by copying another matrix. */
614
+ static fromCopyMatrix22(mat: IMatrix22): Matrix22D;
615
+ /** Creates a matrix from a 4-element array in column-major order. */
616
+ static fromCopyArray9ColumnMajor(array: Array4<number>): Matrix22D;
617
+ /** Creates a matrix from an array in column-major order. */
618
+ static fromCopyArrayColumnMajor(array: Array<number>): Matrix22D;
619
+ /** Creates a matrix from a 4-element array in row-major order. */
620
+ static fromCopyArray9RowMajor(array: Array4<number>): Matrix22D;
621
+ /** Creates a matrix from an array in row-major order. */
622
+ static fromCopyArrayRowMajor(array: Array<number>): Matrix22D;
623
+ }
624
+ /**
625
+ * Alias for the 32-bit (Float32Array) implementation, making the precision explicit.
626
+ */
627
+ export { Matrix22 as Matrix22F };