fix: share complex junction entry sections across layers

This commit is contained in:
que01 committed 2026-09-09 17:23:17 +08:00
1 parent 49212b3f34
commit cd65dbe879
5 files changed
+221 -50

No files matched your search

+122
View File
@@ -146,6 +146,128 @@ for (const feature of complexApproachFeatures) {
);
assert.ok(area > 0, 'compiled complex approach surface must have positive area');
}
// Published transition lanes share the fixed source seam, including when the
// inner width is edited. Their outer endpoints must remain inside that seam.
const previewLanes = complexGeometry.laneCenterlines.features.filter((feature) => feature.properties.cluster_preview);
assert.ok(previewLanes.length > 0);
for (const lane of previewLanes) {
const approach = complexApproachFeatures.find(
(feature) => feature.properties.carriageway_key === lane.properties.carriageway_key,
);
assert.ok(approach, 'a transition lane must have a supported approach surface');
const ring = approach.geometry.coordinates[0];
const ratio = (lane.properties.lane_index - 0.5) / approach.properties.lane_count;
const expected = ring[0].map((value, axis) => value + (ring[3][axis] - value) * ratio);
assert.ok(
Math.hypot(...expected.map((value, axis) => value - lane.geometry.coordinates[0][axis])) < 1e-9,
'transition lane starts on its actual outer seam',
);
}
const boundaryEditOptions = {
junctionTemplates: {
enabled: true,
clusters: [
{
id: 'fixture-five-arm',
template: 'complex-junction-v1',
nodeIds: ['8005332807', '8024512135', '8024512145', '8024512147', '8613058676'],
coreRadiusMeters: 24,
},
],
},
directEdit: {
clusterPlans: new Map([
[
'fixture-five-arm',
new Map([[compiledApproach.properties.carriageway_key, compiledApproach.properties.width_m * 1.2]]),
],
]),
},
};
const widenedGeometry = compiler.nativeRoad.compileGeometry(complexModel, { overrides: [] }, boundaryEditOptions);
const exteriorBaseline = compiler.nativeRoad.compileGeometry(
complexModel,
{ overrides: [] },
{ junctionTemplates: boundaryEditOptions.junctionTemplates },
);
// External pavement and all linear consumers retain the same geometry when
// only the internal width changes; measure the pavement seam in metres too.
for (const layerName of ['roadSurface', 'edgeLines', 'sidewalkSurface', 'centerLines', 'laneCenterlines']) {
const external = (geometry) =>
geometry[layerName].features.filter((feature) =>
layerName === 'roadSurface'
? Boolean(feature.properties.directional_road_ids)
: layerName === 'sidewalkSurface'
? feature.properties.provenance === 'native-road-sidewalk/v1'
: !feature.properties.cluster_preview,
);
assert.deepEqual(
external(widenedGeometry),
external(exteriorBaseline),
`${layerName} must keep the fixed exterior geometry during local widening`,
);
}
let checkedExteriorSeams = 0;
for (const approach of complexApproachFeatures) {
const lane = previewLanes.find(
(candidate) => candidate.properties.carriageway_key === approach.properties.carriageway_key,
);
const surface = complexGeometry.roadSurface.features.find((candidate) =>
String(candidate.properties.directional_road_ids || '')
.split(',')
.includes(lane?.properties.road_id),
);
if (!surface) continue;
const ring = approach.geometry.coordinates[0];
for (const endpoint of [ring[0], ring[3]]) {
const error = Math.min(
...surface.geometry.coordinates[0].map((coordinate) =>
Math.hypot(
(coordinate[0] - endpoint[0]) * 111320 * Math.cos((endpoint[1] * Math.PI) / 180),
(coordinate[1] - endpoint[1]) * 111320,
),
),
);
assert.ok(error <= 0.01, `external pavement seam error ${error} exceeds one centimetre`);
}
checkedExteriorSeams++;
}
assert.ok(checkedExteriorSeams > 0);
const widenedLanes = widenedGeometry.laneCenterlines.features.filter(
(feature) =>
feature.properties.cluster_preview &&
feature.properties.carriageway_key === compiledApproach.properties.carriageway_key,
);
assert.ok(widenedLanes.length > 0);
for (const lane of widenedLanes) {
const before = previewLanes.find((candidate) => candidate.properties.native_id === lane.properties.native_id);
assert.deepEqual(
lane.geometry.coordinates[0],
before.geometry.coordinates[0],
'local widening preserves the outer lane seam',
);
}
const rejectedGeometry = compiler.nativeRoad.compileGeometry(
complexModel,
{ overrides: [] },
{
...boundaryEditOptions,
directEdit: {
clusterTransitions: new Map([
['fixture-five-arm', new Map([[compiledApproach.properties.carriageway_key, 10000]])],
]),
},
},
);
assert.equal(
rejectedGeometry.laneCenterlines.features.some(
(feature) =>
feature.properties.cluster_preview &&
feature.properties.carriageway_key === compiledApproach.properties.carriageway_key,
),
false,
'an unsupported transition must not publish floating lanes',
);
const complexFeatures = Object.values(complexGeometry).flatMap((layer) => layer?.features || []);
assert.equal(
complexFeatures.some((feature) => feature.properties?.kind === 'complex-corner-island'),