Clean up holes/gaps in sub-national regions (v0.15.0)
CI / build + unit + e2e (pull_request) Successful in 2m15s

Part of #16
This commit is contained in:
2026-10-12 13:51:47 +00:00
parent 69782aad69
commit 8eedc37e05
6 changed files with 378 additions and 4 deletions
+42
View File
@@ -326,6 +326,48 @@ describe('regions.geo.json', () => {
);
});
it('has no small enclosed holes left (the v0.15 cleanup filled them); only real water bodies remain', () => {
// v0.15 cleanup (scripts/cleanup-regions.mjs): every enclosed hole (inner
// ring) smaller than the threshold was dropped so each region is solid;
// only genuine water bodies (holes >= the threshold) survive. The big real
// lakes (Great Lakes, Caspian, Aral, Lake Superior, …) were already
// dissolved by the v0.14 coarsening, so the surviving holes are few and
// large. This guards the fix: a re-introduction of the tiny artifacts
// (thousands of < threshold holes) fails here.
const HOLE_MIN_KM2 = 1000; // keep in sync with cleanup-regions.mjs HOLE_AREA_MAX_KM2
let holeCount = 0;
let smallHoles = 0;
let maxHole = 0;
for (const f of regions.features) {
const polys = f.geometry.type === 'Polygon' ? [f.geometry.coordinates] : f.geometry.coordinates;
for (const poly of polys) {
for (let i = 1; i < poly.length; i++) {
const hole = poly[i];
let lat = 0;
for (const [, la] of hole) lat += la;
const area = ringAreaKm2(hole, hole.length ? lat / hole.length : 0);
holeCount++;
if (area > maxHole) maxHole = area;
if (area < HOLE_MIN_KM2) {
smallHoles++;
if (smallHoles <= 10) console.log(` small hole ${f.id} ≈ ${Math.round(area)} km2`);
}
}
}
}
expect(
smallHoles,
`${smallHoles} enclosed hole(s) below ${HOLE_MIN_KM2} km2 remain — the v0.15 cleanup should have filled them`,
).toBe(0);
expect(
holeCount <= 20,
`${holeCount} holes remain — expected only a handful of real water bodies`,
).toBe(true);
console.log(
`\n enclosed holes: ${holeCount} remain (all >= ${HOLE_MIN_KM2} km2, largest ${Math.round(maxHole).toLocaleString('en-US')} km2) — small artifacts filled by the v0.15 cleanup`,
);
});
it('sums to within [40%, 175%] of each country area (median in [70%, 130%])', () => {
// The band is a planar-approximation sanity check. It is wider than a naive
// [40%, 110%] because Natural Earth's admin-1 polygons are digitized