feat(junction): close verified complex cores
This commit is contained in:
1 parent
b4abfdb870
commit
88d8b841e5
5 files changed
+97
-25
No files matched your search
@@ -3,7 +3,7 @@
|
||||
const fs = require('fs');
|
||||
const { structureFromTopology } = require('./junction-topology');
|
||||
const { resolveJunctionBuildPlan, stationAtDistanceFrom } = require('./junction-build-plan');
|
||||
const { buildJunctionBoundaryGraph } = require('./junction-boundary-graph');
|
||||
const { buildJunctionBoundaryGraph, buildCoreClosure } = require('./junction-boundary-graph');
|
||||
const { convertGeoJson, boundsOf } = require('../reference/gaode');
|
||||
const metricsCache = new WeakMap();
|
||||
const CORNER_FILLET_SEGMENTS = 12;
|
||||
@@ -485,22 +485,8 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
geometry: { type: 'Polygon', coordinates: [sidewalkRing] },
|
||||
});
|
||||
}
|
||||
// Build the conflict area from one envelope per effective arm. Using every
|
||||
// carriageway here duplicates same-direction lanes and can create a warped
|
||||
// or self-crossing core for 2x1/T-shaped junctions.
|
||||
const corePoints = arms
|
||||
.flatMap((arm) => {
|
||||
const envelope = armEnvelopeAtRadius(arm, coreRadius * 0.7, center, helpers);
|
||||
if (!envelope) return [];
|
||||
const half = envelope.widthMeters / 2;
|
||||
return [
|
||||
helpers.offsetCoordinate(envelope.center, arm.heading + 90, half),
|
||||
helpers.offsetCoordinate(envelope.center, arm.heading - 90, half),
|
||||
];
|
||||
})
|
||||
.sort((first, second) => angleAround(center, first) - angleAround(center, second));
|
||||
const coreValid = corePoints.length >= 6 && !ringSelfIntersects([...corePoints, corePoints[0]]);
|
||||
const coreRing = coreValid ? roundedPolygonRing(corePoints, 0.16) : null;
|
||||
const coreClosure = buildCoreClosure(topology, boundaryGraph, center);
|
||||
const coreRing = coreClosure.status === 'supported' ? coreClosure.ring : null;
|
||||
const features = [];
|
||||
if (coreRing)
|
||||
features.push({
|
||||
@@ -520,8 +506,9 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
arm_count: arms.length,
|
||||
through_pair_count: shape.throughPairCount,
|
||||
approach_headings: sorted.map((item) => Math.round(item.heading * 10) / 10),
|
||||
corner_rounding_ratio: 0.16,
|
||||
provenance: 'native-road-complex-junction/v6-rounded-core',
|
||||
boundary_refs: coreClosure.sharedEdgeRefs,
|
||||
closure_count: coreClosure.closureCount,
|
||||
provenance: 'native-road-complex-junction/v7-shared-entry-core',
|
||||
},
|
||||
geometry: { type: 'Polygon', coordinates: [coreRing] },
|
||||
});
|
||||
@@ -531,8 +518,8 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
'warning',
|
||||
`junction-cluster:${cluster.id}`,
|
||||
[...nodeIds],
|
||||
'complex-junction-core-fallback',
|
||||
'路口中心区域几何不可靠,已跳过复杂中心面并保留各进口道路面。',
|
||||
'complex-junction-core-closure-unsupported',
|
||||
`路口中心区域缺少可验证的闭合边(${coreClosure.reason}),已保留各进口道路面。`,
|
||||
center,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -92,4 +92,65 @@ function buildJunctionBoundaryGraph(topology, center, radii, helpers) {
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { buildJunctionBoundaryGraph };
|
||||
function ringSelfIntersects(ring) {
|
||||
const cross = (a, b, c) => (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
|
||||
const straddles = (p1, p2, p3, p4) => {
|
||||
const d1 = cross(p3, p4, p1);
|
||||
const d2 = cross(p3, p4, p2);
|
||||
const d3 = cross(p1, p2, p3);
|
||||
const d4 = cross(p1, p2, p4);
|
||||
return ((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) && ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0));
|
||||
};
|
||||
for (let first = 0; first < ring.length - 1; first += 1) {
|
||||
for (let second = first + 2; second < ring.length - 1; second += 1) {
|
||||
if (first === 0 && second === ring.length - 2) continue;
|
||||
if (straddles(ring[first], ring[first + 1], ring[second], ring[second + 1])) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function signedArea(ring) {
|
||||
return ring.slice(1).reduce((area, point, index) => area + ring[index][0] * point[1] - point[0] * ring[index][1], 0);
|
||||
}
|
||||
|
||||
// A central paved region is safe to infer only when every arm has exactly one
|
||||
// source carriageway. Its shared entry seams are the sections' `inner` edges;
|
||||
// every remaining edge is an explicit closure between adjacent arms.
|
||||
function buildCoreClosure(topology, graph, center) {
|
||||
if (topology.arms.some((arm) => arm.members.length !== 1))
|
||||
return { status: 'unsupported', reason: 'parallel-carriageway-closure-unresolved' };
|
||||
if (graph.sections.length < 3 || graph.sections.length > 6)
|
||||
return { status: 'unsupported', reason: 'unsupported-arm-count' };
|
||||
const points = graph.sections
|
||||
.flatMap((section) => [
|
||||
{ point: section.inner.left, edgeRef: section.edgeRefs.inner },
|
||||
{ point: section.inner.right, edgeRef: section.edgeRefs.inner },
|
||||
])
|
||||
.filter((item) => item.point?.every(Number.isFinite))
|
||||
.sort(
|
||||
(first, second) =>
|
||||
Math.atan2(first.point[1] - center[1], first.point[0] - center[0]) -
|
||||
Math.atan2(second.point[1] - center[1], second.point[0] - center[0]),
|
||||
);
|
||||
const ring = [...points.map((item) => item.point), points[0]?.point].filter(Boolean);
|
||||
const pairedEdges = new Map();
|
||||
points.forEach((item, index) => {
|
||||
if (!pairedEdges.has(item.edgeRef)) pairedEdges.set(item.edgeRef, []);
|
||||
pairedEdges.get(item.edgeRef).push(index);
|
||||
});
|
||||
const paired = [...pairedEdges.values()].every((indexes) => {
|
||||
if (indexes.length !== 2) return false;
|
||||
return Math.abs(indexes[0] - indexes[1]) === 1 || (indexes[0] === 0 && indexes[1] === points.length - 1);
|
||||
});
|
||||
if (ring.length < 7 || !paired || Math.abs(signedArea(ring)) < 1e-14 || ringSelfIntersects(ring))
|
||||
return { status: 'unsupported', reason: 'core-closure-invalid' };
|
||||
return {
|
||||
status: 'supported',
|
||||
ring,
|
||||
sharedEdgeRefs: [...pairedEdges.keys()].sort(),
|
||||
closureCount: graph.sections.length,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { buildJunctionBoundaryGraph, buildCoreClosure };
|
||||
Reference in new issue
Block a user