Smooth jagged sub-national region boundaries (v0.16.0)
CI / build + unit + e2e (pull_request) Successful in 2m18s

Part of #16
This commit is contained in:
2026-10-13 09:42:44 +00:00
parent 97702940cd
commit f1cc4fbc10
6 changed files with 313 additions and 4 deletions
+36
View File
@@ -404,4 +404,40 @@ describe('regions.geo.json', () => {
` / max ${maxId} ${(100 * maxRatio).toFixed(1)}% (band 40–175%)`,
);
});
it('is at the Douglas–Peucker 50m fixed point: 1,796 regions, topology unchanged, 111,175 vertices (v0.16 smoothing)', () => {
// v0.16 (scripts/smooth-regions.mjs) thinned every ring with Douglas–Peucker at
// ~50 m. That removes redundant vertices only — it never moves a border, merges
// a part, or creates/removes a ring — so the topology signature is invariant
// (1,796 features, 5,026 parts, 5,027 rings, the single KZ-KZY hole) and the
// vertex total sits at the pass's fixed point (re-running changes nothing).
// Pinning it guards against an accidental re-coarsening or a different-tolerance
// re-smooth silently changing the shipped dataset.
const polysOf = (g: Geometry) => (g.type === 'Polygon' ? [g.coordinates] : g.coordinates);
let verts = 0,
rings = 0,
parts = 0,
holes = 0;
const holeIds: string[] = [];
for (const f of regions.features) {
const polys = polysOf(f.geometry);
parts += polys.length;
for (const poly of polys) {
rings += poly.length;
holes += Math.max(0, poly.length - 1);
if (poly.length > 1) holeIds.push(f.id);
for (const ring of poly) verts += ring.length;
}
}
expect(regions.features.length, 'region count').toBe(1796);
expect(verts, 'total vertices (incl. ring closure)').toBe(111_175); // was 111,891 pre-v0.16; 716 removed
expect(parts, 'parts').toBe(5026); // unchanged — no part merged/dropped
expect(rings, 'rings').toBe(5027); // unchanged — no ring added/dropped
expect(holes, 'holes').toBe(1); // the single KZ-KZY hole, unchanged
expect(holeIds, 'the one remaining hole is KZ-KZY').toEqual(['KZ-KZY']);
console.log(
`\n v0.16 smoothing: ${regions.features.length} regions, ${parts} parts, ${rings} rings, ` +
`${holes} hole (KZ-KZY), ${verts} vertices (50m DP fixed point; 716 removed from 111,891) — topology unchanged`,
);
});
});