@flighthq/camera 0.5.1-next.3302.76ece6b → 0.5.1-next.4304.322dc96

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 CHANGED
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/camera`. The `@fligh
13
13
  This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
14
14
 
15
15
  - [Flight project](https://github.com/flighthq/flight)
16
- - [Source for @flighthq/camera@0.5.1-next.3302.76ece6b](https://github.com/flighthq/flight/tree/76ece6bee38e3d07816f341b7f017bfcec3e8e29/packages/camera)
17
- - [License](https://github.com/flighthq/flight/blob/76ece6bee38e3d07816f341b7f017bfcec3e8e29/LICENSE.md)
16
+ - [Source for @flighthq/camera@0.5.1-next.4304.322dc96](https://github.com/flighthq/flight/tree/322dc963fc5a404a31bc0cc612e906de504ea024/packages/camera)
17
+ - [License](https://github.com/flighthq/flight/blob/322dc963fc5a404a31bc0cc612e906de504ea024/LICENSE.md)
@@ -1,4 +1,5 @@
1
+ import type { LogState } from '@flighthq/log/contract';
1
2
  export declare function areCameraGuardsEnabled(): boolean;
2
3
  export declare function disableCameraGuards(): void;
3
- export declare function enableCameraGuards(): void;
4
+ export declare function enableCameraGuards(logState: LogState, clock: () => number): void;
4
5
  //# sourceMappingURL=enableCameraGuards.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"enableCameraGuards.d.ts","sourceRoot":"","sources":["../src/enableCameraGuards.ts"],"names":[],"mappings":"AAQA,wBAAgB,sBAAsB,IAAI,OAAO,CAEhD;AAED,wBAAgB,mBAAmB,IAAI,IAAI,CAI1C;AAKD,wBAAgB,kBAAkB,IAAI,IAAI,CAIzC"}
1
+ {"version":3,"file":"enableCameraGuards.d.ts","sourceRoot":"","sources":["../src/enableCameraGuards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AASvD,wBAAgB,sBAAsB,IAAI,OAAO,CAEhD;AAED,wBAAgB,mBAAmB,IAAI,IAAI,CAI1C;AAMD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,MAAM,GAAG,IAAI,CAIhF"}
@@ -13,17 +13,18 @@ export function disableCameraGuards() {
13
13
  }
14
14
  // Installs opt-in diagnostics for camera inputs that leave a computation with no answer. The core
15
15
  // modules stay message-free, so an application that omits this one sheds both the text and
16
- // @flighthq/log.
17
- export function enableCameraGuards() {
18
- setCamera3DViewGuard(warnOnNonOrthonormalCamera3DView);
19
- setCamera2DVisibleBoundsGuard(warnOnDegenerateCamera2DVisibleBounds);
16
+ // @flighthq/log. Warnings go to the caller-owned `logState`, stamped with `clock()` read at the moment of
17
+ // misuse.
18
+ export function enableCameraGuards(logState, clock) {
19
+ setCamera3DViewGuard((camera) => warnOnNonOrthonormalCamera3DView(logState, clock(), camera));
20
+ setCamera2DVisibleBoundsGuard((camera) => warnOnDegenerateCamera2DVisibleBounds(logState, clock(), camera));
20
21
  cameraGuardsEnabled = true;
21
22
  }
22
23
  // The unbounded rectangle is a deliberate fail-toward-drawing, not a silent success: nothing is culled,
23
24
  // so the frame is correct but pays for every object. That is a performance cliff with no visible
24
25
  // symptom, which is exactly the case a guard exists to name.
25
- function warnOnDegenerateCamera2DVisibleBounds(camera) {
26
- logOnce(`camera:degenerate-visible-bounds:${camera.zoom}`, LogLevel.Warn, {
26
+ function warnOnDegenerateCamera2DVisibleBounds(logState, nowMs, camera) {
27
+ logOnce(logState, nowMs, `camera:degenerate-visible-bounds:${camera.zoom}`, LogLevel.Warn, {
27
28
  message: 'getCamera2DVisibleBounds: the view matrix has no inverse, so the visible rectangle is unbounded and nothing is culled — a zoom of 0 is the usual cause; set a non-zero zoom.',
28
29
  zoom: camera.zoom,
29
30
  });
@@ -31,11 +32,11 @@ function warnOnDegenerateCamera2DVisibleBounds(camera) {
31
32
  // Names the CAUSE, not any one consequence: several consumers rely on the orthonormality precondition
32
33
  // and warning once per consumer would be noise. A caller that wants to connect this to a specific wrong
33
34
  // answer has `explainCamera3DView` for the numbers.
34
- function warnOnNonOrthonormalCamera3DView(camera) {
35
+ function warnOnNonOrthonormalCamera3DView(logState, nowMs, camera) {
35
36
  const explanation = explainCamera3DView(camera);
36
37
  if (explanation.isOrthonormal)
37
38
  return;
38
- logOnce('camera:non-orthonormal-view', LogLevel.Warn, {
39
+ logOnce(logState, nowMs, 'camera:non-orthonormal-view', LogLevel.Warn, {
39
40
  message: 'setCamera3DViewMatrix4FromMatrix4: the view matrix is not orthonormal, which its consumers rely on — a scaled matrix is the usual cause. Reflections are fine; scale is not. Call explainCamera3DView(camera) for the measured deviations.',
40
41
  scaleDeviation: explanation.scaleDeviation,
41
42
  shearDeviation: explanation.shearDeviation,
@@ -1 +1 @@
1
- {"version":3,"file":"enableCameraGuards.js","sourceRoot":"","sources":["../src/enableCameraGuards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAEnE,MAAM,UAAU,sBAAsB;IACpC,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAC3B,6BAA6B,CAAC,IAAI,CAAC,CAAC;IACpC,mBAAmB,GAAG,KAAK,CAAC;AAC9B,CAAC;AAED,kGAAkG;AAClG,2FAA2F;AAC3F,iBAAiB;AACjB,MAAM,UAAU,kBAAkB;IAChC,oBAAoB,CAAC,gCAAgC,CAAC,CAAC;IACvD,6BAA6B,CAAC,qCAAqC,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": "@flighthq/camera",
3
- "version": "0.5.1-next.3302.76ece6b",
3
+ "version": "0.5.1-next.4304.322dc96",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,10 +38,10 @@
38
38
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@flighthq/entity": "0.5.1-next.3302.76ece6b",
42
- "@flighthq/geometry": "0.5.1-next.3302.76ece6b",
43
- "@flighthq/log": "0.5.1-next.3302.76ece6b",
44
- "@flighthq/types": "0.5.1-next.3302.76ece6b"
41
+ "@flighthq/entity": "0.5.1-next.4304.322dc96",
42
+ "@flighthq/geometry": "0.5.1-next.4304.322dc96",
43
+ "@flighthq/log": "0.5.1-next.4304.322dc96",
44
+ "@flighthq/types": "0.5.1-next.4304.322dc96"
45
45
  },
46
46
  "devDependencies": {
47
47
  "typescript": "^5.3.0"
@@ -1,7 +1,8 @@
1
1
  import { createMatrix4, createMatrix4FromValues, createRectangle } from '@flighthq/geometry/contract';
2
- import { clearLogOnceKeys, setLogSink } from '@flighthq/log/contract';
3
- import type { Camera2D, LogEntry } from '@flighthq/types/contract';
4
- import { afterEach, describe, expect, test } from 'vitest';
2
+ import type { LogState } from '@flighthq/log/contract';
3
+ import { clearLogOnceKeys, createLogState, getMemoryLogSinkEntries, setLogSink } from '@flighthq/log/contract';
4
+ import type { Camera2D, LogEntry, MemoryLogSink } from '@flighthq/types/contract';
5
+ import { afterEach, beforeEach, describe, expect, test } from 'vitest';
5
6
 
6
7
  import { createCamera3D, setCamera3DViewMatrix4FromMatrix4 } from './camera.ts';
7
8
  import { createCamera2D } from './camera2d.ts';
@@ -9,12 +10,26 @@ import { areCameraGuardsEnabled, disableCameraGuards, enableCameraGuards } from
9
10
  import { createPerspectiveProjection } from './projection.ts';
10
11
  import { getCamera2DVisibleBounds } from './visibleBounds.ts';
11
12
 
12
- beforeEach(() => clearLogOnceKeys());
13
+ function clock(): number {
14
+ return 0;
15
+ }
16
+
17
+ function readLogEntries(sink: Readonly<MemoryLogSink>): LogEntry[] {
18
+ const entries: LogEntry[] = [];
19
+ getMemoryLogSinkEntries(entries, sink);
20
+ return entries;
21
+ }
22
+
23
+ beforeEach(() => {
24
+ logState = createLogState();
25
+ });
26
+
27
+ beforeEach(() => clearLogOnceKeys(logState));
13
28
 
14
29
  describe('areCameraGuardsEnabled', () => {
15
30
  test('reports whether the guards are installed', () => {
16
31
  expect(areCameraGuardsEnabled()).toBe(false);
17
- enableCameraGuards();
32
+ enableCameraGuards(logState, clock);
18
33
  expect(areCameraGuardsEnabled()).toBe(true);
19
34
  disableCameraGuards();
20
35
  expect(areCameraGuardsEnabled()).toBe(false);
@@ -23,7 +38,7 @@ describe('areCameraGuardsEnabled', () => {
23
38
 
24
39
  describe('disableCameraGuards', () => {
25
40
  test('leaves the core silent again once removed', () => {
26
- enableCameraGuards();
41
+ enableCameraGuards(logState, clock);
27
42
  disableCameraGuards();
28
43
  expect(captureLog(() => getCamera2DVisibleBounds(degenerateCamera(), 64, 64, createRectangle()))).toHaveLength(0);
29
44
  });
@@ -34,7 +49,7 @@ describe('enableCameraGuards', () => {
34
49
  // degenerate key — a second would be deduplicated away and assert nothing. The seam itself is tested
35
50
  // directly, and deterministically, in visibleBounds.test.ts.
36
51
  test('warns, naming the zoom and the consequence, when the visible bounds cannot be computed', () => {
37
- enableCameraGuards();
52
+ enableCameraGuards(logState, clock);
38
53
  const entries = captureLog(() => getCamera2DVisibleBounds(degenerateCamera(), 64, 64, createRectangle()));
39
54
  expect(entries).toHaveLength(1);
40
55
  expect(entries[0].data).toMatchObject({ zoom: 0 });
@@ -42,7 +57,7 @@ describe('enableCameraGuards', () => {
42
57
  });
43
58
 
44
59
  test('warns on a non-orthonormal 3D view, naming the cause rather than a consumer', () => {
45
- enableCameraGuards();
60
+ enableCameraGuards(logState, clock);
46
61
  const entries = captureLog(() => {
47
62
  const camera = createCamera3D({
48
63
  far: 100,
@@ -61,7 +76,7 @@ describe('enableCameraGuards', () => {
61
76
  // Reflections satisfy the precondition, so warning on them would be a false positive on a legitimate
62
77
  // water/mirror camera.
63
78
  test('stays silent for a reflection view', () => {
64
- enableCameraGuards();
79
+ enableCameraGuards(logState, clock);
65
80
  const entries = captureLog(() => {
66
81
  const camera = createCamera3D({
67
82
  far: 100,
@@ -77,7 +92,7 @@ describe('enableCameraGuards', () => {
77
92
  });
78
93
 
79
94
  test('stays silent for a camera whose view matrix inverts', () => {
80
- enableCameraGuards();
95
+ enableCameraGuards(logState, clock);
81
96
  expect(captureLog(() => getCamera2DVisibleBounds(createCamera2D(), 64, 64, createRectangle()))).toHaveLength(0);
82
97
  });
83
98
  });
@@ -88,11 +103,11 @@ afterEach(() => {
88
103
 
89
104
  function captureLog(run: () => void): LogEntry[] {
90
105
  const entries: LogEntry[] = [];
91
- setLogSink((entry) => entries.push(entry));
106
+ setLogSink(logState, (entry) => entries.push(entry));
92
107
  try {
93
108
  run();
94
109
  } finally {
95
- setLogSink(null);
110
+ setLogSink(logState, null);
96
111
  }
97
112
  return entries;
98
113
  }
@@ -100,3 +115,5 @@ function captureLog(run: () => void): LogEntry[] {
100
115
  function degenerateCamera(): Camera2D {
101
116
  return createCamera2D({ zoom: 0 });
102
117
  }
118
+
119
+ let logState: LogState = createLogState();