@flighthq/spatial 0.3.0-next.906.07cea63 → 0.3.1-next.209.43ef1bc
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/dist/contract.d.ts +2 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +2 -0
- package/dist/contract.js.map +1 -1
- package/dist/explainSpatialIndexing.d.ts +3 -0
- package/dist/explainSpatialIndexing.d.ts.map +1 -0
- package/dist/explainSpatialIndexing.js +14 -0
- package/dist/explainSpatialIndexing.js.map +1 -0
- package/dist/formatSpatialIndexingNotice.d.ts +3 -0
- package/dist/formatSpatialIndexingNotice.d.ts.map +1 -0
- package/dist/formatSpatialIndexingNotice.js +38 -0
- package/dist/formatSpatialIndexingNotice.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/spatialIndex.d.ts +2 -2
- package/dist/spatialIndex.d.ts.map +1 -1
- package/dist/spatialIndex.js +9 -3
- package/dist/spatialIndex.js.map +1 -1
- package/dist/uniformGrid.d.ts +3 -1
- package/dist/uniformGrid.d.ts.map +1 -1
- package/dist/uniformGrid.js +254 -31
- package/dist/uniformGrid.js.map +1 -1
- package/package.json +5 -3
- package/src/explainSpatialIndexing.test.ts +76 -0
- package/src/formatSpatialIndexingNotice.test.ts +116 -0
- package/src/uniformGrid.test.ts +713 -3
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { SpatialIndexingNotice } from '@flighthq/types/contract';
|
|
2
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { formatSpatialIndexingNotice } from './formatSpatialIndexingNotice';
|
|
5
|
+
import { MAX_INDEXED_CELLS_PER_OBJECT, createUniformGridSpatialBackend, setSpatialIndexingGuard } from './uniformGrid';
|
|
6
|
+
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
setSpatialIndexingGuard(null);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('formatSpatialIndexingNotice', () => {
|
|
12
|
+
it('names the sentinel to check for a decline', () => {
|
|
13
|
+
const message = formatSpatialIndexingNotice({
|
|
14
|
+
cellSize: 10,
|
|
15
|
+
id: 3,
|
|
16
|
+
mode: 'declined',
|
|
17
|
+
operation: 'insert',
|
|
18
|
+
reason: 'non-finite-bounds',
|
|
19
|
+
wouldOccupyBucketCount: 0,
|
|
20
|
+
});
|
|
21
|
+
expect(message).toContain('insertSpatialObject(3)');
|
|
22
|
+
expect(message).toContain('not finite');
|
|
23
|
+
expect(message).toContain('returns false');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('names the span and the cell-size cause for an overflow, without calling it wrong', () => {
|
|
27
|
+
const message = formatSpatialIndexingNotice({
|
|
28
|
+
cellSize: 1,
|
|
29
|
+
id: 4,
|
|
30
|
+
mode: 'overflow',
|
|
31
|
+
operation: 'insert',
|
|
32
|
+
reason: null,
|
|
33
|
+
wouldOccupyBucketCount: 40000,
|
|
34
|
+
});
|
|
35
|
+
expect(message).toContain('insertSpatialObject(4)');
|
|
36
|
+
expect(message).toContain('40000 cells');
|
|
37
|
+
expect(message).toContain(`${MAX_INDEXED_CELLS_PER_OBJECT} per-object budget`);
|
|
38
|
+
expect(message).toContain('cellSize is too small');
|
|
39
|
+
// Overflow is a cost decision, not a wrong answer, and the message must not imply otherwise.
|
|
40
|
+
expect(message).toContain('Results are unaffected');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('explains invalid cell sizes, inverted bounds, and missing ids', () => {
|
|
44
|
+
expect(
|
|
45
|
+
formatSpatialIndexingNotice({
|
|
46
|
+
cellSize: 0,
|
|
47
|
+
id: 1,
|
|
48
|
+
mode: 'overflow',
|
|
49
|
+
operation: 'insert',
|
|
50
|
+
reason: 'invalid-cell-size',
|
|
51
|
+
wouldOccupyBucketCount: 0,
|
|
52
|
+
}),
|
|
53
|
+
).toContain('cellSize must be a positive finite number');
|
|
54
|
+
expect(
|
|
55
|
+
formatSpatialIndexingNotice({
|
|
56
|
+
cellSize: 10,
|
|
57
|
+
id: 2,
|
|
58
|
+
mode: 'declined',
|
|
59
|
+
operation: 'update',
|
|
60
|
+
reason: 'inverted-bounds',
|
|
61
|
+
wouldOccupyBucketCount: 0,
|
|
62
|
+
}),
|
|
63
|
+
).toContain('minX/minY must not exceed maxX/maxY');
|
|
64
|
+
expect(
|
|
65
|
+
formatSpatialIndexingNotice({
|
|
66
|
+
cellSize: 10,
|
|
67
|
+
id: 3,
|
|
68
|
+
mode: 'absent',
|
|
69
|
+
operation: 'remove',
|
|
70
|
+
reason: 'missing-id',
|
|
71
|
+
wouldOccupyBucketCount: 0,
|
|
72
|
+
}),
|
|
73
|
+
).toContain('removal was a no-op');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('says plainly that a mode it does not cover carries no advice', () => {
|
|
77
|
+
expect(
|
|
78
|
+
formatSpatialIndexingNotice({
|
|
79
|
+
cellSize: 10,
|
|
80
|
+
id: 5,
|
|
81
|
+
mode: 'cells',
|
|
82
|
+
operation: 'insert',
|
|
83
|
+
reason: null,
|
|
84
|
+
wouldOccupyBucketCount: 4,
|
|
85
|
+
}),
|
|
86
|
+
).toContain('no caller-facing advice');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('formats what the grid actually hands a guard', () => {
|
|
90
|
+
// Pins the two halves together: a record produced by a real insert, rendered by this formatter.
|
|
91
|
+
const notices: SpatialIndexingNotice[] = [];
|
|
92
|
+
setSpatialIndexingGuard((notice) => notices.push({ ...notice }));
|
|
93
|
+
const grid = createUniformGridSpatialBackend(1);
|
|
94
|
+
grid.insertSpatialObject(9, { minX: 0, minY: 0, maxX: 199, maxY: 199 });
|
|
95
|
+
grid.insertSpatialObject(10, { minX: NaN, minY: 0, maxX: 1, maxY: 1 });
|
|
96
|
+
expect(notices.map(formatSpatialIndexingNotice)).toEqual([
|
|
97
|
+
formatSpatialIndexingNotice({
|
|
98
|
+
cellSize: 1,
|
|
99
|
+
id: 9,
|
|
100
|
+
mode: 'overflow',
|
|
101
|
+
operation: 'insert',
|
|
102
|
+
reason: null,
|
|
103
|
+
wouldOccupyBucketCount: 40000,
|
|
104
|
+
}),
|
|
105
|
+
formatSpatialIndexingNotice({
|
|
106
|
+
cellSize: 1,
|
|
107
|
+
id: 10,
|
|
108
|
+
mode: 'declined',
|
|
109
|
+
operation: 'insert',
|
|
110
|
+
reason: 'non-finite-bounds',
|
|
111
|
+
wouldOccupyBucketCount: 0,
|
|
112
|
+
}),
|
|
113
|
+
]);
|
|
114
|
+
expect(notices.map(formatSpatialIndexingNotice)[0]).toContain('40000 cells');
|
|
115
|
+
});
|
|
116
|
+
});
|