@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
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ yarn add @pawells/math-extended
|
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
|
-
All exports are available as individual named imports for tree-shaking
|
|
22
|
+
All exports are available as individual named imports for tree-shaking optimization.
|
|
23
23
|
|
|
24
24
|
### Direct Named Imports (Tree-Shaking Friendly)
|
|
25
25
|
|
|
@@ -43,29 +43,22 @@ const v = SmoothStep(0, 10, 0.5); // 5
|
|
|
43
43
|
const rad = DegreesToRadians(180); // Math.PI
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
### Namespace Imports (Grouped)
|
|
47
|
-
|
|
48
|
-
Import related utilities together using namespace imports:
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
import { VectorUtils, MatrixUtils, QuaternionUtils } from '@pawells/math-extended';
|
|
52
|
-
|
|
53
|
-
// Access utilities via namespace
|
|
54
|
-
VectorUtils.VectorAdd([1, 0, 0], [0, 1, 0]);
|
|
55
|
-
MatrixUtils.MatrixMultiply(matA, matB);
|
|
56
|
-
QuaternionUtils.QuaternionSLERP(q1, q2, 0.5);
|
|
57
|
-
```
|
|
58
46
|
|
|
59
47
|
### Import Patterns
|
|
60
48
|
|
|
61
49
|
| Pattern | Best For | Example |
|
|
62
50
|
|---------|----------|---------|
|
|
63
51
|
| **Direct named** | Tree-shaking, small imports | `import { VectorAdd } from '@pawells/math-extended'` |
|
|
64
|
-
| **
|
|
65
|
-
| **Mixed** | Flexibility | Both patterns together |
|
|
52
|
+
| **Mixed** | Flexibility | Multiple imports together |
|
|
66
53
|
|
|
67
54
|
## API
|
|
68
55
|
|
|
56
|
+
### Core
|
|
57
|
+
|
|
58
|
+
| Export | Description |
|
|
59
|
+
|--------|-------------|
|
|
60
|
+
| `CubeRoot(value)` | Compute the cube root of a number |
|
|
61
|
+
|
|
69
62
|
### Angles
|
|
70
63
|
|
|
71
64
|
| Export | Description |
|
|
@@ -106,7 +99,7 @@ All interpolation functions share the signature `(a, b, t)`. `t` is typically in
|
|
|
106
99
|
| `CosineInterpolation` | Cosine interpolation |
|
|
107
100
|
| `CatmullRomInterpolation` | Catmull-Rom spline `(p0, p1, p2, p3, t)` |
|
|
108
101
|
| `HermiteInterpolation` | Hermite spline `(p0, p1, t0, t1, t)` |
|
|
109
|
-
| `SphericalLinearInterpolation` |
|
|
102
|
+
| `SphericalLinearInterpolation` | **@deprecated** Identical to `LinearInterpolation`. Use `QuaternionSLERP` for true spherical interpolation. |
|
|
110
103
|
| `StepInterpolation` | Step function with configurable threshold |
|
|
111
104
|
| `QuadraticEaseIn/Out/InOut` | Quadratic easing |
|
|
112
105
|
| `CubicEaseIn/Out/InOut` | Cubic easing |
|
|
@@ -172,11 +165,11 @@ Every scalar easing function has a `Vector*` counterpart (e.g., `VectorSmoothSte
|
|
|
172
165
|
|
|
173
166
|
#### Assertions
|
|
174
167
|
|
|
175
|
-
`AssertVector`, `AssertVector2`, `AssertVector3`, `AssertVector4`, `
|
|
168
|
+
`AssertVector`, `AssertVector2`, `AssertVector3`, `AssertVector4`, `AssertVectorNonZero`, `AssertVectorSameSize`, `ValidateVector`, `ValidateVector2`, `ValidateVector3`, `ValidateVector4`, `ValidateVectorSameSize`, `VectorError`
|
|
176
169
|
|
|
177
170
|
### Matrices
|
|
178
171
|
|
|
179
|
-
Matrices are `number[][]` arrays (`
|
|
172
|
+
Matrices are `number[][]` arrays (`TMatrix`, `TMatrix1`–`TMatrix4`). All operations return new matrices.
|
|
180
173
|
|
|
181
174
|
#### Core
|
|
182
175
|
|
|
@@ -266,7 +259,7 @@ Matrices are `number[][]` arrays (`IMatrix`, `IMatrix1`–`IMatrix4`). All opera
|
|
|
266
259
|
|
|
267
260
|
#### Assertions
|
|
268
261
|
|
|
269
|
-
`AssertMatrix`, `AssertMatrix1`–`AssertMatrix4`, `
|
|
262
|
+
`AssertMatrix`, `AssertMatrix1`–`AssertMatrix4`, `AssertMatrixSquare`, `AssertMatricesCompatible`, `ValidateMatrix`, `ValidateMatrix1`–`ValidateMatrix4`, `ValidateMatrixSquare`, `MatrixError`
|
|
270
263
|
|
|
271
264
|
### Quaternions
|
|
272
265
|
|
|
@@ -318,6 +311,7 @@ Quaternions are `[x, y, z, w]` tuples (`TQuaternion`).
|
|
|
318
311
|
|
|
319
312
|
`AssertQuaternion`, `AssertQuaternions`, `AssertNormalizedQuaternion`, `AssertAxisAngle`, `AssertEulerAngles`, `AssertRotationMatrix`, `QuaternionError`
|
|
320
313
|
|
|
314
|
+
|
|
321
315
|
## Development
|
|
322
316
|
|
|
323
317
|
```bash
|
|
@@ -328,7 +322,7 @@ yarn watch # Watch mode
|
|
|
328
322
|
yarn typecheck # Type check without building
|
|
329
323
|
yarn lint # ESLint
|
|
330
324
|
yarn lint:fix # ESLint with auto-fix
|
|
331
|
-
yarn test # Run tests (
|
|
325
|
+
yarn test # Run tests (1137 tests)
|
|
332
326
|
yarn test:ui # Interactive Vitest UI
|
|
333
327
|
yarn test:coverage # Tests with coverage report
|
|
334
328
|
```
|
|
@@ -339,4 +333,4 @@ yarn test:coverage # Tests with coverage report
|
|
|
339
333
|
|
|
340
334
|
## License
|
|
341
335
|
|
|
342
|
-
|
|
336
|
+
This project is licensed under the [MIT License](LICENSE).
|
package/build/clamp.d.ts
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
* @returns The clamped value in the range [min, max]
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
* ```typescript
|
|
13
|
+
* Clamp(5, 0, 10) // 5 (within range)
|
|
14
|
+
* Clamp(-3, 0, 10) // 0 (below min)
|
|
15
|
+
* Clamp(15, 0, 10) // 10 (above max)
|
|
16
|
+
* ```
|
|
17
17
|
*/
|
|
18
18
|
export declare function Clamp(x: number, min: number, max: number): number;
|
|
19
19
|
//# sourceMappingURL=clamp.d.ts.map
|
package/build/clamp.js
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
* @returns The clamped value in the range [min, max]
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
* ```typescript
|
|
13
|
+
* Clamp(5, 0, 10) // 5 (within range)
|
|
14
|
+
* Clamp(-3, 0, 10) // 0 (below min)
|
|
15
|
+
* Clamp(15, 0, 10) // 10 (above max)
|
|
16
|
+
* ```
|
|
17
17
|
*/
|
|
18
18
|
export function Clamp(x, min, max) {
|
|
19
19
|
return Math.max(min, Math.min(x, max));
|
package/build/core.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core mathematical utilities for pure numeric calculations.
|
|
3
|
+
* Provides foundational math operations with no domain coupling.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Calculates the cube root of a number, preserving the sign of the input.
|
|
7
|
+
* Handles negative numbers correctly (unlike Math.cbrt in some contexts).
|
|
8
|
+
*
|
|
9
|
+
* @param value - The value to calculate the cube root of
|
|
10
|
+
* @returns The cube root of the value, with same sign as input
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { CubeRoot } from '@pawells/math-extended';
|
|
15
|
+
*
|
|
16
|
+
* CubeRoot(8); // 2
|
|
17
|
+
* CubeRoot(-8); // -2
|
|
18
|
+
* CubeRoot(27); // 3
|
|
19
|
+
* CubeRoot(0); // 0
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function CubeRoot(value: number): number;
|
|
23
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
package/build/core.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core mathematical utilities for pure numeric calculations.
|
|
3
|
+
* Provides foundational math operations with no domain coupling.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Calculates the cube root of a number, preserving the sign of the input.
|
|
7
|
+
* Handles negative numbers correctly (unlike Math.cbrt in some contexts).
|
|
8
|
+
*
|
|
9
|
+
* @param value - The value to calculate the cube root of
|
|
10
|
+
* @returns The cube root of the value, with same sign as input
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { CubeRoot } from '@pawells/math-extended';
|
|
15
|
+
*
|
|
16
|
+
* CubeRoot(8); // 2
|
|
17
|
+
* CubeRoot(-8); // -2
|
|
18
|
+
* CubeRoot(27); // 3
|
|
19
|
+
* CubeRoot(0); // 0
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function CubeRoot(value) {
|
|
23
|
+
return Math.sign(value) * Math.pow(Math.abs(value), 1 / 3);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACrC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5D,CAAC"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
export * as VectorUtils from './vectors/index.js';
|
|
2
|
-
export * as MatrixUtils from './matrices/index.js';
|
|
3
|
-
export * as QuaternionUtils from './quaternions/index.js';
|
|
4
|
-
export * from './angles.js';
|
|
5
1
|
export * from './clamp.js';
|
|
2
|
+
export * from './core.js';
|
|
6
3
|
export * from './interpolation.js';
|
|
7
4
|
export * from './matrices/index.js';
|
|
8
5
|
export * from './quaternions/index.js';
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
// Namespace exports for grouped imports
|
|
2
|
-
export * as VectorUtils from './vectors/index.js';
|
|
3
|
-
export * as MatrixUtils from './matrices/index.js';
|
|
4
|
-
export * as QuaternionUtils from './quaternions/index.js';
|
|
5
|
-
// Direct named exports for tree-shaking
|
|
6
|
-
export * from './angles.js';
|
|
7
1
|
export * from './clamp.js';
|
|
2
|
+
export * from './core.js';
|
|
8
3
|
export * from './interpolation.js';
|
|
9
4
|
export * from './matrices/index.js';
|
|
10
5
|
export * from './quaternions/index.js';
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
|