fix(junction): align complex boundary trims

This commit is contained in:
que01 committed 2026-09-08 17:57:03 +08:00
1 parent a12e2ac823
commit 4de971ce68
5 files changed
+125 -24

No files matched your search

+63 -18
View File
@@ -8,6 +8,7 @@ const {
complexJunctionMetrics,
resolveComplexJunctionTopology,
} = require('./complex-junction');
const { stationAtDistanceFrom } = require('./junction-build-plan');
const { diagnostic } = require('./diagnostics');
// Default marking placement lives with the constraint bounds in the solver, which
// is the IO-free module; importing the other way would drag fs into it.
@@ -783,12 +784,21 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
if (generated.islands) generatedComplexSidewalks.push(...generated.islands);
diagnostics.push(...generated.diagnostics);
}
const lanes = compileLaneCenterlines(model, diagnostics, junctionPlans, options, {
crosswalks: generatedComplexCrosswalks,
stopLines: generatedComplexStopLines,
});
const lanes = compileLaneCenterlines(
model,
diagnostics,
junctionPlans,
options,
{
crosswalks: generatedComplexCrosswalks,
stopLines: generatedComplexStopLines,
},
complexApproachBoundaries,
);
const edgeLines =
options.edgeLines === false ? [] : compileEdgeLines(model, overrides, junctionPlans, options, features);
options.edgeLines === false
? []
: compileEdgeLines(model, overrides, junctionPlans, options, features, complexApproachBoundaries);
const controls = compileControlMarkings(
model,
lanes,
@@ -800,13 +810,21 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
crosswalks: [...controls.crosswalks, ...generatedComplexCrosswalks],
stopLines: [...controls.stopLines, ...generatedComplexStopLines],
};
const centerLines = compileCenterLines(model, overrides, junctionPlans, allControls, diagnostics, options);
const centerLines = compileCenterLines(
model,
overrides,
junctionPlans,
allControls,
diagnostics,
options,
complexApproachBoundaries,
);
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);
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);
@@ -1068,7 +1086,14 @@ function laneWasClipped(original, visible) {
return Boolean(visible) && lineLengthMeters(visible) < lineLengthMeters(original) - 0.01;
}
function compileEdgeLines(model, overrides, junctionPlans, options = {}, roadSurfaces = []) {
function compileEdgeLines(
model,
overrides,
junctionPlans,
options = {},
roadSurfaces = [],
complexBoundaries = new Map(),
) {
const features = [];
const clusters = options.junctionTemplates?.enabled ? options.junctionTemplates.clusters || [] : [];
const clusterByNode = new Map(
@@ -1104,6 +1129,7 @@ function compileEdgeLines(model, overrides, junctionPlans, options = {}, roadSur
junctionPlans,
cluster,
clusterCenters.get(cluster.id),
complexBoundaries.get(cluster.id)?.get(road.id),
)
: trimLineAtJunctions(road.centerline, road.sourceNodeIds, junctionPlans);
// On a two-way segment, the inner edge is the road centre boundary and is
@@ -1155,7 +1181,15 @@ function edgeLineFeature(road, side, style, ring, part = null) {
};
}
function compileCenterLines(model, overrides, junctionPlans, controls, diagnostics, options = {}) {
function compileCenterLines(
model,
overrides,
junctionPlans,
controls,
diagnostics,
options = {},
complexBoundaries = new Map(),
) {
const features = [];
const controlFeatures = [...controls.crosswalks, ...controls.stopLines];
const segments = new Map();
@@ -1177,6 +1211,7 @@ function compileCenterLines(model, overrides, junctionPlans, controls, diagnosti
junctionPlans,
cluster,
clusterCenter(cluster, junctionPlans),
complexBoundaries.get(cluster.id)?.get(forward.id),
)
: trimLineAtJunctions(forward.centerline, forward.sourceNodeIds, junctionPlans);
const length = lineLengthMeters(line);
@@ -1827,7 +1862,7 @@ function ringsOverlap(first, second) {
);
}
function compileSidewalkSurfaces(model, diagnostics, junctionPlans, options = {}) {
function compileSidewalkSurfaces(model, diagnostics, junctionPlans, options = {}, complexBoundaries = new Map()) {
const features = [];
const byWay = new Map();
for (const road of model.roads) {
@@ -1850,7 +1885,14 @@ function compileSidewalkSurfaces(model, diagnostics, junctionPlans, options = {}
const sidewalkWidth = profile?.sidewalkWidths?.[side] ?? DEFAULT_SIDEWALK_WIDTH_METERS;
if (!enabled || sidewalkWidth <= 0) continue;
const centerline = cluster
? trimLineAtComplexCluster(forward.centerline, forward.sourceNodeIds, junctionPlans, cluster, center)
? trimLineAtComplexCluster(
forward.centerline,
forward.sourceNodeIds,
junctionPlans,
cluster,
center,
complexBoundaries.get(cluster.id)?.get(forward.id),
)
: trimLineAtJunctions(forward.centerline, forward.sourceNodeIds, junctionPlans);
const ring = sidewalkRing(centerline, totalWidth / 2, totalWidth / 2 + sidewalkWidth, side === 'left' ? 1 : -1);
if (!ring) {
@@ -2088,7 +2130,14 @@ function pointOnSegment(point, a, b) {
// templates already emitted. Ordinary controls cannot be passed here: they are
// placed *from* these lane centerlines, so only the template-generated ones
// exist this early.
function compileLaneCenterlines(model, diagnostics, junctionPlans, options = {}, complexControls = {}) {
function compileLaneCenterlines(
model,
diagnostics,
junctionPlans,
options = {},
complexControls = {},
complexBoundaries = new Map(),
) {
const features = [];
const controlFeatures = [...(complexControls.crosswalks || []), ...(complexControls.stopLines || [])];
const byRoadId = new Map();
@@ -2115,6 +2164,7 @@ function compileLaneCenterlines(model, diagnostics, junctionPlans, options = {},
junctionPlans,
boundaryCluster,
clusterCenters.get(boundaryCluster.id),
complexBoundaries.get(boundaryCluster.id)?.get(road.id),
)
: trimLineAtJunctions(road.centerline, road.sourceNodeIds, junctionPlans);
// OSM centerline is the shared carriageway center. On a two-way road,
@@ -3237,12 +3287,7 @@ function complexApproachBoundaryRadii(model, clusters, junctionPlans) {
}
function distanceAlongLineToRadius(line, center, radius) {
if (!center || line.length < 2) return 0;
const heading = headingAtEndpoint(line);
const vector = project(line[0], center);
const radians = (heading * Math.PI) / 180;
const startRadius = vector[0] * Math.sin(radians) + vector[1] * Math.cos(radians);
return Math.max(0, radius - startRadius);
return stationAtDistanceFrom(line, center, radius, { distanceMeters });
}
function trimLineRange(line, startCutback, endCutback) {