Skip to content

Commit 036f8ef

Browse files
committed
test(engine): half-cell grid-offset calibration via mid-edge symmetry
Review follow-up: the lone-sample calibration test exercises the fallback circle at tiny budgets, so it can't detect a systematic contour-transform offset. A mid-edge origin must produce a symmetric polygon; tolerance sits between measured discretization noise (~20m) and the half-cell failure signature (~60m).
1 parent b0379fe commit 036f8ef

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

packages/engine/src/__tests__/polygonize.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,31 @@ describe('polygonize', () => {
6767
expect(Math.abs(cLat - 32.08)).toBeLessThan(0.0007);
6868
});
6969

70+
it('is symmetric around a mid-edge origin (detects half-cell grid offset)', () => {
71+
// From the exact midpoint with a 60 s budget the reachable stretch is
72+
// symmetric east/west, so the contoured polygon must be too. A systematic
73+
// half-cell (30 m) transform offset shifts BOTH frontiers the same way,
74+
// producing ~60 m of east/west asymmetry; raster + simplify noise measures
75+
// ~20 m. The 38 m tolerance sits between the two, so this fails on a real
76+
// transform bug but not on discretization jitter. (The lone-sample test
77+
// above can't catch offsets: tiny budgets fall back to the origin circle.)
78+
const mid: [number, number] = [34.7821, 32.08];
79+
const { result } = isoOn(LINE, mid, 60);
80+
expect(result.degraded).toBe(false);
81+
const coords = (
82+
result.polygon.type === 'Polygon' ? result.polygon.coordinates : result.polygon.coordinates.flat()
83+
).flat();
84+
const lngs = coords.map((c) => c[0]!);
85+
const lats = coords.map((c) => c[1]!);
86+
const eastReach = Math.max(...lngs) - mid[0];
87+
const westReach = mid[0] - Math.min(...lngs);
88+
const northReach = Math.max(...lats) - mid[1];
89+
const southReach = mid[1] - Math.min(...lats);
90+
const tolDeg = 0.0004; // ~38 m — above noise (~20 m), below half-cell signature (~60 m)
91+
expect(Math.abs(eastReach - westReach)).toBeLessThan(tolDeg);
92+
expect(Math.abs(northReach - southReach)).toBeLessThan(tolDeg);
93+
});
94+
7095
it('is deterministic', () => {
7196
const a = isoOn(LINE, [34.781, 32.08], 120).result;
7297
const b = isoOn(LINE, [34.781, 32.08], 120).result;

0 commit comments

Comments
 (0)