@pawells/math-extended 1.0.1 → 1.0.2
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/package.json +1 -1
- package/build/angles.spec.d.ts +0 -2
- package/build/angles.spec.d.ts.map +0 -1
- package/build/angles.spec.js +0 -147
- package/build/angles.spec.js.map +0 -1
- package/build/clamp.spec.d.ts +0 -2
- package/build/clamp.spec.d.ts.map +0 -1
- package/build/clamp.spec.js +0 -19
- package/build/clamp.spec.js.map +0 -1
- package/build/documentation-validation.spec.d.ts +0 -11
- package/build/documentation-validation.spec.d.ts.map +0 -1
- package/build/documentation-validation.spec.js +0 -401
- package/build/documentation-validation.spec.js.map +0 -1
- package/build/interpolation.spec.d.ts +0 -2
- package/build/interpolation.spec.d.ts.map +0 -1
- package/build/interpolation.spec.js +0 -480
- package/build/interpolation.spec.js.map +0 -1
- package/build/matrices/arithmetic.spec.d.ts +0 -2
- package/build/matrices/arithmetic.spec.d.ts.map +0 -1
- package/build/matrices/arithmetic.spec.js +0 -915
- package/build/matrices/arithmetic.spec.js.map +0 -1
- package/build/matrices/asserts.spec.d.ts +0 -2
- package/build/matrices/asserts.spec.d.ts.map +0 -1
- package/build/matrices/asserts.spec.js +0 -565
- package/build/matrices/asserts.spec.js.map +0 -1
- package/build/matrices/core.spec.d.ts +0 -2
- package/build/matrices/core.spec.d.ts.map +0 -1
- package/build/matrices/core.spec.js +0 -634
- package/build/matrices/core.spec.js.map +0 -1
- package/build/matrices/decompositions.spec.d.ts +0 -2
- package/build/matrices/decompositions.spec.d.ts.map +0 -1
- package/build/matrices/decompositions.spec.js +0 -195
- package/build/matrices/decompositions.spec.js.map +0 -1
- package/build/matrices/linear-algebra.spec.d.ts +0 -2
- package/build/matrices/linear-algebra.spec.d.ts.map +0 -1
- package/build/matrices/linear-algebra.spec.js +0 -355
- package/build/matrices/linear-algebra.spec.js.map +0 -1
- package/build/matrices/normalization.spec.d.ts +0 -2
- package/build/matrices/normalization.spec.d.ts.map +0 -1
- package/build/matrices/normalization.spec.js +0 -335
- package/build/matrices/normalization.spec.js.map +0 -1
- package/build/matrices/transformations.spec.d.ts +0 -2
- package/build/matrices/transformations.spec.d.ts.map +0 -1
- package/build/matrices/transformations.spec.js +0 -755
- package/build/matrices/transformations.spec.js.map +0 -1
- package/build/quaternions/asserts.spec.d.ts +0 -2
- package/build/quaternions/asserts.spec.d.ts.map +0 -1
- package/build/quaternions/asserts.spec.js +0 -320
- package/build/quaternions/asserts.spec.js.map +0 -1
- package/build/quaternions/conversions.spec.d.ts +0 -2
- package/build/quaternions/conversions.spec.d.ts.map +0 -1
- package/build/quaternions/conversions.spec.js +0 -344
- package/build/quaternions/conversions.spec.js.map +0 -1
- package/build/quaternions/core.spec.d.ts +0 -2
- package/build/quaternions/core.spec.d.ts.map +0 -1
- package/build/quaternions/core.spec.js +0 -294
- package/build/quaternions/core.spec.js.map +0 -1
- package/build/quaternions/interpolation.spec.d.ts +0 -2
- package/build/quaternions/interpolation.spec.d.ts.map +0 -1
- package/build/quaternions/interpolation.spec.js +0 -64
- package/build/quaternions/interpolation.spec.js.map +0 -1
- package/build/quaternions/predefined.spec.d.ts +0 -2
- package/build/quaternions/predefined.spec.d.ts.map +0 -1
- package/build/quaternions/predefined.spec.js +0 -35
- package/build/quaternions/predefined.spec.js.map +0 -1
- package/build/random.spec.d.ts +0 -2
- package/build/random.spec.d.ts.map +0 -1
- package/build/random.spec.js +0 -267
- package/build/random.spec.js.map +0 -1
- package/build/vectors/asserts.spec.d.ts +0 -2
- package/build/vectors/asserts.spec.d.ts.map +0 -1
- package/build/vectors/asserts.spec.js +0 -260
- package/build/vectors/asserts.spec.js.map +0 -1
- package/build/vectors/core.spec.d.ts +0 -2
- package/build/vectors/core.spec.d.ts.map +0 -1
- package/build/vectors/core.spec.js +0 -343
- package/build/vectors/core.spec.js.map +0 -1
- package/build/vectors/interpolation.spec.d.ts +0 -2
- package/build/vectors/interpolation.spec.d.ts.map +0 -1
- package/build/vectors/interpolation.spec.js +0 -378
- package/build/vectors/interpolation.spec.js.map +0 -1
- package/build/vectors/predefined.spec.d.ts +0 -2
- package/build/vectors/predefined.spec.d.ts.map +0 -1
- package/build/vectors/predefined.spec.js +0 -333
- package/build/vectors/predefined.spec.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pawells/math-extended",
|
|
3
3
|
"displayName": "Math Extended",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "Shared TypeScript math library — vectors, matrices, quaternions, interpolation, angles, and random utilities. ESM-only.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./build/index.js",
|
package/build/angles.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"angles.spec.d.ts","sourceRoot":"","sources":["../src/angles.spec.ts"],"names":[],"mappings":""}
|
package/build/angles.spec.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { DegreesToRadians, RadiansToDegrees, FormatRadians, NormalizeRadians, NormalizeDegrees, } from './angles.ts';
|
|
2
|
-
describe('Math Extended > Angles', () => {
|
|
3
|
-
test('Degrees to Radians', () => {
|
|
4
|
-
expect(DegreesToRadians(0)).toBe(0);
|
|
5
|
-
expect(DegreesToRadians(90)).toBe(Math.PI / 2);
|
|
6
|
-
expect(DegreesToRadians(180)).toBe(Math.PI);
|
|
7
|
-
expect(DegreesToRadians(270)).toBe((3 * Math.PI) / 2);
|
|
8
|
-
expect(DegreesToRadians(360)).toBe(2 * Math.PI);
|
|
9
|
-
expect(DegreesToRadians(-45)).toBe(-Math.PI / 4);
|
|
10
|
-
// Test decimal values
|
|
11
|
-
expect(DegreesToRadians(45.5)).toBeCloseTo(Math.PI * 0.25278);
|
|
12
|
-
// Test large values
|
|
13
|
-
expect(DegreesToRadians(3600)).toBe(20 * Math.PI);
|
|
14
|
-
});
|
|
15
|
-
test('Radians to Degrees', () => {
|
|
16
|
-
expect(RadiansToDegrees(0)).toBe(0);
|
|
17
|
-
expect(RadiansToDegrees(Math.PI / 2)).toBe(90);
|
|
18
|
-
expect(RadiansToDegrees(Math.PI)).toBe(180);
|
|
19
|
-
expect(RadiansToDegrees((3 * Math.PI) / 2)).toBe(270);
|
|
20
|
-
expect(RadiansToDegrees(2 * Math.PI)).toBe(360);
|
|
21
|
-
expect(RadiansToDegrees(-Math.PI / 4)).toBe(-45);
|
|
22
|
-
// Test decimal values
|
|
23
|
-
expect(RadiansToDegrees(Math.PI / 6)).toBeCloseTo(30);
|
|
24
|
-
// Test large values
|
|
25
|
-
expect(RadiansToDegrees(10 * Math.PI)).toBe(1800);
|
|
26
|
-
});
|
|
27
|
-
test('Format Radians', () => {
|
|
28
|
-
expect(FormatRadians(0)).toBe('0');
|
|
29
|
-
expect(FormatRadians(Math.PI)).toBe('π');
|
|
30
|
-
expect(FormatRadians(-Math.PI)).toBe('-π');
|
|
31
|
-
expect(FormatRadians(Math.PI / 2)).toBe('π/2');
|
|
32
|
-
expect(FormatRadians(Math.PI / 4)).toBe('π/4');
|
|
33
|
-
expect(FormatRadians(Math.PI / 3)).toBe('π/3');
|
|
34
|
-
// Based on the current implementation, this returns "1.5π" rather than "3π/2"
|
|
35
|
-
expect(FormatRadians((3 * Math.PI) / 2)).toContain('π');
|
|
36
|
-
// Additional fraction representations
|
|
37
|
-
expect(FormatRadians(Math.PI / 6)).toBe('π/6');
|
|
38
|
-
expect(FormatRadians((2 * Math.PI) / 3)).toBe('2π/3');
|
|
39
|
-
expect(FormatRadians((3 * Math.PI) / 4)).toContain('π'); // Based on the implementation behavior
|
|
40
|
-
// Edge cases
|
|
41
|
-
expect(FormatRadians(0.00001)).toContain('π'); // Very small value
|
|
42
|
-
expect(FormatRadians(100 * Math.PI)).toContain('π'); // Very large value
|
|
43
|
-
// Common angles - adjust expectations to match the actual implementation
|
|
44
|
-
const formattedAngle = FormatRadians(Math.PI * 1.5);
|
|
45
|
-
expect(formattedAngle === '1.5π' || formattedAngle === '3π/2').toBeTruthy();
|
|
46
|
-
// Value that doesn't have a simple fraction representation
|
|
47
|
-
expect(FormatRadians(Math.PI * 0.7)).toContain('π');
|
|
48
|
-
});
|
|
49
|
-
test('Radian Normalization', () => {
|
|
50
|
-
// Basic cases
|
|
51
|
-
expect(NormalizeRadians(0)).toBe(0);
|
|
52
|
-
expect(NormalizeRadians(Math.PI)).toBeCloseTo(Math.PI);
|
|
53
|
-
expect(NormalizeRadians(2 * Math.PI)).toBeCloseTo(0);
|
|
54
|
-
// Values outside the 0-2π range
|
|
55
|
-
expect(NormalizeRadians(3 * Math.PI)).toBeCloseTo(Math.PI);
|
|
56
|
-
expect(NormalizeRadians(-Math.PI)).toBeCloseTo(Math.PI);
|
|
57
|
-
expect(NormalizeRadians(-2 * Math.PI)).toBeCloseTo(0);
|
|
58
|
-
expect(NormalizeRadians(7 * Math.PI)).toBeCloseTo(Math.PI);
|
|
59
|
-
// Extreme values - these need special handling due to floating point precision
|
|
60
|
-
const normalizedLarge = NormalizeRadians(1000 * Math.PI);
|
|
61
|
-
expect(normalizedLarge >= 0 && normalizedLarge < 2 * Math.PI).toBeTruthy();
|
|
62
|
-
const normalizedNegative = NormalizeRadians(-999 * Math.PI);
|
|
63
|
-
expect(normalizedNegative >= 0 && normalizedNegative < 2 * Math.PI).toBeTruthy();
|
|
64
|
-
// Decimal values
|
|
65
|
-
expect(NormalizeRadians(Math.PI + 0.1)).toBeCloseTo(Math.PI + 0.1);
|
|
66
|
-
expect(NormalizeRadians((2 * Math.PI) + 0.2)).toBeCloseTo(0.2);
|
|
67
|
-
});
|
|
68
|
-
test('Degree Normalization', () => {
|
|
69
|
-
// Basic cases
|
|
70
|
-
expect(NormalizeDegrees(0)).toBe(0);
|
|
71
|
-
expect(NormalizeDegrees(180)).toBe(180);
|
|
72
|
-
expect(NormalizeDegrees(360)).toBe(0);
|
|
73
|
-
// Values outside the 0-360 range
|
|
74
|
-
expect(NormalizeDegrees(540)).toBe(180);
|
|
75
|
-
expect(NormalizeDegrees(-180)).toBe(180);
|
|
76
|
-
expect(NormalizeDegrees(-360)).toBe(0);
|
|
77
|
-
expect(NormalizeDegrees(1260)).toBe(180);
|
|
78
|
-
// Extreme values
|
|
79
|
-
expect(NormalizeDegrees(3600)).toBe(0);
|
|
80
|
-
expect(NormalizeDegrees(-3600)).toBe(0);
|
|
81
|
-
// Decimal values
|
|
82
|
-
expect(NormalizeDegrees(45.5)).toBe(45.5);
|
|
83
|
-
expect(NormalizeDegrees(360.5)).toBe(0.5);
|
|
84
|
-
expect(NormalizeDegrees(-0.5)).toBe(359.5);
|
|
85
|
-
});
|
|
86
|
-
test('Preserve Angles when Normalizing', () => {
|
|
87
|
-
// Create a range of angles
|
|
88
|
-
for (let angle = -720; angle <= 720; angle += 45) {
|
|
89
|
-
// For radians
|
|
90
|
-
const radians = DegreesToRadians(angle);
|
|
91
|
-
const normalizedRadians = NormalizeRadians(radians);
|
|
92
|
-
// Convert back to degrees for comparison
|
|
93
|
-
const backToDegrees = RadiansToDegrees(normalizedRadians);
|
|
94
|
-
const normalizedDegrees = NormalizeDegrees(angle);
|
|
95
|
-
// Check if the angles are equivalent (considering circular nature)
|
|
96
|
-
expect(normalizedDegrees).toBeCloseTo(NormalizeDegrees(backToDegrees));
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
test('Additional Angle Conversions', () => {
|
|
100
|
-
// Test random angles to ensure conversion works correctly in both directions
|
|
101
|
-
for (let i = 0; i < 10; i++) {
|
|
102
|
-
const randomDegrees = (Math.random() * 720) - 360; // Random between -360 and 360
|
|
103
|
-
const toRadians = DegreesToRadians(randomDegrees);
|
|
104
|
-
const backToDegrees = RadiansToDegrees(toRadians);
|
|
105
|
-
expect(backToDegrees).toBeCloseTo(randomDegrees);
|
|
106
|
-
}
|
|
107
|
-
// Test that normalization preserves the angle's position on the circle
|
|
108
|
-
// for non-integer values
|
|
109
|
-
for (let angle = -10.5; angle <= 10.5; angle += 0.5) {
|
|
110
|
-
const normalizedDegrees = NormalizeDegrees(angle * 360);
|
|
111
|
-
const normalizedRadians = NormalizeRadians(angle * 2 * Math.PI);
|
|
112
|
-
const convertedDegrees = RadiansToDegrees(normalizedRadians);
|
|
113
|
-
expect(normalizedDegrees).toBeCloseTo(NormalizeDegrees(convertedDegrees));
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
test('NormalizeRadians covers negative non-multiple of π', () => {
|
|
117
|
-
// -5 radians is not a multiple of π, should normalize to [0, 2π)
|
|
118
|
-
const input = -5;
|
|
119
|
-
const normalized = NormalizeRadians(input);
|
|
120
|
-
expect(normalized).toBeGreaterThanOrEqual(0);
|
|
121
|
-
expect(normalized).toBeLessThan(2 * Math.PI);
|
|
122
|
-
// Check that adding/subtracting 2π lands on the same angle
|
|
123
|
-
const expected = ((input % (2 * Math.PI)) + (2 * Math.PI)) % (2 * Math.PI);
|
|
124
|
-
expect(normalized).toBeCloseTo(expected);
|
|
125
|
-
});
|
|
126
|
-
test('NormalizeRadians covers negative just below zero', () => {
|
|
127
|
-
const input = -0.1;
|
|
128
|
-
const normalized = NormalizeRadians(input);
|
|
129
|
-
expect(normalized).toBeCloseTo((2 * Math.PI) - 0.1);
|
|
130
|
-
});
|
|
131
|
-
test('NormalizeRadians covers positive just above 2π', () => {
|
|
132
|
-
const input = (2 * Math.PI) + 0.1;
|
|
133
|
-
const normalized = NormalizeRadians(input);
|
|
134
|
-
expect(normalized).toBeCloseTo(0.1);
|
|
135
|
-
});
|
|
136
|
-
test('FormatRadians handles π/5', () => {
|
|
137
|
-
const input = Math.PI / 5;
|
|
138
|
-
const formatted = FormatRadians(input);
|
|
139
|
-
expect(formatted).toBe('π/5');
|
|
140
|
-
});
|
|
141
|
-
test('FormatRadians handles -π/5', () => {
|
|
142
|
-
const input = -Math.PI / 5;
|
|
143
|
-
const formatted = FormatRadians(input);
|
|
144
|
-
expect(formatted).toBe('-π/5');
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
//# sourceMappingURL=angles.spec.js.map
|
package/build/angles.spec.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"angles.spec.js","sourceRoot":"","sources":["../src/angles.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EACjD,gBAAgB,EAAE,gBAAgB,GAClC,MAAM,aAAa,CAAC;AAErB,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACvC,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAC/B,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QAC/C,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5C,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACtD,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;QAChD,MAAM,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QACjD,sBAAsB;QACtB,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC;QAC9D,oBAAoB;QACpB,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CA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,KAAK,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QAC3B,MAAM,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/build/clamp.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clamp.spec.d.ts","sourceRoot":"","sources":["../src/clamp.spec.ts"],"names":[],"mappings":""}
|
package/build/clamp.spec.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Clamp } from './clamp.ts';
|
|
2
|
-
describe('Math Extended > Clamp', () => {
|
|
3
|
-
test('If the value is within range, return the value.', () => {
|
|
4
|
-
expect(Clamp(5, 0, 10)).toBe(5);
|
|
5
|
-
expect(Clamp(-3, -5, 5)).toBe(-3);
|
|
6
|
-
expect(Clamp(0, -10, 10)).toBe(0);
|
|
7
|
-
});
|
|
8
|
-
test('If the value is less than the minimum, return the minimum value.', () => {
|
|
9
|
-
expect(Clamp(-10, 0, 10)).toBe(0);
|
|
10
|
-
expect(Clamp(-100, -50, 50)).toBe(-50);
|
|
11
|
-
expect(Clamp(-5, -2, 2)).toBe(-2);
|
|
12
|
-
});
|
|
13
|
-
test('If the value is greater than the maximum, return the maximum value.', () => {
|
|
14
|
-
expect(Clamp(15, 0, 10)).toBe(10);
|
|
15
|
-
expect(Clamp(100, -50, 50)).toBe(50);
|
|
16
|
-
expect(Clamp(3, -2, 2)).toBe(2);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
//# sourceMappingURL=clamp.spec.js.map
|
package/build/clamp.spec.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clamp.spec.js","sourceRoot":"","sources":["../src/clamp.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAA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AC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Documentation Validation Tests
|
|
3
|
-
*
|
|
4
|
-
* This file validates all code examples from README.md to ensure:
|
|
5
|
-
* 1. All examples compile correctly
|
|
6
|
-
* 2. Type inference works as documented
|
|
7
|
-
* 3. Examples produce expected results
|
|
8
|
-
* 4. No runtime errors occur
|
|
9
|
-
*/
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=documentation-validation.spec.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"documentation-validation.spec.d.ts","sourceRoot":"","sources":["../src/documentation-validation.spec.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG"}
|
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Documentation Validation Tests
|
|
3
|
-
*
|
|
4
|
-
* This file validates all code examples from README.md to ensure:
|
|
5
|
-
* 1. All examples compile correctly
|
|
6
|
-
* 2. Type inference works as documented
|
|
7
|
-
* 3. Examples produce expected results
|
|
8
|
-
* 4. No runtime errors occur
|
|
9
|
-
*/
|
|
10
|
-
import {
|
|
11
|
-
// Matrix operations
|
|
12
|
-
MatrixAdd, MatrixMultiply, MatrixInverse, MatrixTranspose, MatrixDeterminant, MatrixLU, MatrixQR, MatrixSVD, MatrixEigen,
|
|
13
|
-
// Vector operations
|
|
14
|
-
VectorAdd, VectorDot, Vector3Cross, VectorNormalize, VectorMultiply, VectorDistance, VectorAngle, VectorLERP, VectorSmoothStep, VectorCubicEaseOut,
|
|
15
|
-
// Quaternion operations
|
|
16
|
-
QuaternionFromAxisAngle, QuaternionRotateVector, QuaternionSLERP, QuaternionFromEuler, QuaternionMultiply, QuaternionToRotationMatrix, QuaternionFromRotationMatrix, QuaternionIdentity,
|
|
17
|
-
// Transformations
|
|
18
|
-
MatrixRotation3D, MatrixScale3D, MatrixTranslation3D, MatrixRotation2D, MatrixScale2D, MatrixTranslation2D, MatrixView, MatrixPerspective, MatrixTransform3D,
|
|
19
|
-
// Interpolation
|
|
20
|
-
LinearInterpolation, SmoothStep, ElasticEaseOut,
|
|
21
|
-
// Utilities
|
|
22
|
-
DegreesToRadians, RadiansToDegrees, Clamp, RandomInt, RandomNormal,
|
|
23
|
-
// Predefined vectors
|
|
24
|
-
Vector3Up, Vector3Forward, VectorZero,
|
|
25
|
-
// Validation
|
|
26
|
-
AssertMatrix2, AssertVector3, } from './index.ts';
|
|
27
|
-
describe('README.md Code Examples Validation', () => {
|
|
28
|
-
describe('Quick Start Examples', () => {
|
|
29
|
-
test('Matrix operations example', () => {
|
|
30
|
-
const a = [
|
|
31
|
-
[1, 0, 0],
|
|
32
|
-
[0, 1, 0],
|
|
33
|
-
[0, 0, 1],
|
|
34
|
-
];
|
|
35
|
-
const b = [
|
|
36
|
-
[2, 0, 0],
|
|
37
|
-
[0, 2, 0],
|
|
38
|
-
[0, 0, 2],
|
|
39
|
-
];
|
|
40
|
-
const sum = MatrixAdd(a, b);
|
|
41
|
-
const product = MatrixMultiply(a, b);
|
|
42
|
-
expect(sum).toEqual([
|
|
43
|
-
[3, 0, 0],
|
|
44
|
-
[0, 3, 0],
|
|
45
|
-
[0, 0, 3],
|
|
46
|
-
]);
|
|
47
|
-
expect(product).toEqual(b); // Identity × B = B
|
|
48
|
-
});
|
|
49
|
-
test('Vector operations example', () => {
|
|
50
|
-
const v1 = [1, 2, 3];
|
|
51
|
-
const v2 = [4, 5, 6];
|
|
52
|
-
const vSum = VectorAdd(v1, v2);
|
|
53
|
-
const dot = VectorDot(v1, v2);
|
|
54
|
-
const cross = Vector3Cross(v1, v2);
|
|
55
|
-
expect(vSum).toEqual([5, 7, 9]);
|
|
56
|
-
expect(dot).toBe(32);
|
|
57
|
-
expect(cross).toEqual([-3, 6, -3]);
|
|
58
|
-
});
|
|
59
|
-
test('Quaternion rotations example', () => {
|
|
60
|
-
const axis = [0, 1, 0];
|
|
61
|
-
const rotation = QuaternionFromAxisAngle(axis, Math.PI / 2);
|
|
62
|
-
const rotated = QuaternionRotateVector(rotation, [1, 0, 0]);
|
|
63
|
-
// Should rotate [1,0,0] 90° around Y-axis to approximately [0,0,-1]
|
|
64
|
-
expect(rotated[0]).toBeCloseTo(0, 5);
|
|
65
|
-
expect(rotated[1]).toBeCloseTo(0, 5);
|
|
66
|
-
expect(rotated[2]).toBeCloseTo(-1, 5);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
describe('Matrix Operations Examples', () => {
|
|
70
|
-
test('Basic arithmetic', () => {
|
|
71
|
-
const a = [
|
|
72
|
-
[1, 2],
|
|
73
|
-
[3, 4],
|
|
74
|
-
];
|
|
75
|
-
const b = [
|
|
76
|
-
[5, 6],
|
|
77
|
-
[7, 8],
|
|
78
|
-
];
|
|
79
|
-
const sum = MatrixAdd(a, b);
|
|
80
|
-
const product = MatrixMultiply(a, b);
|
|
81
|
-
expect(sum).toEqual([
|
|
82
|
-
[6, 8],
|
|
83
|
-
[10, 12],
|
|
84
|
-
]);
|
|
85
|
-
expect(product).toEqual([
|
|
86
|
-
[19, 22],
|
|
87
|
-
[43, 50],
|
|
88
|
-
]);
|
|
89
|
-
});
|
|
90
|
-
test('Linear algebra operations', () => {
|
|
91
|
-
const a = [
|
|
92
|
-
[1, 2],
|
|
93
|
-
[3, 4],
|
|
94
|
-
];
|
|
95
|
-
const transposed = MatrixTranspose(a);
|
|
96
|
-
const inverse = MatrixInverse(a);
|
|
97
|
-
const det = MatrixDeterminant(a);
|
|
98
|
-
expect(transposed).toEqual([
|
|
99
|
-
[1, 3],
|
|
100
|
-
[2, 4],
|
|
101
|
-
]);
|
|
102
|
-
// Verify inverse exists and has correct values
|
|
103
|
-
expect(inverse).toBeDefined();
|
|
104
|
-
expect(inverse.length).toBe(2);
|
|
105
|
-
expect(inverse[0]?.length).toBe(2);
|
|
106
|
-
expect(inverse[0]?.[0]).toBeCloseTo(-2, 5);
|
|
107
|
-
expect(inverse[0]?.[1]).toBeCloseTo(1, 5);
|
|
108
|
-
expect(inverse[1]?.[0]).toBeCloseTo(1.5, 5);
|
|
109
|
-
expect(inverse[1]?.[1]).toBeCloseTo(-0.5, 5);
|
|
110
|
-
expect(det).toBeCloseTo(-2, 5);
|
|
111
|
-
});
|
|
112
|
-
test('Matrix decompositions', () => {
|
|
113
|
-
const a = [
|
|
114
|
-
[1, 2],
|
|
115
|
-
[3, 4],
|
|
116
|
-
];
|
|
117
|
-
const { L, U } = MatrixLU(a);
|
|
118
|
-
const { Q, R } = MatrixQR(a);
|
|
119
|
-
const { U: svdU, S, VT } = MatrixSVD(a);
|
|
120
|
-
const { eigenvalues, eigenvectors } = MatrixEigen(a);
|
|
121
|
-
// Verify decompositions exist and have correct structure
|
|
122
|
-
expect(L).toBeDefined();
|
|
123
|
-
expect(U).toBeDefined();
|
|
124
|
-
expect(Q).toBeDefined();
|
|
125
|
-
expect(R).toBeDefined();
|
|
126
|
-
expect(svdU).toBeDefined();
|
|
127
|
-
expect(S).toBeDefined();
|
|
128
|
-
expect(VT).toBeDefined();
|
|
129
|
-
expect(eigenvalues).toBeDefined();
|
|
130
|
-
expect(eigenvectors).toBeDefined();
|
|
131
|
-
});
|
|
132
|
-
test('Transformation matrices', () => {
|
|
133
|
-
const rotation = MatrixRotation3D(0, Math.PI / 4, 0);
|
|
134
|
-
const scale = MatrixScale3D(2, 2, 2);
|
|
135
|
-
const translation = MatrixTranslation3D(10, 5, 0);
|
|
136
|
-
expect(rotation).toBeDefined();
|
|
137
|
-
expect(rotation.length).toBe(4);
|
|
138
|
-
expect(rotation[0].length).toBe(4);
|
|
139
|
-
expect(scale).toBeDefined();
|
|
140
|
-
expect(translation).toBeDefined();
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
describe('Vector Operations Examples', () => {
|
|
144
|
-
test('Basic operations', () => {
|
|
145
|
-
const v1 = [1, 2, 3];
|
|
146
|
-
const v2 = [4, 5, 6];
|
|
147
|
-
const sum = VectorAdd(v1, v2);
|
|
148
|
-
const scaled = VectorMultiply(v1, 2);
|
|
149
|
-
expect(sum).toEqual([5, 7, 9]);
|
|
150
|
-
expect(scaled).toEqual([2, 4, 6]);
|
|
151
|
-
});
|
|
152
|
-
test('Geometric operations', () => {
|
|
153
|
-
const v1 = [1, 2, 3];
|
|
154
|
-
const v2 = [4, 5, 6];
|
|
155
|
-
const dot = VectorDot(v1, v2);
|
|
156
|
-
const cross = Vector3Cross(v1, v2);
|
|
157
|
-
const normalized = VectorNormalize(v1);
|
|
158
|
-
const distance = VectorDistance(v1, v2);
|
|
159
|
-
const angle = VectorAngle(v1, v2);
|
|
160
|
-
expect(dot).toBe(32);
|
|
161
|
-
expect(cross).toEqual([-3, 6, -3]);
|
|
162
|
-
expect(normalized[0]).toBeCloseTo(0.267, 2);
|
|
163
|
-
expect(normalized[1]).toBeCloseTo(0.535, 2);
|
|
164
|
-
expect(normalized[2]).toBeCloseTo(0.802, 2);
|
|
165
|
-
expect(distance).toBeCloseTo(5.196, 2);
|
|
166
|
-
expect(angle).toBeCloseTo(0.226, 2);
|
|
167
|
-
});
|
|
168
|
-
test('Interpolation', () => {
|
|
169
|
-
const v1 = [1, 2, 3];
|
|
170
|
-
const v2 = [4, 5, 6];
|
|
171
|
-
const lerp = VectorLERP(v1, v2, 0.5);
|
|
172
|
-
const smooth = VectorSmoothStep(v1, v2, 0.5);
|
|
173
|
-
const cubic = VectorCubicEaseOut(v1, v2, 0.5);
|
|
174
|
-
expect(lerp).toEqual([2.5, 3.5, 4.5]);
|
|
175
|
-
expect(smooth).toBeDefined();
|
|
176
|
-
expect(cubic).toBeDefined();
|
|
177
|
-
});
|
|
178
|
-
test('Predefined vectors', () => {
|
|
179
|
-
const up = Vector3Up();
|
|
180
|
-
const forward = Vector3Forward();
|
|
181
|
-
const zero = VectorZero(3);
|
|
182
|
-
expect(up).toEqual([0, 1, 0]);
|
|
183
|
-
expect(forward).toEqual([0, 0, 1]);
|
|
184
|
-
expect(zero).toEqual([0, 0, 0]);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
describe('Quaternion Operations Examples', () => {
|
|
188
|
-
test('Create rotations', () => {
|
|
189
|
-
const identity = QuaternionIdentity();
|
|
190
|
-
const axis = [0, 1, 0];
|
|
191
|
-
const rotation = QuaternionFromAxisAngle(axis, Math.PI / 2);
|
|
192
|
-
expect(identity).toEqual([0, 0, 0, 1]);
|
|
193
|
-
expect(rotation).toBeDefined();
|
|
194
|
-
expect(rotation.length).toBe(4);
|
|
195
|
-
});
|
|
196
|
-
test('Euler angle conversion', () => {
|
|
197
|
-
const euler = [0, Math.PI / 4, 0];
|
|
198
|
-
const quat = QuaternionFromEuler(euler);
|
|
199
|
-
expect(quat).toBeDefined();
|
|
200
|
-
expect(quat.length).toBe(4);
|
|
201
|
-
});
|
|
202
|
-
test('Rotate vectors', () => {
|
|
203
|
-
const axis = [0, 1, 0];
|
|
204
|
-
const rotation = QuaternionFromAxisAngle(axis, Math.PI / 2);
|
|
205
|
-
const vector = [1, 0, 0];
|
|
206
|
-
const rotated = QuaternionRotateVector(rotation, vector);
|
|
207
|
-
expect(rotated[0]).toBeCloseTo(0, 5);
|
|
208
|
-
expect(rotated[1]).toBeCloseTo(0, 5);
|
|
209
|
-
expect(rotated[2]).toBeCloseTo(-1, 5);
|
|
210
|
-
});
|
|
211
|
-
test('Combine rotations', () => {
|
|
212
|
-
const q1 = QuaternionFromAxisAngle([1, 0, 0], Math.PI / 4);
|
|
213
|
-
const q2 = QuaternionFromAxisAngle([0, 1, 0], Math.PI / 4);
|
|
214
|
-
const combined = QuaternionMultiply(q1, q2);
|
|
215
|
-
expect(combined).toBeDefined();
|
|
216
|
-
expect(combined.length).toBe(4);
|
|
217
|
-
});
|
|
218
|
-
test('Smooth interpolation (SLERP)', () => {
|
|
219
|
-
const q1 = QuaternionFromAxisAngle([1, 0, 0], Math.PI / 4);
|
|
220
|
-
const q2 = QuaternionFromAxisAngle([0, 1, 0], Math.PI / 4);
|
|
221
|
-
const interpolated = QuaternionSLERP(q1, q2, 0.5);
|
|
222
|
-
expect(interpolated).toBeDefined();
|
|
223
|
-
expect(interpolated.length).toBe(4);
|
|
224
|
-
});
|
|
225
|
-
test('Convert to/from rotation matrices', () => {
|
|
226
|
-
const axis = [0, 1, 0];
|
|
227
|
-
const rotation = QuaternionFromAxisAngle(axis, Math.PI / 2);
|
|
228
|
-
const matrix = QuaternionToRotationMatrix(rotation);
|
|
229
|
-
const quatFromMatrix = QuaternionFromRotationMatrix(matrix);
|
|
230
|
-
expect(matrix).toBeDefined();
|
|
231
|
-
expect(matrix.length).toBe(3);
|
|
232
|
-
expect(matrix[0].length).toBe(3);
|
|
233
|
-
expect(quatFromMatrix).toBeDefined();
|
|
234
|
-
expect(quatFromMatrix.length).toBe(4);
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
describe('Transformation Matrices Examples', () => {
|
|
238
|
-
test('2D transformations', () => {
|
|
239
|
-
const rotation2D = MatrixRotation2D(Math.PI / 4);
|
|
240
|
-
const scale2D = MatrixScale2D(2, 3);
|
|
241
|
-
const translation2D = MatrixTranslation2D(10, 20);
|
|
242
|
-
expect(rotation2D).toBeDefined();
|
|
243
|
-
expect(rotation2D.length).toBe(3);
|
|
244
|
-
expect(scale2D).toBeDefined();
|
|
245
|
-
expect(translation2D).toBeDefined();
|
|
246
|
-
});
|
|
247
|
-
test('3D transformations', () => {
|
|
248
|
-
const rotation3D = MatrixRotation3D(0, Math.PI / 4, 0);
|
|
249
|
-
const scale3D = MatrixScale3D(2, 2, 2);
|
|
250
|
-
const translation3D = MatrixTranslation3D(10, 5, 0);
|
|
251
|
-
expect(rotation3D).toBeDefined();
|
|
252
|
-
expect(rotation3D.length).toBe(4);
|
|
253
|
-
expect(scale3D).toBeDefined();
|
|
254
|
-
expect(translation3D).toBeDefined();
|
|
255
|
-
});
|
|
256
|
-
test('Camera matrices', () => {
|
|
257
|
-
const eye = [0, 5, 10];
|
|
258
|
-
const target = [0, 0, 0];
|
|
259
|
-
const up = [0, 1, 0];
|
|
260
|
-
const view = MatrixView(eye, target, up);
|
|
261
|
-
const perspective = MatrixPerspective(Math.PI / 4, 16 / 9, 0.1, 100);
|
|
262
|
-
expect(view).toBeDefined();
|
|
263
|
-
expect(view.length).toBe(4);
|
|
264
|
-
expect(perspective).toBeDefined();
|
|
265
|
-
expect(perspective.length).toBe(4);
|
|
266
|
-
});
|
|
267
|
-
test('Apply transformations', () => {
|
|
268
|
-
const rotation3D = MatrixRotation3D(0, Math.PI / 4, 0);
|
|
269
|
-
const point = [1, 2, 3];
|
|
270
|
-
const transformed = MatrixTransform3D(point, rotation3D);
|
|
271
|
-
expect(transformed).toBeDefined();
|
|
272
|
-
expect(transformed.length).toBe(3);
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
describe('Interpolation & Utilities Examples', () => {
|
|
276
|
-
test('Scalar interpolation', () => {
|
|
277
|
-
const lerp = LinearInterpolation(0, 100, 0.5);
|
|
278
|
-
const smooth = SmoothStep(0, 100, 0.5);
|
|
279
|
-
const elastic = ElasticEaseOut(0, 100, 0.8);
|
|
280
|
-
expect(lerp).toBe(50);
|
|
281
|
-
expect(smooth).toBeDefined();
|
|
282
|
-
expect(elastic).toBeDefined();
|
|
283
|
-
});
|
|
284
|
-
test('Angle utilities', () => {
|
|
285
|
-
const radians = DegreesToRadians(90);
|
|
286
|
-
const degrees = RadiansToDegrees(Math.PI);
|
|
287
|
-
expect(radians).toBeCloseTo(Math.PI / 2, 5);
|
|
288
|
-
expect(degrees).toBeCloseTo(180, 5);
|
|
289
|
-
});
|
|
290
|
-
test('Utilities', () => {
|
|
291
|
-
const clamped = Clamp(150, 0, 100);
|
|
292
|
-
const randomInt = RandomInt(1, 10);
|
|
293
|
-
const gaussian = RandomNormal(0, 1);
|
|
294
|
-
expect(clamped).toBe(100);
|
|
295
|
-
expect(randomInt).toBeGreaterThanOrEqual(1);
|
|
296
|
-
expect(randomInt).toBeLessThanOrEqual(10);
|
|
297
|
-
expect(gaussian).toBeDefined();
|
|
298
|
-
expect(typeof gaussian).toBe('number');
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
describe('Validation & Error Handling Examples', () => {
|
|
302
|
-
test('Type guards with runtime validation', () => {
|
|
303
|
-
const matrix = [
|
|
304
|
-
[1, 2],
|
|
305
|
-
[3, 4],
|
|
306
|
-
];
|
|
307
|
-
expect(() => AssertMatrix2(matrix)).not.toThrow();
|
|
308
|
-
const vector = [1, 2, 3];
|
|
309
|
-
expect(() => AssertVector3(vector)).not.toThrow();
|
|
310
|
-
});
|
|
311
|
-
test('Automatic validation in operations', () => {
|
|
312
|
-
const a = [
|
|
313
|
-
[1, 2],
|
|
314
|
-
[3, 4],
|
|
315
|
-
];
|
|
316
|
-
const b = [
|
|
317
|
-
[5, 6],
|
|
318
|
-
[7, 8],
|
|
319
|
-
];
|
|
320
|
-
expect(() => MatrixAdd(a, b)).not.toThrow();
|
|
321
|
-
const v1 = [1, 2, 3];
|
|
322
|
-
const v2 = [4, 5, 6];
|
|
323
|
-
expect(() => VectorDot(v1, v2)).not.toThrow();
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
describe('SPECIFICATION.md Examples', () => {
|
|
327
|
-
test('Matrix operations example', () => {
|
|
328
|
-
const a = [
|
|
329
|
-
[1, 2],
|
|
330
|
-
[3, 4],
|
|
331
|
-
];
|
|
332
|
-
const b = [
|
|
333
|
-
[5, 6],
|
|
334
|
-
[7, 8],
|
|
335
|
-
];
|
|
336
|
-
const sum = MatrixAdd(a, b);
|
|
337
|
-
const product = MatrixMultiply(a, b);
|
|
338
|
-
expect(sum).toEqual([
|
|
339
|
-
[6, 8],
|
|
340
|
-
[10, 12],
|
|
341
|
-
]);
|
|
342
|
-
expect(product).toEqual([
|
|
343
|
-
[19, 22],
|
|
344
|
-
[43, 50],
|
|
345
|
-
]);
|
|
346
|
-
});
|
|
347
|
-
test('Vector operations example', () => {
|
|
348
|
-
const v1 = [1, 2, 3];
|
|
349
|
-
const v2 = [4, 5, 6];
|
|
350
|
-
const sum = VectorAdd(v1, v2);
|
|
351
|
-
const dot = VectorDot(v1, v2);
|
|
352
|
-
const cross = Vector3Cross(v1, v2);
|
|
353
|
-
const normalized = VectorNormalize(v1);
|
|
354
|
-
expect(sum).toEqual([5, 7, 9]);
|
|
355
|
-
expect(dot).toBe(32);
|
|
356
|
-
expect(cross).toEqual([-3, 6, -3]);
|
|
357
|
-
expect(normalized[0]).toBeCloseTo(0.267, 2);
|
|
358
|
-
expect(normalized[1]).toBeCloseTo(0.535, 2);
|
|
359
|
-
expect(normalized[2]).toBeCloseTo(0.802, 2);
|
|
360
|
-
});
|
|
361
|
-
test('Quaternion operations example', () => {
|
|
362
|
-
const axis = [0, 1, 0];
|
|
363
|
-
const rotation = QuaternionFromAxisAngle(axis, Math.PI / 2);
|
|
364
|
-
const vector = [1, 0, 0];
|
|
365
|
-
const rotated = QuaternionRotateVector(rotation, vector);
|
|
366
|
-
expect(rotated[0]).toBeCloseTo(0, 5);
|
|
367
|
-
expect(rotated[1]).toBeCloseTo(0, 5);
|
|
368
|
-
expect(rotated[2]).toBeCloseTo(-1, 5);
|
|
369
|
-
});
|
|
370
|
-
test('Transformation matrices example', () => {
|
|
371
|
-
const rotation = MatrixRotation3D(0, Math.PI / 4, 0);
|
|
372
|
-
const scale = MatrixScale3D(2, 2, 2);
|
|
373
|
-
const translation = MatrixTranslation3D(10, 5, 0);
|
|
374
|
-
const transform = MatrixMultiply(MatrixMultiply(translation, rotation), scale);
|
|
375
|
-
const point = [1, 0, 0];
|
|
376
|
-
const transformed = MatrixTransform3D(point, transform);
|
|
377
|
-
expect(transformed).toBeDefined();
|
|
378
|
-
expect(transformed.length).toBe(3);
|
|
379
|
-
});
|
|
380
|
-
test('Matrix decompositions example', () => {
|
|
381
|
-
const matrix = [
|
|
382
|
-
[4, 3],
|
|
383
|
-
[6, 3],
|
|
384
|
-
];
|
|
385
|
-
const { L, U } = MatrixLU(matrix);
|
|
386
|
-
const { Q, R } = MatrixQR(matrix);
|
|
387
|
-
const { U: svdU, S, VT } = MatrixSVD(matrix);
|
|
388
|
-
const { eigenvalues, eigenvectors } = MatrixEigen(matrix);
|
|
389
|
-
expect(L).toBeDefined();
|
|
390
|
-
expect(U).toBeDefined();
|
|
391
|
-
expect(Q).toBeDefined();
|
|
392
|
-
expect(R).toBeDefined();
|
|
393
|
-
expect(svdU).toBeDefined();
|
|
394
|
-
expect(S).toBeDefined();
|
|
395
|
-
expect(VT).toBeDefined();
|
|
396
|
-
expect(eigenvalues).toBeDefined();
|
|
397
|
-
expect(eigenvectors).toBeDefined();
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
//# sourceMappingURL=documentation-validation.spec.js.map
|