@flighthq/geometry 0.5.1-next.920.da8f530 → 0.6.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 (159) hide show
  1. package/README.md +2 -2
  2. package/dist/.tsbuildinfo.contract +1 -0
  3. package/dist/.tsbuildinfo.runtime +1 -0
  4. package/dist/aabb.d.ts +2 -1
  5. package/dist/aabb.d.ts.map +1 -1
  6. package/dist/aabb.js +3 -3
  7. package/dist/aabb.js.map +1 -1
  8. package/dist/boundingSphere.d.ts +2 -1
  9. package/dist/boundingSphere.d.ts.map +1 -1
  10. package/dist/boundingSphere.js +3 -3
  11. package/dist/boundingSphere.js.map +1 -1
  12. package/dist/capsule.d.ts +2 -1
  13. package/dist/capsule.d.ts.map +1 -1
  14. package/dist/capsule.js +2 -2
  15. package/dist/capsule.js.map +1 -1
  16. package/dist/contract.d.ts +2 -44
  17. package/dist/contract.d.ts.map +1 -1
  18. package/dist/contract.geometry-types.d.ts +2 -0
  19. package/dist/contract.geometry-types.d.ts.map +1 -0
  20. package/dist/contract.geometry-types.js +4 -0
  21. package/dist/contract.geometry-types.js.map +1 -0
  22. package/dist/contract.js +2 -44
  23. package/dist/contract.js.map +1 -1
  24. package/dist/enableGeometryPoolGuards.d.ts +10 -1
  25. package/dist/enableGeometryPoolGuards.d.ts.map +1 -1
  26. package/dist/enableGeometryPoolGuards.js +56 -23
  27. package/dist/enableGeometryPoolGuards.js.map +1 -1
  28. package/dist/frustum.d.ts +2 -1
  29. package/dist/frustum.d.ts.map +1 -1
  30. package/dist/frustum.js +3 -3
  31. package/dist/frustum.js.map +1 -1
  32. package/dist/geometryPoolGuards.d.ts +3 -3
  33. package/dist/geometryPoolGuards.d.ts.map +1 -1
  34. package/dist/geometryPoolGuards.js +3 -0
  35. package/dist/geometryPoolGuards.js.map +1 -1
  36. package/dist/index.d.ts +28 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +27 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/matrix.d.ts +3 -1
  41. package/dist/matrix.d.ts.map +1 -1
  42. package/dist/matrix.js +3 -2
  43. package/dist/matrix.js.map +1 -1
  44. package/dist/matrix3.d.ts +6 -4
  45. package/dist/matrix3.d.ts.map +1 -1
  46. package/dist/matrix3.js +13 -27
  47. package/dist/matrix3.js.map +1 -1
  48. package/dist/matrix3Pool.d.ts +1 -1
  49. package/dist/matrix3Pool.d.ts.map +1 -1
  50. package/dist/matrix3Pool.js +4 -4
  51. package/dist/matrix3Pool.js.map +1 -1
  52. package/dist/matrix4.d.ts +5 -3
  53. package/dist/matrix4.d.ts.map +1 -1
  54. package/dist/matrix4.js +12 -40
  55. package/dist/matrix4.js.map +1 -1
  56. package/dist/matrix4Pool.d.ts +1 -1
  57. package/dist/matrix4Pool.d.ts.map +1 -1
  58. package/dist/matrix4Pool.js +4 -4
  59. package/dist/matrix4Pool.js.map +1 -1
  60. package/dist/matrixPool.d.ts +1 -1
  61. package/dist/matrixPool.d.ts.map +1 -1
  62. package/dist/matrixPool.js +4 -4
  63. package/dist/matrixPool.js.map +1 -1
  64. package/dist/obb.d.ts +2 -1
  65. package/dist/obb.d.ts.map +1 -1
  66. package/dist/obb.js +2 -2
  67. package/dist/obb.js.map +1 -1
  68. package/dist/plane.d.ts +2 -1
  69. package/dist/plane.d.ts.map +1 -1
  70. package/dist/plane.js +2 -2
  71. package/dist/plane.js.map +1 -1
  72. package/dist/quaternion.d.ts +2 -1
  73. package/dist/quaternion.d.ts.map +1 -1
  74. package/dist/quaternion.js +2 -2
  75. package/dist/quaternion.js.map +1 -1
  76. package/dist/quaternionPool.d.ts +1 -1
  77. package/dist/quaternionPool.d.ts.map +1 -1
  78. package/dist/quaternionPool.js +4 -4
  79. package/dist/quaternionPool.js.map +1 -1
  80. package/dist/ray3d.d.ts +2 -1
  81. package/dist/ray3d.d.ts.map +1 -1
  82. package/dist/ray3d.js +3 -3
  83. package/dist/ray3d.js.map +1 -1
  84. package/dist/rectangle.d.ts +2 -1
  85. package/dist/rectangle.d.ts.map +1 -1
  86. package/dist/rectangle.js +2 -2
  87. package/dist/rectangle.js.map +1 -1
  88. package/dist/rectanglePool.d.ts +1 -1
  89. package/dist/rectanglePool.d.ts.map +1 -1
  90. package/dist/rectanglePool.js +4 -4
  91. package/dist/rectanglePool.js.map +1 -1
  92. package/dist/runtime.d.ts +29 -0
  93. package/dist/runtime.d.ts.map +1 -0
  94. package/dist/runtime.js +29 -0
  95. package/dist/runtime.js.map +1 -0
  96. package/dist/transform2d.d.ts +2 -1
  97. package/dist/transform2d.d.ts.map +1 -1
  98. package/dist/transform2d.js +2 -2
  99. package/dist/transform2d.js.map +1 -1
  100. package/dist/transform3d.d.ts +2 -1
  101. package/dist/transform3d.d.ts.map +1 -1
  102. package/dist/transform3d.js +5 -5
  103. package/dist/transform3d.js.map +1 -1
  104. package/dist/types.d.ts +145 -0
  105. package/dist/types.d.ts.map +1 -0
  106. package/dist/types.js +2 -0
  107. package/dist/types.js.map +1 -0
  108. package/dist/vector2.d.ts +2 -1
  109. package/dist/vector2.d.ts.map +1 -1
  110. package/dist/vector2.js +2 -2
  111. package/dist/vector2.js.map +1 -1
  112. package/dist/vector2Pool.d.ts +1 -1
  113. package/dist/vector2Pool.d.ts.map +1 -1
  114. package/dist/vector2Pool.js +4 -4
  115. package/dist/vector2Pool.js.map +1 -1
  116. package/dist/vector3.d.ts +2 -1
  117. package/dist/vector3.d.ts.map +1 -1
  118. package/dist/vector3.js +2 -2
  119. package/dist/vector3.js.map +1 -1
  120. package/dist/vector3Pool.d.ts +1 -1
  121. package/dist/vector3Pool.d.ts.map +1 -1
  122. package/dist/vector3Pool.js +4 -4
  123. package/dist/vector3Pool.js.map +1 -1
  124. package/dist/vector4.d.ts +2 -1
  125. package/dist/vector4.d.ts.map +1 -1
  126. package/dist/vector4.js +2 -2
  127. package/dist/vector4.js.map +1 -1
  128. package/dist/vector4Pool.d.ts +1 -1
  129. package/dist/vector4Pool.d.ts.map +1 -1
  130. package/dist/vector4Pool.js +4 -4
  131. package/dist/vector4Pool.js.map +1 -1
  132. package/package.json +7 -6
  133. package/src/aabb.test.ts +3 -2
  134. package/src/boundingSphere.test.ts +4 -3
  135. package/src/capsule.test.ts +1 -1
  136. package/src/enableGeometryPoolGuards.test.ts +31 -24
  137. package/src/frustum.test.ts +5 -4
  138. package/src/geometryPoolGuards.test.ts +14 -1
  139. package/src/matrix.test.ts +2 -2
  140. package/src/matrix3.test.ts +59 -63
  141. package/src/matrix3Pool.test.ts +2 -2
  142. package/src/matrix4.test.ts +42 -51
  143. package/src/matrix4Pool.test.ts +2 -2
  144. package/src/matrixPool.test.ts +2 -2
  145. package/src/obb.test.ts +7 -5
  146. package/src/plane.test.ts +1 -1
  147. package/src/quaternion.test.ts +2 -2
  148. package/src/ray3d.test.ts +8 -8
  149. package/src/rectangle.test.ts +2 -2
  150. package/src/rectanglePool.test.ts +2 -2
  151. package/src/transform2d.test.ts +2 -2
  152. package/src/transform3d.test.ts +4 -4
  153. package/src/typedarray.test.ts +1 -1
  154. package/src/vector2.test.ts +2 -2
  155. package/src/vector2Pool.test.ts +2 -2
  156. package/src/vector3.test.ts +2 -2
  157. package/src/vector3Pool.test.ts +2 -2
  158. package/src/vector4.test.ts +2 -2
  159. package/src/vector4Pool.test.ts +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/geometry",
