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

+45 -34
View File
@@ -11,11 +11,6 @@ const CORNER_FILLET_SEGMENTS = 12;
// Must match DEFAULT_SIDEWALK_WIDTH_METERS in native-road.js so the corner band
// lines up with the straight strips it joins.
const SIDEWALK_WIDTH_METERS = 2;
// The straight strips are trimmed against the cluster boundary using the road
// centerline, so they stop a little beyond the carriageway end. Run the corner
// past that end and let the two overlap rather than chase an exact seam.
const SIDEWALK_CORNER_OVERRUN_METERS = 6;
// Compatibility export for current compiler consumers. The build-plan module is
// pure and is the shared authority for geometry and direct-edit identity.
const resolveComplexJunctionTopology = resolveJunctionBuildPlan;
@@ -426,26 +421,24 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
// The corner faces clockwise from `first` and counter-clockwise from
// `second`, so each arm must carry the footway on that facing side.
if (!armCarriesSidewalk(first, model, true) || !armCarriesSidewalk(second, model, false)) continue;
const curb = [
...edgeRunToRadius(
apex,
edges[0],
tangentDistance,
outerRadius + SIDEWALK_CORNER_OVERRUN_METERS,
center,
helpers,
).reverse(),
...curve.slice(1, -1),
...edgeRunToRadius(
apex,
edges[1],
tangentDistance,
outerRadius + SIDEWALK_CORNER_OVERRUN_METERS,
center,
helpers,
),
];
const seams = edges.map((edge) => exteriorSidewalkSeam(edge, boundaryGraph, helpers));
if (!seams.every(Boolean)) {
cornerDiagnostics.push(
helpers.diagnostic(
'warning',
`corner:${first.cornerKey}`,
edges.flatMap((edge) => edge.roadIds),
'complex-junction-sidewalk-seam-unavailable',
'该角部缺少两侧可验证的人行道接缝,已省略连接,避免生成悬空步行带。',
center,
),
);
continue;
}
const curb = [seams[0].curb, ...curve, seams[1].curb];
const outerEdge = offsetPolylineAwayFromCenter(curb, center, SIDEWALK_WIDTH_METERS, helpers);
outerEdge[0] = seams[0].outer;
outerEdge[outerEdge.length - 1] = seams[1].outer;
const sidewalkRing = [...curb, ...outerEdge.slice().reverse(), curb[0]];
if (!sidewalkRing.every((point) => point.every(Number.isFinite)) || ringSelfIntersects(sidewalkRing)) {
cornerDiagnostics.push(
@@ -473,7 +466,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
to_heading: second.heading,
bisector_heading: bisector,
width_m: SIDEWALK_WIDTH_METERS,
overrun_m: SIDEWALK_CORNER_OVERRUN_METERS,
seam_source: 'published-exterior-sidewalk',
provenance: 'native-road-complex-junction-sidewalk-corner/v1',
},
geometry: { type: 'Polygon', coordinates: [sidewalkRing] },
@@ -729,16 +722,31 @@ function armCarriesSidewalk(arm, model, cornerIsClockwise) {
);
}
// Walk outward along a wedge edge from its tangent point until the curb reaches
// `targetRadius`, so the corner band overlaps the straight strip it joins.
function edgeRunToRadius(apex, edge, tangentDistance, targetRadius, center, helpers) {
const points = [];
for (let extra = 0; extra <= 40; extra += 2) {
const point = helpers.offsetCoordinate(apex, edge.heading, tangentDistance + extra);
points.push(point);
if (helpers.distanceMeters(point, center) >= targetRadius) break;
// Use the emitted strip's complete end edge, including its actual width and
// orientation. A radius extension cannot guarantee this seam on curved roads.
function exteriorSidewalkSeam(edge, graph, helpers) {
const section = graph.sections.find((item) => item.carriagewayKey === edge.carriagewayKey);
if (
!section ||
section.ringStatus !== 'supported' ||
section.transitionStatus !== 'supported' ||
section.exclusionStatus !== 'clear'
)
return null;
const target = edge.side === 90 ? section.outer.right : section.outer.left;
for (const feature of helpers.exteriorSidewalks || []) {
const ids = String(feature.properties.directional_road_ids || '').split(',');
if (!edge.roadIds.some((id) => ids.includes(String(id)))) continue;
const ring = feature.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]],
]) {
if (helpers.distanceMeters(curb, target) <= 0.01) return { curb, outer };
}
}
return points;
return null;
}
// Offset each vertex along the polyline normal that increases distance from the
@@ -858,6 +866,9 @@ function cornerEdgeAt(arm, radius, bisector, center, helpers) {
return [90, -90].map((side) => ({
point: helpers.offsetCoordinate(point, member.heading + side, halfWidth),
heading: member.heading,
carriagewayKey: member.key,
roadIds: member.approach.roadIds,
side,
}));
});
return (
+30 -3
View File
@@ -781,6 +781,17 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
});
}
}
const surfacedRoadIds = new Set(
features.flatMap((feature) => String(feature.properties.directional_road_ids || '').split(',')).filter(Boolean),
);
const sidewalks = compileSidewalkSurfaces(
model,
diagnostics,
junctionPlans,
options,
complexApproachBoundaries,
surfacedRoadIds,
);
for (const cluster of activeClusters) {
if (cluster.template !== 'complex-junction-v1') continue;
const generated = buildComplexJunctionGeometry(model, cluster, {
@@ -794,6 +805,7 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
headingVector,
circleRing,
boundaryGraph: complexApproachBoundaries.get(cluster.id)?.boundaryGraph,
exteriorSidewalks: sidewalks,
clusterCornerRadii: options.directEdit?.clusterCorners?.get(String(cluster.id)),
clusterCrossingControls: options.directEdit?.clusterCrossings?.get(String(cluster.id)),
});
@@ -813,6 +825,7 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
stopLines: generatedComplexStopLines,
},
complexApproachBoundaries,
surfacedRoadIds,
);
const edgeLines =
options.edgeLines === false
@@ -837,13 +850,13 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
diagnostics,
options,
complexApproachBoundaries,
surfacedRoadIds,
);
const markings = compileLaneMarkings(model, overrides, lanes, diagnostics, junctionPlans, allControls, options);
markings.separators.push(
...compileComplexLaneSeparators(lanes.features, [...allControls.crosswalks, ...allControls.stopLines]),
);
markings.directionArrows.push(...compileComplexPreviewArrows(lanes.features, generatedComplexStopLines));
const sidewalks = compileSidewalkSurfaces(model, diagnostics, junctionPlans, options, complexApproachBoundaries);
// Complex crosswalks are generated from native approach tangents; do not
// synthesize side strips that can be mistaken for crosswalks.
sidewalks.push(...generatedComplexSidewalks);
@@ -1154,7 +1167,7 @@ function compileEdgeLines(
.filter(Boolean),
);
for (const road of model.roads) {
if (surfaced.size && !surfaced.has(road.id)) continue;
if (!surfaced.has(road.id)) continue;
// The road surface is one polygon per segment, centred on this centerline
// and spanning the sum of both directions. Deriving the edge from a single
// direction's width puts it half a carriageway inside the asphalt.
@@ -1234,6 +1247,7 @@ function compileCenterLines(
diagnostics,
options = {},
complexBoundaries = new Map(),
surfacedRoadIds = null,
) {
const features = [];
const controlFeatures = [...controls.crosswalks, ...controls.stopLines];
@@ -1247,6 +1261,7 @@ function compileCenterLines(
const backward = roads.find((road) => road.direction === 'backward');
if (roads.length !== 2 || !forward || !backward || forward.highway === 'service' || backward.highway === 'service')
continue;
if (surfacedRoadIds && !surfacedRoadIds.has(forward.id)) continue;
const cluster = clusterForRoad(forward, options) || clusterForRoad(backward, options);
const internalCluster = cluster && roadInternalToCluster(forward, cluster);
const line = cluster
@@ -1907,7 +1922,14 @@ function ringsOverlap(first, second) {
);
}
function compileSidewalkSurfaces(model, diagnostics, junctionPlans, options = {}, complexBoundaries = new Map()) {
function compileSidewalkSurfaces(
model,
diagnostics,
junctionPlans,
options = {},
complexBoundaries = new Map(),
surfacedRoadIds = null,
) {
const features = [];
const byWay = new Map();
for (const road of model.roads) {
@@ -1917,6 +1939,7 @@ function compileSidewalkSurfaces(model, diagnostics, junctionPlans, options = {}
}
for (const [wayKey, directions] of byWay) {
const forward = directions.find((road) => road.direction === 'forward') || directions[0];
if (surfacedRoadIds && !surfacedRoadIds.has(forward.id)) continue;
const backward = directions.find((road) => road.id !== forward.id);
const totalWidth = directions.reduce((sum, road) => sum + road.widthMeters, 0);
const sides = [
@@ -2182,6 +2205,7 @@ function compileLaneCenterlines(
options = {},
complexControls = {},
complexBoundaries = new Map(),
surfacedRoadIds = null,
) {
const features = [];
const controlFeatures = [...(complexControls.crosswalks || []), ...(complexControls.stopLines || [])];
@@ -2243,6 +2267,9 @@ function compileLaneCenterlines(
}
const lane = { id: laneId(road.id, index + 1), roadId: road.id, index: index + 1, coordinates };
lanes.push(lane);
// Retain internal lanes for movement solving, but publish markings only
// where the external road surface was actually emitted.
if (surfacedRoadIds && !surfacedRoadIds.has(road.id)) continue;
// Only the published geometry stops at the crossing. `coordinates` stays
// whole because connectors are derived from it; a lane that ends at the
// stop bar would otherwise break every turn path through the junction.