fix: align junction crossings and round pedestrian islands

This commit is contained in:
que01 committed 2026-09-11 17:35:32 +08:00
1 parent 76f81d024a
commit 7a7912f302
18 files changed
+491 -96

No files matched your search

+110 -89
View File
@@ -1,10 +1,16 @@
'use strict';
const fs = require('fs');
const { COMPLEX_CROSSWALK_DEPTH_METERS } = require('./junction-metrics');
const { structureFromTopology } = require('./junction-topology');
const { resolveJunctionBuildPlan, stationAtDistanceFrom } = require('./junction-build-plan');
const { buildJunctionBoundaryGraph, buildCoreClosure, ringsOverlap } = require('./junction-boundary-graph');
const { solveCornerFeasibleRegion } = require('./junction-region-solver');
const {
buildIslandFromCrossingEdges,
orthogonalCrossingHeadings,
stripeLayout,
crossingArcSupport,
} = require('./junction-facility-composition');
const { complexJunctionMetrics: calculateComplexJunctionMetrics } = require('./junction-metrics');
const { convertGeoJson, boundsOf } = require('../reference/gaode');
const metricsCache = new WeakMap();
@@ -157,41 +163,37 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
.map((roadId) => model.roads.find((road) => road.id === roadId))
.find((road) => String(road?.sourceNodeIds.at(-1)) === String(item.nodeId));
if (incomingRoad) {
// Keep the stop bar just outside the road crosswalk. The previous fixed
// core-radius offset placed it nearly ten metres beyond the crossing.
// Offset is clear space beyond the relocated crossing outer edge; include
// half the stop bar thickness so the minimum offset cannot cut into it.
const arm = arms.find((candidate) => candidate.members.includes(item));
const crossingKey = `crossing:${arm.key}`;
const crossingRadius = armCrosswalkRadiusFor(arm);
const stopOffset = crossingControls.get(crossingKey)?.stopLineOffsetMeters || 3;
const stopCenter = pointOnCarriagewayRadius(item, center, crossingRadius + stopOffset, helpers);
const stopHeading = orthogonalCrossingHeadings(arms.map((candidate) => candidate.heading))[arms.indexOf(arm)];
const envelope = armEnvelopeAtRadius(arm, crossingRadius, center, helpers);
const basePoint = pointOnCarriagewayRadius(item, center, crossingRadius, helpers);
const lateral = signedLateralMeters(envelope.center, basePoint, stopHeading);
const stopCenter = helpers.offsetCoordinate(
helpers.offsetCoordinate(envelope.center, stopHeading + 90, lateral),
stopHeading,
COMPLEX_CROSSWALK_DEPTH_METERS * 1.5 + 0.24 + stopOffset,
);
const crossingEvidence = crossingPlans.get(arm.key)?.evidence || {
kind: 'unknown-no-crossing-source',
crossingNodeIds: [],
};
const ring = [
helpers.offsetCoordinate(
helpers.offsetCoordinate(stopCenter, item.heading + 90, -outerHalf),
item.heading,
helpers.offsetCoordinate(stopCenter, stopHeading + 90, -outerHalf),
stopHeading,
-0.24,
),
helpers.offsetCoordinate(helpers.offsetCoordinate(stopCenter, stopHeading + 90, outerHalf), stopHeading, -0.24),
helpers.offsetCoordinate(helpers.offsetCoordinate(stopCenter, stopHeading + 90, outerHalf), stopHeading, 0.24),
helpers.offsetCoordinate(helpers.offsetCoordinate(stopCenter, stopHeading + 90, -outerHalf), stopHeading, 0.24),
helpers.offsetCoordinate(
helpers.offsetCoordinate(stopCenter, item.heading + 90, outerHalf),
item.heading,
-0.24,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(stopCenter, item.heading + 90, outerHalf),
item.heading,
0.24,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(stopCenter, item.heading + 90, -outerHalf),
item.heading,
0.24,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(stopCenter, item.heading + 90, -outerHalf),
item.heading,
helpers.offsetCoordinate(stopCenter, stopHeading + 90, -outerHalf),
stopHeading,
-0.24,
),
];
@@ -258,57 +260,68 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
}
arm.crosswalkFrame = {
center: envelope.center,
groupDepth: 3.4,
groupDepth: COMPLEX_CROSSWALK_DEPTH_METERS,
supportHeading: normalizeHeading(arm.heading + 90),
envelopeWidthMeters: envelope.widthMeters,
};
arm.crosswalkEvidence = evidence;
}
const crossingHeadings = orthogonalCrossingHeadings(arms.map((arm) => arm.heading));
arms.forEach((arm, index) => {
if (arm.crosswalkFrame) {
arm.crosswalkFrame.heading = crossingHeadings[index];
arm.crosswalkFrame.supportHeading = normalizeHeading(crossingHeadings[index] + 90);
}
});
for (let index = 0; index < arms.length; index += 1) {
const arm = arms[index];
if (!arm.crosswalkFrame) continue;
const item = arm.representative;
const crossingHeading = arm.crosswalkFrame.heading;
const roadEdgeInset = 0.35;
const usableSpan = Math.max(0.42, arm.crosswalkFrame.envelopeWidthMeters - roadEdgeInset * 2);
const endpoints = [
helpers.offsetCoordinate(arm.crosswalkFrame.center, arm.heading + 90, -usableSpan / 2),
helpers.offsetCoordinate(arm.crosswalkFrame.center, arm.heading + 90, usableSpan / 2),
];
const groupDepth = arm.crosswalkFrame.groupDepth;
arm.crosswalkFrame.center = helpers.offsetCoordinate(arm.crosswalkFrame.center, crossingHeading, groupDepth);
arm.crosswalkRadius += groupDepth;
const endpoints = [
helpers.offsetCoordinate(arm.crosswalkFrame.center, crossingHeading + 90, -usableSpan / 2),
helpers.offsetCoordinate(arm.crosswalkFrame.center, crossingHeading + 90, usableSpan / 2),
];
const stripeWidth = 0.42;
const stripeCount = Math.max(6, Math.floor((usableSpan - stripeWidth) / 0.82) + 1);
const stripeSpacing = stripeCount > 1 ? (usableSpan - stripeWidth) / (stripeCount - 1) : 0;
const layout = stripeLayout(usableSpan);
const stripeCount = layout.centers.length;
const stripeSpacing = layout.pitch;
arm.crosswalkFrame.center = midpoint(...endpoints);
arm.crosswalkFrame.endpoints = endpoints;
arm.crosswalkFrame.spanMeters = usableSpan;
arm.crosswalkFrame.roadEdgeInsetMeters = roadEdgeInset;
for (let stripe = 0; stripe < stripeCount; stripe += 1) {
const along = stripeWidth / 2 + stripe * stripeSpacing;
const along = layout.centers[stripe];
const centerPoint = helpers.offsetCoordinate(endpoints[0], bearing(...endpoints), along);
const ring = [
helpers.offsetCoordinate(
helpers.offsetCoordinate(centerPoint, arm.heading, -groupDepth / 2),
arm.heading + 90,
helpers.offsetCoordinate(centerPoint, crossingHeading, -groupDepth / 2),
crossingHeading + 90,
-stripeWidth / 2,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(centerPoint, arm.heading, groupDepth / 2),
arm.heading + 90,
helpers.offsetCoordinate(centerPoint, crossingHeading, groupDepth / 2),
crossingHeading + 90,
-stripeWidth / 2,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(centerPoint, arm.heading, groupDepth / 2),
arm.heading + 90,
helpers.offsetCoordinate(centerPoint, crossingHeading, groupDepth / 2),
crossingHeading + 90,
stripeWidth / 2,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(centerPoint, arm.heading, -groupDepth / 2),
arm.heading + 90,
helpers.offsetCoordinate(centerPoint, crossingHeading, -groupDepth / 2),
crossingHeading + 90,
stripeWidth / 2,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(centerPoint, arm.heading, -groupDepth / 2),
arm.heading + 90,
helpers.offsetCoordinate(centerPoint, crossingHeading, -groupDepth / 2),
crossingHeading + 90,
-stripeWidth / 2,
),
];
@@ -323,7 +336,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
kind: 'complex-crosswalk',
crossing_node_id: item.nodeId,
road_id: item.approach.roadIds[0],
direction: arm.heading,
direction: crossingHeading,
radial_distance_m: arm.crosswalkRadius,
span_m: usableSpan,
road_envelope_span_m: arm.crosswalkFrame.envelopeWidthMeters,
@@ -448,27 +461,29 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
},
geometry: { type: 'Polygon', coordinates: [ring] },
});
const islandDepth = Math.min(7, Math.max(3, apexReach * 0.35));
const islandHalfWidth = Math.min(
2.2,
Math.max(1.2, Math.min(first.widthMeters || 4, second.widthMeters || 4) * 0.28),
if (!first.crosswalkFrame?.endpoints || !second.crosswalkFrame?.endpoints) continue;
const endpointPairs = first.crosswalkFrame.endpoints.flatMap((a) =>
second.crosswalkFrame.endpoints.map((b) => ({ a, b, distance: helpers.distanceMeters(a, b) })),
);
const islandCenter = helpers.offsetCoordinate(apex, bisector, -islandDepth * 0.5);
const islandRing = [
helpers.offsetCoordinate(helpers.offsetCoordinate(apex, bisector, 0.6), bisector + 90, -islandHalfWidth),
helpers.offsetCoordinate(
helpers.offsetCoordinate(islandCenter, bisector, islandDepth * 0.5),
bisector + 90,
-islandHalfWidth * 0.72,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(islandCenter, bisector, islandDepth * 0.5),
bisector + 90,
islandHalfWidth * 0.72,
),
helpers.offsetCoordinate(helpers.offsetCoordinate(apex, bisector, 0.6), bisector + 90, islandHalfWidth),
helpers.offsetCoordinate(helpers.offsetCoordinate(apex, bisector, 0.6), bisector + 90, -islandHalfWidth),
];
const pair = endpointPairs.sort((a, b) => a.distance - b.distance)[0];
const crossingCorner = rayIntersection(
{ point: pair.a, heading: first.crosswalkFrame.heading },
{ point: pair.b, heading: second.crosswalkFrame.heading },
center,
);
if (!crossingCorner) continue;
const stripeWidth = 0.42;
const outerFirst = helpers.offsetCoordinate(
crossingCorner,
first.crosswalkFrame.heading,
first.crosswalkFrame.groupDepth * 2,
);
const outerSecond = helpers.offsetCoordinate(
crossingCorner,
second.crosswalkFrame.heading,
second.crosswalkFrame.groupDepth * 2,
);
const islandRing = buildIslandFromCrossingEdges(crossingCorner, outerFirst, outerSecond);
const publishedIslandRing = islandRing;
if (!cornerOverlapsExclusion(publishedIslandRing, first.cornerKey, '安全岛'))
islands.push({
@@ -493,48 +508,51 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
// Complex junctions carry a default diagonal crossing across each safe
// corner. Source crossing nodes refine provenance/inset values, but are
// not required for the default visual treatment.
const islandMidpoint = publishedIslandRing
.slice(0, -1)
.reduce(
(sum, point) => [
sum[0] + point[0] / (publishedIslandRing.length - 1),
sum[1] + point[1] / (publishedIslandRing.length - 1),
],
[0, 0],
);
const diagonalCenter = helpers.offsetCoordinate(islandMidpoint, bisector, islandHalfWidth + 1.2);
const diagonalSpan = Math.min(6, Math.max(2.4, helpers.distanceMeters(tangents[0], tangents[1]) * 0.35));
const diagonalDepth = 2.4;
const stripeCount = 7;
const stripeWidth = 0.32;
const stripeSpacing = diagonalDepth / stripeCount;
const outerMidpoint = [(outerFirst[0] + outerSecond[0]) / 2, (outerFirst[1] + outerSecond[1]) / 2];
const diagonalDepth = COMPLEX_CROSSWALK_DEPTH_METERS;
const diagonalHeading = bearing(outerFirst, outerSecond) - 90;
const outwardHeading = bearing(crossingCorner, outerMidpoint);
const theta = (outwardHeading * Math.PI) / 180;
const lonScale = 111320 * Math.cos((outerMidpoint[1] * Math.PI) / 180);
const projectedIsland = publishedIslandRing.map((p) => {
const east = (p[0] - outerMidpoint[0]) * lonScale;
const north = (p[1] - outerMidpoint[1]) * 111320;
return [east * Math.cos(theta) - north * Math.sin(theta), east * Math.sin(theta) + north * Math.cos(theta)];
});
const support = crossingArcSupport(projectedIsland, COMPLEX_CROSSWALK_DEPTH_METERS / 2);
if (support === null) continue;
const diagonalCenter = helpers.offsetCoordinate(outerMidpoint, outwardHeading, support + diagonalDepth / 2);
const diagonalSpan = COMPLEX_CROSSWALK_DEPTH_METERS;
const layout = stripeLayout(diagonalDepth);
const stripeCount = layout.centers.length;
const stripeSpacing = layout.pitch;
for (let stripe = 0; stripe < stripeCount; stripe += 1) {
const along = -diagonalDepth / 2 + (stripe + 0.5) * stripeSpacing;
const stripeCenter = helpers.offsetCoordinate(diagonalCenter, bisector, along);
const along = -diagonalDepth / 2 + layout.centers[stripe] - (layout.centers[0] - stripeWidth / 2);
const stripeCenter = helpers.offsetCoordinate(diagonalCenter, diagonalHeading, along);
const ring = [
helpers.offsetCoordinate(
helpers.offsetCoordinate(stripeCenter, bisector + 90, -diagonalSpan / 2),
bisector,
helpers.offsetCoordinate(stripeCenter, diagonalHeading + 90, -diagonalSpan / 2),
diagonalHeading,
-stripeWidth / 2,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(stripeCenter, bisector + 90, diagonalSpan / 2),
bisector,
helpers.offsetCoordinate(stripeCenter, diagonalHeading + 90, diagonalSpan / 2),
diagonalHeading,
-stripeWidth / 2,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(stripeCenter, bisector + 90, diagonalSpan / 2),
bisector,
helpers.offsetCoordinate(stripeCenter, diagonalHeading + 90, diagonalSpan / 2),
diagonalHeading,
stripeWidth / 2,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(stripeCenter, bisector + 90, -diagonalSpan / 2),
bisector,
helpers.offsetCoordinate(stripeCenter, diagonalHeading + 90, -diagonalSpan / 2),
diagonalHeading,
stripeWidth / 2,
),
helpers.offsetCoordinate(
helpers.offsetCoordinate(stripeCenter, bisector + 90, -diagonalSpan / 2),
bisector,
helpers.offsetCoordinate(stripeCenter, diagonalHeading + 90, -diagonalSpan / 2),
diagonalHeading,
-stripeWidth / 2,
),
];
@@ -549,6 +567,9 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
to_boundary: `island:inferred/${first.cornerKey}`,
cluster_id: cluster.id,
kind: 'complex-corner-crosswalk',
stripe_width_m: stripeWidth,
stripe_spacing_m: stripeSpacing,
group_depth_m: COMPLEX_CROSSWALK_DEPTH_METERS,
corner_key: first.cornerKey,
facility_evidence: 'default-complex-junction',
provenance: 'native-road-complex-junction-corner-crosswalk/v1',