3
- "version": "0.5.1-next.920.da8f530",
3
+ "version": "0.6.0",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -32,19 +32,20 @@
32
32
  "scripts": {
33
33
  "build": "tsc -b",
34
34
  "clean": "tsc -b --clean",
35
+ "generate": "tsx ../../scripts/generate-rust-package.ts --crate flight-geometry --package geometry",
36
+ "generate:check": "tsx ../../scripts/generate-rust-package.ts --crate flight-geometry --package geometry --check",
35
37
  "test": "vitest run --config vitest.config.ts",
36
38
  "test:watch": "vitest --watch --config vitest.config.ts",
37
39
  "prepack": "npm run clean && npm run clean:dist && npm run build",
38
40
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
41
  },
40
42
  "dependencies": {
41
- "@flighthq/entity": "0.5.1-next.920.da8f530",
42
- "@flighthq/log": "0.5.1-next.920.da8f530",
43
- "@flighthq/math": "0.5.1-next.920.da8f530",
44
- "@flighthq/types": "0.5.1-next.920.da8f530"
43
+ "@flighthq/entity": "0.6.0",
44
+ "@flighthq/log": "0.6.0",
45
+ "@flighthq/math": "0.6.0"
45
46
  },
46
47
  "devDependencies": {
47
- "typescript": "^5.3.0"
48
+ "typescript": "^7.0.2"
48
49
  },
