fix: share complex junction entry sections across layers
This commit is contained in:
1 parent
49212b3f34
commit
cd65dbe879
5 files changed
+221
-50
No files matched your search
+56
-38
@@ -5,6 +5,7 @@ const path = require('path');
|
||||
const { arrowRingsAt, normalizeManeuver } = require('./turn-lane-arrows');
|
||||
const {
|
||||
buildComplexJunctionGeometry,
|
||||
buildComplexApproachBoundaryGraph,
|
||||
complexJunctionMetrics,
|
||||
resolveComplexJunctionTopology,
|
||||
} = require('./complex-junction');
|
||||
@@ -672,9 +673,9 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
|
||||
const generatedComplexCrosswalks = [];
|
||||
const generatedComplexStopLines = [];
|
||||
// The external road and its complex-junction carriageway must end at the
|
||||
// same radial boundary. A fixed outer radius here while the carriageway used
|
||||
// its per-arm cutback left a visible asphalt gap between the two surfaces.
|
||||
const complexApproachBoundaries = complexApproachBoundaryRadii(model, activeClusters, junctionPlans);
|
||||
// same source section. The graph is built once and reused by surfaces,
|
||||
// road trims, and transition markings rather than re-solving each radius.
|
||||
const complexApproachBoundaries = complexApproachBoundarySections(model, activeClusters, junctionPlans);
|
||||
for (const road of model.roads) {
|
||||
const segmentKey = road.segmentId;
|
||||
if (emittedSegments.has(segmentKey)) continue;
|
||||
@@ -792,6 +793,7 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
|
||||
headingAtEndpoint,
|
||||
headingVector,
|
||||
circleRing,
|
||||
boundaryGraph: complexApproachBoundaries.get(cluster.id)?.boundaryGraph,
|
||||
clusterCornerRadii: options.directEdit?.clusterCorners?.get(String(cluster.id)),
|
||||
clusterCrossingControls: options.directEdit?.clusterCrossings?.get(String(cluster.id)),
|
||||
});
|
||||
@@ -2323,21 +2325,26 @@ function compileLaneCenterlines(
|
||||
const corridorRoads = approach.roadIds
|
||||
.map((roadId) => model.roads.find((road) => road.id === roadId))
|
||||
.filter(Boolean);
|
||||
const boundaryRadii = corridorRoads
|
||||
.map((road) => complexBoundaries.get(cluster.id)?.get(road.id))
|
||||
.filter(Number.isFinite);
|
||||
const outerRadius = boundaryRadii[0] ?? complexJunctionMetrics(cluster).approachOuterRadius;
|
||||
const length = Math.min(
|
||||
distanceAlongLineToRadius(approach.line, compositeCenter, outerRadius),
|
||||
lineLengthMeters(approach.line),
|
||||
);
|
||||
const section = corridorRoads.map((road) => complexBoundaries.get(cluster.id)?.get(road.id)).find(Boolean);
|
||||
if (
|
||||
cluster.template === 'complex-junction-v1' &&
|
||||
(!section ||
|
||||
section.ringStatus !== 'supported' ||
|
||||
section.transitionStatus !== 'supported' ||
|
||||
section.exclusionStatus !== 'clear')
|
||||
)
|
||||
continue;
|
||||
const length =
|
||||
section?.outer.stationMeters ??
|
||||
distanceAlongLineToRadius(approach.line, compositeCenter, complexJunctionMetrics(cluster).approachOuterRadius);
|
||||
if (length < 12) continue;
|
||||
const line = approach.line;
|
||||
const outer = pointAlongLine(line, Math.max(0, length));
|
||||
const inner = pointAlongLine(
|
||||
line,
|
||||
Math.min(Math.max(3, Number(cluster.coreRadiusMeters || 28) * 0.14), Math.max(3, length - 8)),
|
||||
);
|
||||
const outer = section?.outer.point || pointAlongLine(approach.line, length);
|
||||
const inner =
|
||||
section?.inner.point ||
|
||||
pointAlongLine(
|
||||
approach.line,
|
||||
Math.min(Math.max(3, Number(cluster.coreRadiusMeters || 28) * 0.14), Math.max(3, length - 8)),
|
||||
);
|
||||
const incoming = corridorRoads.some((road) => String(road.sourceNodeIds.at(-1)) === String(corridor.nodeId));
|
||||
const count = Math.max(
|
||||
1,
|
||||
@@ -2351,8 +2358,13 @@ function compileLaneCenterlines(
|
||||
const across = [-normalized[1], normalized[0]];
|
||||
for (let index = 0; index < count; index += 1) {
|
||||
const offset = approach.widthMeters / 2 - laneWidth * (index + 0.5);
|
||||
const start = unproject([across[0] * offset, across[1] * offset], outer);
|
||||
const end = unproject([across[0] * offset, across[1] * offset], inner);
|
||||
const ratio = (index + 0.5) / count;
|
||||
const start = section
|
||||
? interpolate(section.outer.right, section.outer.left, ratio)
|
||||
: unproject([across[0] * offset, across[1] * offset], outer);
|
||||
const end = section
|
||||
? interpolate(section.inner.right, section.inner.left, ratio)
|
||||
: unproject([across[0] * offset, across[1] * offset], inner);
|
||||
const maneuver = incoming ? (index === 0 ? 'left' : index === count - 1 ? 'right' : 'through') : 'outbound';
|
||||
// Preview lanes are laid out radially from the outer radius inwards, so
|
||||
// an untrimmed one runs straight over the arm crossing. Stop it at the
|
||||
@@ -2371,6 +2383,8 @@ function compileLaneCenterlines(
|
||||
road_id: corridorRoads[0]?.id || null,
|
||||
cluster_id: cluster.id,
|
||||
cluster_preview: true,
|
||||
carriageway_key: section?.carriagewayKey || null,
|
||||
boundary_refs: section?.edgeRefs || null,
|
||||
incoming,
|
||||
lane_index: index + 1,
|
||||
maneuver,
|
||||
@@ -3294,40 +3308,44 @@ function trimLineAtJunctions(line, sourceNodeIds, junctionPlans) {
|
||||
return result;
|
||||
}
|
||||
|
||||
function trimLineAtComplexCluster(line, sourceNodeIds, junctionPlans, cluster, center, boundaryRadius) {
|
||||
function trimLineAtComplexCluster(line, sourceNodeIds, junctionPlans, cluster, center, boundarySection) {
|
||||
if (!center || line.length < 2) return trimLineAtJunctions(line, sourceNodeIds, junctionPlans);
|
||||
const radius = Number.isFinite(boundaryRadius) ? boundaryRadius : complexJunctionMetrics(cluster).approachOuterRadius;
|
||||
const radius = complexJunctionMetrics(cluster).approachOuterRadius;
|
||||
const startInCluster = cluster.nodeIds.map(String).includes(String(sourceNodeIds[0]));
|
||||
const endInCluster = cluster.nodeIds.map(String).includes(String(sourceNodeIds.at(-1)));
|
||||
const available = lineLengthMeters(line);
|
||||
const startDistance = startInCluster ? distanceAlongLineToRadius(line, center, radius) : 0;
|
||||
const endDistance = endInCluster ? distanceAlongLineToRadius([...line].reverse(), center, radius) : 0;
|
||||
const startDistance = startInCluster
|
||||
? (boundarySection?.outer.stationMeters ?? distanceAlongLineToRadius(line, center, radius))
|
||||
: 0;
|
||||
const endDistance = endInCluster
|
||||
? (boundarySection?.outer.stationMeters ?? distanceAlongLineToRadius([...line].reverse(), center, radius))
|
||||
: 0;
|
||||
const startCutback = startDistance > 0 && available > startDistance + 1 ? startDistance : 0;
|
||||
const endCutback = endDistance > 0 && available > endDistance + 1 ? endDistance : 0;
|
||||
if (!startCutback && !endCutback) return line;
|
||||
return trimLineRange(line, startCutback, endCutback);
|
||||
}
|
||||
|
||||
function complexApproachBoundaryRadii(model, clusters, junctionPlans) {
|
||||
function complexApproachBoundarySections(model, clusters, junctionPlans) {
|
||||
const result = new Map();
|
||||
const helpers = { junctionPlans, distanceMeters, lineLengthMeters, headingAtEndpoint };
|
||||
for (const cluster of clusters) {
|
||||
if (cluster.template !== 'complex-junction-v1') continue;
|
||||
const outerRadius = complexJunctionMetrics(cluster).approachOuterRadius;
|
||||
const topology = resolveComplexJunctionTopology(model, cluster, {
|
||||
junctionPlans,
|
||||
distanceMeters,
|
||||
lineLengthMeters,
|
||||
headingAtEndpoint,
|
||||
});
|
||||
const radii = new Map();
|
||||
const topology = resolveComplexJunctionTopology(model, cluster, helpers);
|
||||
const graph = buildComplexApproachBoundaryGraph(
|
||||
topology,
|
||||
clusterCenter(cluster, junctionPlans),
|
||||
cluster,
|
||||
helpers,
|
||||
model.exclusionRegions || [],
|
||||
);
|
||||
const sections = new Map();
|
||||
sections.boundaryGraph = graph;
|
||||
for (const item of topology.carriageways) {
|
||||
const radius = Math.max(
|
||||
complexJunctionMetrics(cluster).coreRadius + 4,
|
||||
outerRadius - Math.max(0, item.approach.cutback || 0),
|
||||
);
|
||||
for (const roadId of item.approach.roadIds) radii.set(roadId, radius);
|
||||
const section = graph.sections.find((candidate) => candidate.carriagewayKey === item.key);
|
||||
for (const roadId of item.approach.roadIds) sections.set(roadId, section);
|
||||
}
|
||||
result.set(cluster.id, radii);
|
||||
result.set(cluster.id, sections);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user