fix: suppress orphaned complex junction attachments

This commit is contained in:
que01 committed 2026-09-09 17:44:00 +08:00
1 parent cd65dbe879
commit 79f2ee5d4e
3 files changed
+179 -37

No files matched your search

+104
View File
@@ -268,6 +268,110 @@ assert.equal(
false,
'an unsupported transition must not publish floating lanes',
);
// External attachments must follow actual pavement publication, even when a
// short source road is swallowed by a cluster. Internal solver lanes remain private.
const surfacedIds = new Set(
exteriorBaseline.roadSurface.features
.flatMap((feature) => String(feature.properties.directional_road_ids || '').split(','))
.filter(Boolean),
);
assert.ok(
complexModel.roads.some((road) => !surfacedIds.has(road.id)),
'fixture exercises omitted roads',
);
for (const name of ['edgeLines', 'centerLines', 'laneCenterlines', 'laneSeparators', 'directionArrows', 'turnArrows']) {
for (const feature of exteriorBaseline[name].features) {
if (feature.properties.cluster_preview || String(feature.properties.native_id).startsWith('complex-')) continue;
assert.ok(
surfacedIds.has(feature.properties.road_id),
`${name} must not publish an attachment without external pavement`,
);
}
}
const sidewalkModel = {
...complexModel,
roads: complexModel.roads.map((road) => ({ ...road, sidewalkLeft: true, sidewalkRight: true })),
};
const sidewalkGeometry = compiler.nativeRoad.compileGeometry(
sidewalkModel,
{ overrides: [] },
{ junctionTemplates: boundaryEditOptions.junctionTemplates },
);
const strips = sidewalkGeometry.sidewalkSurface.features.filter(
(feature) => feature.properties.provenance === 'native-road-sidewalk/v1',
);
for (const strip of strips)
assert.ok(
String(strip.properties.directional_road_ids)
.split(',')
.every((id) => surfacedIds.has(id)),
);
const corners = sidewalkGeometry.sidewalkSurface.features.filter(
(feature) => feature.properties.kind === 'complex-sidewalk-corner',
);
assert.ok(corners.length > 0, 'fixture must exercise joined corner sidewalks');
for (const corner of corners) {
const ring = corner.geometry.coordinates[0];
const half = (ring.length - 1) / 2;
for (const [curb, outer] of [
[ring[0], ring[ring.length - 2]],
[ring[half - 1], ring[half]],
]) {
assert.ok(
strips.some((strip) => {
const points = strip.geometry.coordinates[0];
const middle = (points.length - 1) / 2;
return [
[points[0], points[points.length - 2]],
[points[middle - 1], points[middle]],
].some(([first, second]) => JSON.stringify([first, second]) === JSON.stringify([curb, outer]));
}),
'both ends of each corner must share the complete published sidewalk seam',
);
}
}
// Empty pavement is a real result, not a signal to disable attachment checks.
const shortPoints = [
[1, -1, 0],
[2, 1, 0],
[3, -8, 8],
[4, -8, -8],
[5, 8, 8],
[6, 8, -8],
];
const shortWays = [
[1, 2],
[1, 3],
[1, 4],
[2, 5],
[2, 6],
];
const shortXml = `<osm>${shortPoints.map(([id, x, y]) => `<node id="${id}" lon="${x / 111320}" lat="${y / 111320}"/>`).join('')}${shortWays.map(([from, to], index) => `<way id="${index + 1}"><nd ref="${from}"/><nd ref="${to}"/><tag k="highway" v="residential"/><tag k="sidewalk" v="both"/></way>`).join('')}</osm>`;
const shortModel = compiler.nativeRoad.compileRoadModel(shortXml, { overrides: [] });
const shortGeometry = compiler.nativeRoad.compileGeometry(
shortModel,
{ overrides: [] },
{
junctionTemplates: {
enabled: true,
clusters: [{ id: 'short', nodeIds: ['1', '2'], template: 'complex-junction-v1', coreRadiusMeters: 24 }],
},
},
);
assert.equal(
shortGeometry.roadSurface.features.some((feature) => feature.properties.directional_road_ids),
false,
);
for (const name of [
'edgeLines',
'centerLines',
'laneCenterlines',
'laneSeparators',
'directionArrows',
'turnArrows',
'sidewalkSurface',
])
assert.equal(shortGeometry[name].features.length, 0, `${name} must remain empty when all source roads are swallowed`);
const complexFeatures = Object.values(complexGeometry).flatMap((layer) => layer?.features || []);
assert.equal(
complexFeatures.some((feature) => feature.properties?.kind === 'complex-corner-island'),