49
50
  "description": "2D/3D math primitives: vectors, matrices, rectangles, and object pools",
50
51
  "sideEffects": false
package/src/aabb.test.ts CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  createAabb,
5
5
  createBoundingSphere,
6
6
  createMatrix4,
7
+ createMatrix4FromValues,
7
8
  createVector3,
8
9
  expandAabbByPoint,
9
10
  expandAabbBySphere,
@@ -22,7 +23,7 @@ import {
22
23
  unionAabb,
23
24
  } from '@flighthq/geometry/contract';
24
25
 
25
- import { initializeAabb } from './aabb';
26
+ import { initializeAabb } from './aabb.ts';
26
27
 
27
28
  describe('cloneAabb', () => {
28
29
  it('creates an independent copy with independent corner vectors', () => {
@@ -351,7 +352,7 @@ describe('transformAabbByMatrix4', () => {
351
352
  const a = createAabb(-1, -1, -1, 1, 1, 1);
352
353
  // Column-major 45-degree z rotation.
353
354
  const c = Math.SQRT1_2;
354
- const m = createMatrix4(c, c, 0, 0, -c, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
355
+ const m = createMatrix4FromValues(c, c, 0, 0, -c, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
355
356
  const out = createAabb();
356
357
  transformAabbByMatrix4(out, a, m);
357
358
  // Rotated unit box spans +/- sqrt(2) in x and y.
@@ -4,6 +4,7 @@ import {
4
4
  createAabb,
5
5
  createBoundingSphere,
6
6
  createMatrix4,
7
+ createMatrix4FromValues,
7
8
  createVector3,
8
9
  containsBoundingSpherePoint,
9
10
  getClosestPointOnBoundingSphere,
@@ -15,7 +16,7 @@ import {
15
16
  transformBoundingSphereByMatrix4,
16
17
  } from '@flighthq/geometry/contract';
17
18
 
18
- import { initializeBoundingSphere } from './boundingSphere';
19
+ import { initializeBoundingSphere } from './boundingSphere.ts';
19
20
 
20
21
  describe('cloneBoundingSphere', () => {
21
22
  it('creates an independent copy with an independent center', () => {
@@ -264,7 +265,7 @@ describe('transformBoundingSphereByMatrix4', () => {
264
265
  it('scales the radius by the largest axis scale', () => {
265
266
  const s = createBoundingSphere(0, 0, 0, 1);
266
267
  // Column-major non-uniform scale diag(2,3,4).
267
- const m = createMatrix4(2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4, 0, 0, 0, 0, 1);
268
+ const m = createMatrix4FromValues(2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 4, 0, 0, 0, 0, 1);
268
269
  const out = createBoundingSphere();
269
270
  transformBoundingSphereByMatrix4(out, s, m);
270
271
  expect(out.radius).toBeCloseTo(4, 6);
@@ -285,7 +286,7 @@ describe('transformBoundingSphereByMatrix4', () => {
285
286
  // move it further from zero and, under a scale below 1, could carry it up past zero into a
286
287
  // real sphere that was never there.
287
288
  const empty = createBoundingSphere(0, 0, 0, -1);
288
- const m = createMatrix4(3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1);
289
+ const m = createMatrix4FromValues(3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1);
289
290
  const out = createBoundingSphere();
290
291
  transformBoundingSphereByMatrix4(out, empty, m);
291
292
  expect(out.radius).toBe(-1);
@@ -12,7 +12,7 @@ import {
12
12
  setCapsule,
13
13
  } from '@flighthq/geometry/contract';
14
14
 
15
- import { initializeCapsule } from './capsule';
15
+ import { initializeCapsule } from './capsule.ts';
16
16
 
17
17
  describe('createCapsule', () => {
18
18
  it('stores all fields', () => {
@@ -1,35 +1,40 @@
1
+ import type { LogState } from '@flighthq/log/contract';
1
2
  import {
2
3
  addLogSink,
3
- clearLogOnceKeys,
4
+ clearMemoryLogSink,
5
+ createLogState,
4
6
  createMemoryLogSink,
5
7
  getMemoryLogSinkEntries,
6
- removeLogSink,
7
8
  } from '@flighthq/log/contract';
8
- import type { LogEntry } from '@flighthq/types/contract';
9
+ import type { LogEntry } from '@flighthq/log/contract';
9
10
 
10
11
  import {
11
12
  areGeometryPoolGuardsEnabled,
12
13
  disableGeometryPoolGuards,
13
14
  enableGeometryPoolGuards,
14
- } from './enableGeometryPoolGuards';
15
- import { acquireMatrix3, clearMatrix3Pool, releaseMatrix3 } from './matrix3Pool';
16
- import { acquireMatrix4, clearMatrix4Pool, releaseMatrix4 } from './matrix4Pool';
17
- import { acquireMatrix, clearMatrixPool, releaseMatrix } from './matrixPool';
18
- import { acquireQuaternion, clearQuaternionPool, releaseQuaternion } from './quaternionPool';
19
- import { acquireRectangle, clearRectanglePool, releaseRectangle } from './rectanglePool';
20
- import { acquireVector2, clearVector2Pool, releaseVector2 } from './vector2Pool';
21
- import { acquireVector3, clearVector3Pool, releaseVector3 } from './vector3Pool';
22
- import { acquireVector4, clearVector4Pool, releaseVector4 } from './vector4Pool';
15
+ } from './enableGeometryPoolGuards.ts';
16
+ import { acquireMatrix3, clearMatrix3Pool, releaseMatrix3 } from './matrix3Pool.ts';
17
+ import { acquireMatrix4, clearMatrix4Pool, releaseMatrix4 } from './matrix4Pool.ts';
18
+ import { acquireMatrix, clearMatrixPool, releaseMatrix } from './matrixPool.ts';
19
+ import { acquireQuaternion, clearQuaternionPool, releaseQuaternion } from './quaternionPool.ts';
20
+ import { acquireRectangle, clearRectanglePool, releaseRectangle } from './rectanglePool.ts';
21
+ import { acquireVector2, clearVector2Pool, releaseVector2 } from './vector2Pool.ts';
22
+ import { acquireVector3, clearVector3Pool, releaseVector3 } from './vector3Pool.ts';
23
+ import { acquireVector4, clearVector4Pool, releaseVector4 } from './vector4Pool.ts';
23
24
 
25
+ // Each test gets its own caller-owned log state, so once-keys never leak between tests.
24
26
  function captureLog(run: () => void): readonly LogEntry[] {
25
27
  const sink = createMemoryLogSink(16);
26
- addLogSink(sink.sink);
27
- try {
28
- run();
29
- return getMemoryLogSinkEntries(sink);
30
- } finally {
31
- removeLogSink(sink.sink);
32
- }
28
+ addLogSink(logState, sink.sink);
29
+ run();
30
+ const entries: LogEntry[] = [];
31
+ getMemoryLogSinkEntries(entries, sink);
32
+ clearMemoryLogSink(sink);
33
+ return entries;
34
+ }
35
+
36
+ function clock(): number {
37
+ return 0;
33
38
  }
34
39
 
35
40
  function clearPools(): void {
@@ -55,7 +60,7 @@ function messageOf(entry: Readonly<LogEntry>): string {
55
60
  }
56
61
 
57
62
  beforeEach(() => {
58
- clearLogOnceKeys();
63
+ logState = createLogState();
59
64
  clearPools();
60
65
  });
61
66
 
@@ -67,7 +72,7 @@ afterEach(() => {
67
72
  describe('areGeometryPoolGuardsEnabled', () => {
68
73
  it('reports whether the pool release diagnostic is installed', () => {
69
74
  expect(areGeometryPoolGuardsEnabled()).toBe(false);
70
- enableGeometryPoolGuards();
75
+ enableGeometryPoolGuards(logState, clock);
71
76
  expect(areGeometryPoolGuardsEnabled()).toBe(true);
72
77
  disableGeometryPoolGuards();
73
78
  expect(areGeometryPoolGuardsEnabled()).toBe(false);
@@ -76,7 +81,7 @@ describe('areGeometryPoolGuardsEnabled', () => {
76
81
 
77
82
  describe('disableGeometryPoolGuards', () => {
78
83
  it('restores the production-default silent release path', () => {
79
- enableGeometryPoolGuards();
84
+ enableGeometryPoolGuards(logState, clock);
80
85
  disableGeometryPoolGuards();
81
86
  const entries = captureLog(() => doubleRelease(acquireVector2, releaseVector2));
82
87
  expect(entries).toHaveLength(0);
@@ -84,9 +89,9 @@ describe('disableGeometryPoolGuards', () => {
84
89
  });
85
90
 
86
91
  describe('enableGeometryPoolGuards', () => {
87
- // ONE firing test deliberately consumes all eight process-lifetime logOnce keys.
92
+ // ONE firing test deliberately consumes all eight logOnce keys of this test's log state.
88
93
  it('warns once for a double release from every geometry pool and stays silent for valid brackets', () => {
89
- enableGeometryPoolGuards();
94
+ enableGeometryPoolGuards(logState, clock);
90
95
 
91
96
  const pairedEntries = captureLog(() => {
92
97
  releaseMatrix(acquireMatrix());
@@ -128,3 +133,5 @@ describe('enableGeometryPoolGuards', () => {
128
133
  }
129
134
  });
130
135
  });
136
+
137
+ let logState: LogState = createLogState();
@@ -3,6 +3,7 @@ import {
3
3
  createBoundingSphere,
4
4
  createFrustum,
5
5
  createMatrix4,
6
+ createMatrix4FromValues,
6
7
  createPerspectiveMatrix4,
7
8
  createVector3,
8
9
  getFrustumCorners,
@@ -16,9 +17,9 @@ import {
16
17
  setFrustumFromMatrix4,
17
18
  setMatrix4LookAt,
18
19
  } from '@flighthq/geometry/contract';
19
- import type { Matrix4 } from '@flighthq/types/contract';
20
20
 
21
- import { initializeFrustum } from './frustum';
21
+ import { initializeFrustum } from './frustum.ts';
22
+ import type { Matrix4 } from './types.ts';
22
23
 
23
24
  // View-projection for a camera at (0,0,5) looking toward the origin down -z.
24
25
  function createTestViewProjection(): Matrix4 {
@@ -89,7 +90,7 @@ describe('getFrustumCorners', () => {
89
90
  // point at infinity. Passing the coordinates through undivided keeps the corner finite, so a
90
91
  // caller fitting bounds around these corners gets a wrong box rather than an infinite one.
91
92
  const corners = Array.from({ length: 8 }, () => createVector3());
92
- getFrustumCorners(corners, createMatrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0));
93
+ getFrustumCorners(corners, createMatrix4FromValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0));
93
94
  for (const corner of corners) {
94
95
  expect(Number.isFinite(corner.x)).toBe(true);
95
96
  expect(Number.isFinite(corner.y)).toBe(true);
@@ -219,7 +220,7 @@ describe('setFrustumFromMatrix4', () => {
219
220
  // culls against this frustum gets consistent rejections instead of NaN comparisons, which are
220
221
  // false in both directions and would let a box pass and fail the same test.
221
222
  const f = createFrustum();
222
- setFrustumFromMatrix4(f, createMatrix4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
223
+ setFrustumFromMatrix4(f, createMatrix4FromValues(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
223
224
  for (const plane of [f.near, f.far, f.left, f.right, f.top, f.bottom]) {
224
225
  expect(Number.isFinite(plane.a)).toBe(true);
225
226
  expect(Number.isFinite(plane.b)).toBe(true);
@@ -1,9 +1,22 @@
1
- import { geometryPoolReleaseGuard, setGeometryPoolReleaseGuard } from './geometryPoolGuards';
1
+ import {
2
+ geometryPoolReleaseGuard,
3
+ getGeometryPoolReleaseGuard,
4
+ setGeometryPoolReleaseGuard,
5
+ } from './geometryPoolGuards.ts';
2
6
 
3
7
  afterEach(() => {
4
8
  setGeometryPoolReleaseGuard(null);
5
9
  });
6
10
 
11
+ describe('getGeometryPoolReleaseGuard', () => {
12
+ it('reads the installed release callback, or null when none is installed', () => {
13
+ expect(getGeometryPoolReleaseGuard()).toBeNull();
14
+ const guard = (): void => {};
15
+ setGeometryPoolReleaseGuard(guard);
16
+ expect(getGeometryPoolReleaseGuard()).toBe(guard);
17
+ });
18
+ });
19
+
7
20
  describe('setGeometryPoolReleaseGuard', () => {
8
21
  it('installs and removes the internal release callback', () => {
9
22
  const guard = (): void => {};
@@ -41,9 +41,9 @@ import {
41
41
  translateMatrixByVectorXY,
42
42
  writeMatrixToFloat32Array,
43
43
  } from '@flighthq/geometry/contract';
44
- import type { Matrix, Matrix3Like, Matrix4Like } from '@flighthq/types/contract';
45
44
 
46
- import { initializeMatrix } from './matrix';
45
+ import { initializeMatrix } from './matrix.ts';
46
+ import type { Matrix, Matrix3Like, Matrix4Like } from './types.ts';
47
47
 
48
48
  describe('cloneMatrix', () => {
49
49
  it('should clone the matrix3x2 correctly', () => {