@flighthq/geometry 0.1.0 → 0.2.1-next.410.a23f189

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 (46) hide show
  1. package/dist/aabb.d.ts +4 -4
  2. package/dist/aabb.d.ts.map +1 -1
  3. package/dist/aabb.js +11 -11
  4. package/dist/aabb.js.map +1 -1
  5. package/dist/boundingSphere.d.ts +5 -5
  6. package/dist/boundingSphere.d.ts.map +1 -1
  7. package/dist/boundingSphere.js +12 -12
  8. package/dist/boundingSphere.js.map +1 -1
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +2 -0
  12. package/dist/index.js.map +1 -1
  13. package/dist/matrix.d.ts +5 -2
  14. package/dist/matrix.d.ts.map +1 -1
  15. package/dist/matrix.js +19 -15
  16. package/dist/matrix.js.map +1 -1
  17. package/dist/matrix3.d.ts +13 -7
  18. package/dist/matrix3.d.ts.map +1 -1
  19. package/dist/matrix3.js +158 -195
  20. package/dist/matrix3.js.map +1 -1
  21. package/dist/matrix4.d.ts.map +1 -1
  22. package/dist/matrix4.js +5 -3
  23. package/dist/matrix4.js.map +1 -1
  24. package/dist/quaternion.d.ts +1 -0
  25. package/dist/quaternion.d.ts.map +1 -1
  26. package/dist/quaternion.js +8 -0
  27. package/dist/quaternion.js.map +1 -1
  28. package/dist/transform2d.d.ts +4 -0
  29. package/dist/transform2d.d.ts.map +1 -0
  30. package/dist/transform2d.js +53 -0
  31. package/dist/transform2d.js.map +1 -0
  32. package/dist/transform3d.d.ts +5 -0
  33. package/dist/transform3d.d.ts.map +1 -0
  34. package/dist/transform3d.js +23 -0
  35. package/dist/transform3d.js.map +1 -0
  36. package/dist/vector3.d.ts +2 -2
  37. package/dist/vector3.js +5 -5
  38. package/package.json +8 -3
  39. package/src/aabb.test.ts +14 -14
  40. package/src/boundingSphere.test.ts +23 -23
  41. package/src/matrix.test.ts +28 -1
  42. package/src/matrix3.test.ts +150 -88
  43. package/src/matrix4.test.ts +23 -0
  44. package/src/quaternion.test.ts +9 -0
  45. package/src/transform2d.test.ts +84 -0
  46. package/src/transform3d.test.ts +50 -0
