fix: fill pavement gaps when junction islands move outward

This commit is contained in:
que01 committed 2026-09-16 15:35:33 +08:00
1 parent 0c42eb46cd
commit e0eaa1c950
2 files changed
+80

No files matched your search

+54
View File
@@ -33,6 +33,60 @@ assert.ok(Math.hypot(shift[0] * 111320 * Math.cos((center[1] * Math.PI) / 180),
directEdit: { clusterIslandOffsets: new Map([[cluster.id, 2]]) },
},
);
// Check the complete crossing envelope at intermediate positions, not only
// stripe coverage at the final position. This catches the exposed road gap.
const clipping = require('polygon-clipping');
const toMeters = ([x, y]) => [(x - 114) * 111320 * Math.cos((30 * Math.PI) / 180), (y - 30) * 111320];
const area = (regions) =>
regions.reduce(
(total, polygon) =>
total +
polygon.reduce((sum, ring, index) => {
const value =
Math.abs(ring.slice(1).reduce((acc, p, i) => acc + ring[i][0] * p[1] - p[0] * ring[i][1], 0)) / 2;
return sum + (index ? -value : value);
}, 0),
0,
);
const groups = (geometry) => {
const result = new Map();
for (const feature of geometry.crosswalks.features) {
if (feature.properties.kind !== 'complex-crosswalk') continue;
const key = feature.properties.arm_key;
const stripes = result.get(key) || [];
stripes.push(feature.geometry.coordinates[0]);
result.set(key, stripes);
}
return new Map(
[...result].map(([key, stripes]) => {
const first = stripes[0],
last = stripes.at(-1);
return [key, [first[0], first[1], last[2], last[3], first[0]].map(toMeters)];
}),
);
};
const originalGroups = groups(base);
for (const offset of [3.3, 8]) {
const moved = compileGeometry(
model,
{ overrides: [] },
{
...options,
directEdit: { clusterIslandOffsets: new Map([[cluster.id, offset]]) },
},
);
const pavement = moved.roadSurface.features.find((f) => f.properties.kind === 'complex-pavement-region');
assert.ok(pavement, `offset ${offset}: must publish unified pavement`);
const regions = pavement.geometry.coordinates.map((polygon) => polygon.map((ring) => ring.map(toMeters)));
for (const [key, end] of groups(moved)) {
const start = originalGroups.get(key);
for (const ratio of [0, 0.25, 0.5, 0.75, 1]) {
const envelope = start.map((point, i) => point.map((v, axis) => v + (end[i][axis] - v) * ratio));
const missing = area(clipping.difference([envelope], regions));
assert.ok(missing < 0.001, `offset ${offset}, arm ${key}, sweep ${ratio}: ${missing} m² unpaved`);
}
}
}
const byKind = (geometry, kind) =>
geometry.sidewalkSurface.features.filter((feature) => feature.properties.kind === kind);
const baseIslands = byKind(base, 'island');