feat: solve complete junction island contacts

This commit is contained in:
que01 committed 2026-09-14 08:59:32 +08:00
1 parent 7a7912f302
commit 1b91e280bc
5 files changed
+164 -7

No files matched your search

+44 -5
View File
@@ -10,6 +10,7 @@ const {
orthogonalCrossingHeadings,
stripeLayout,
crossingArcSupport,
solveIslandContacts,
} = require('./junction-facility-composition');
const { complexJunctionMetrics: calculateComplexJunctionMetrics } = require('./junction-metrics');
const { convertGeoJson, boundsOf } = require('../reference/gaode');
@@ -483,8 +484,30 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
second.crosswalkFrame.heading,
second.crosswalkFrame.groupDepth * 2,
);
const islandRing = buildIslandFromCrossingEdges(crossingCorner, outerFirst, outerSecond);
const publishedIslandRing = islandRing;
const lonScale = 111320 * Math.cos((crossingCorner[1] * Math.PI) / 180);
const toLocal = (point) => [(point[0] - crossingCorner[0]) * lonScale, (point[1] - crossingCorner[1]) * 111320];
const fromLocal = (point) => [crossingCorner[0] + point[0] / lonScale, crossingCorner[1] + point[1] / 111320];
const contactSolution = solveIslandContacts(
[[0, 0], toLocal(outerFirst)],
[[0, 0], toLocal(outerSecond)],
COMPLEX_CROSSWALK_DEPTH_METERS,
{ maxLegLength: Math.max(outerRadius * 2, COMPLEX_CROSSWALK_DEPTH_METERS * 4) },
);
if (contactSolution.status !== 'solved') {
cornerDiagnostics.push(
helpers.diagnostic(
'warning',
`corner:${first.cornerKey}`,
[...nodeIds],
'complex-junction-island-infeasible',
contactSolution.reason,
crossingCorner,
),
);
continue;
}
const publishedIslandRing = contactSolution.ring.map(fromLocal);
const greenRing = contactSolution.greenRing.map(fromLocal);
if (!cornerOverlapsExclusion(publishedIslandRing, first.cornerKey, '安全岛'))
islands.push({
type: 'Feature',
@@ -496,9 +519,25 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
corner_key: first.cornerKey,
facility_evidence: 'inferred-complex-junction-corner',
provenance: 'native-road-complex-junction-inferred-island/v1',
island_leg_lengths_m: contactSolution.legLengths,
contact_points: greenRing.slice(0, -1),
},
geometry: { type: 'Polygon', coordinates: [publishedIslandRing] },
});
if (!cornerOverlapsExclusion(greenRing, first.cornerKey, '安全岛绿色接触区'))
islands.push({
type: 'Feature',
properties: {
native_id: `complex-corner-island-green:${cluster.id}:${index + 1}`,
object_key: `island:inferred/${first.cornerKey}`,
cluster_id: cluster.id,
corner_key: first.cornerKey,
kind: 'island-green',
island_key: `island:inferred/${first.cornerKey}`,
provenance: 'native-road-complex-junction-island-contact-hexagon/v1',
},
geometry: { type: 'Polygon', coordinates: [greenRing] },
});
if (
!first.members.every((item) => publishedCarriageways.has(item.key)) ||
@@ -508,14 +547,14 @@ 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 outerMidpoint = [(outerFirst[0] + outerSecond[0]) / 2, (outerFirst[1] + outerSecond[1]) / 2];
const outerMidpoint = fromLocal(contactSolution.thirdCenter);
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 diagonalLonScale = 111320 * Math.cos((outerMidpoint[1] * Math.PI) / 180);
const projectedIsland = publishedIslandRing.map((p) => {
const east = (p[0] - outerMidpoint[0]) * lonScale;
const east = (p[0] - outerMidpoint[0]) * diagonalLonScale;
const north = (p[1] - outerMidpoint[1]) * 111320;
return [east * Math.cos(theta) - north * Math.sin(theta), east * Math.sin(theta) + north * Math.cos(theta)];
});