@@ -0,0 +1,84 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { createMatrix } from './matrix';
4
+ import { createTransform2D, decomposeMatrixToTransform2D } from './transform2d';
5
+
6
+ const DEG_TO_RAD = Math.PI / 180;
7
+
8
+ // Mirrors the display object's forward transform build (recomputeLocalTransform2D) so round-trip
9
+ // tests exercise the exact convention decomposeMatrixToTransform2D inverts.
10
+ function buildMatrix(x: number, y: number, rotation: number, scaleX: number, scaleY: number, skewX = 0, skewY = 0) {
11
+ const radY = (rotation + skewY) * DEG_TO_RAD;
12
+ const radX = (rotation + skewX) * DEG_TO_RAD;
13
+ return createMatrix(
14
+ Math.cos(radY) * scaleX,
15
+ Math.sin(radY) * scaleX,
16
+ -Math.sin(radX) * scaleY,
17
+ Math.cos(radX) * scaleY,
18
+ x,
19
+ y,
20
+ );
21
+ }
22
+
23
+ describe('createTransform2D', () => {
24
+ it('defaults to the identity transform', () => {
25
+ const t = createTransform2D();
26
+ expect(t).toMatchObject({
27
+ pivotX: 0,
28
+ pivotY: 0,
29
+ rotation: 0,
30
+ scaleX: 1,
31
+ scaleY: 1,
32
+ skewX: 0,
33
+ skewY: 0,
34
+ x: 0,
35
+ y: 0,
36
+ });
37
+ });
38
+
39
+ it('accepts positional fields', () => {
40
+ const t = createTransform2D(10, 20, 45, 2, 3);
41
+ expect(t).toMatchObject({ rotation: 45, scaleX: 2, scaleY: 3, x: 10, y: 20 });
42
+ });
43
+ });
44
+
45
+ describe('decomposeMatrixToTransform2D', () => {
46
+ it('decomposes the identity matrix', () => {
47
+ const out = createTransform2D(99, 99, 99, 99, 99, 99, 99);
48
+ decomposeMatrixToTransform2D(out, createMatrix());
49
+ expect(out).toMatchObject({ rotation: 0, scaleX: 1, scaleY: 1, skewX: 0, skewY: 0, x: 0, y: 0 });
50
+ });
51
+
52
+ it('recovers translation and scale', () => {
53
+ const out = createTransform2D();
54
+ decomposeMatrixToTransform2D(out, buildMatrix(5, 7, 0, 2, 3));
55
+ expect(out.x).toBeCloseTo(5);
56
+ expect(out.y).toBeCloseTo(7);
57
+ expect(out.scaleX).toBeCloseTo(2);
58
+ expect(out.scaleY).toBeCloseTo(3);
59
+ });
60
+
61
+ it('recovers a pure rotation with no skew', () => {
62
+ const out = createTransform2D();
63
+ decomposeMatrixToTransform2D(out, buildMatrix(0, 0, 30, 1, 1));
64
+ expect(out.rotation).toBeCloseTo(30);
65
+ expect(out.skewX).toBe(0);
66
+ expect(out.skewY).toBe(0);
67
+ });
68
+
69
+ it('round-trips a skewed transform, folding the angles into skew', () => {
70
+ const out = createTransform2D();
71
+ decomposeMatrixToTransform2D(out, buildMatrix(0, 0, 0, 1, 1, 10, 20));
72
+ expect(out.rotation).toBe(0);
73
+ expect(out.skewX).toBeCloseTo(10);
74
+ expect(out.skewY).toBeCloseTo(20);
75
+ });
76
+
77
+ it('carries a reflection on scaleY', () => {
78
+ const out = createTransform2D();
79
+ // A mirror across X: determinant negative.
80
+ decomposeMatrixToTransform2D(out, createMatrix(1, 0, 0, -1, 0, 0));
81
+ expect(out.scaleX).toBeCloseTo(1);
82
+ expect(out.scaleY).toBeCloseTo(-1);
83
+ });
84
+ });
@@ -0,0 +1,50 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { createMatrix4 } from './matrix4';
4
+ import { createQuaternion } from './quaternion';
5
+ import { composeMatrix4FromTransform3D, createTransform3D, decomposeMatrix4ToTransform3D } from './transform3d';
6
+ import { createVector3 } from './vector3';
7
+
8
+ describe('composeMatrix4FromTransform3D', () => {
9
+ it('composes translation, rotation, and scale into a matrix', () => {
10
+ const t = createTransform3D();
11
+ t.position = createVector3(4, 5, 6);
12
+ t.scale = createVector3(2, 2, 2);
13
+ const out = createMatrix4();
14
+ composeMatrix4FromTransform3D(out, t);
15
+ // Identity rotation + uniform scale 2 + translation (4,5,6): diagonal scale, last column translation.
16
+ expect(out.m[0]).toBeCloseTo(2);
17
+ expect(out.m[5]).toBeCloseTo(2);
18
+ expect(out.m[10]).toBeCloseTo(2);
19
+ expect(out.m[12]).toBeCloseTo(4);
20
+ expect(out.m[13]).toBeCloseTo(5);
21
+ expect(out.m[14]).toBeCloseTo(6);
22
+ });
23
+ });
24
+
25
+ describe('createTransform3D', () => {
26
+ it('defaults to identity: zero translation, identity rotation, unit scale', () => {
27
+ const t = createTransform3D();
28
+ expect(t.position).toMatchObject({ x: 0, y: 0, z: 0 });
29
+ expect(t.rotation).toMatchObject({ x: 0, y: 0, z: 0, w: 1 });
30
+ expect(t.scale).toMatchObject({ x: 1, y: 1, z: 1 });
31
+ });
32
+ });
33
+
34
+ describe('decomposeMatrix4ToTransform3D', () => {
35
+ it('round-trips a shear-free compose', () => {
36
+ const source = createTransform3D();
37
+ source.position = createVector3(1, 2, 3);
38
+ source.rotation = createQuaternion(0, 0, 0, 1);
39
+ source.scale = createVector3(2, 3, 4);
40
+ const m = createMatrix4();
41
+ composeMatrix4FromTransform3D(m, source);
42
+
43
+ const out = createTransform3D();
44
+ decomposeMatrix4ToTransform3D(out, m);
45
+ expect(out.position).toMatchObject({ x: 1, y: 2, z: 3 });
46
+ expect(out.scale.x).toBeCloseTo(2);
47
+ expect(out.scale.y).toBeCloseTo(3);
48
+ expect(out.scale.z).toBeCloseTo(4);
49
+ });
50
+ });