feat(junction): close verified complex cores

This commit is contained in:
que01 committed 2026-09-09 09:15:58 +08:00
1 parent b4abfdb870
commit 88d8b841e5
5 files changed
+97 -25

No files matched your search

@@ -20,6 +20,7 @@
- [x] 将复杂路口边界半径映射到来源折线的实际首次相交站点,并把同一车行道裁切传递给道路面、边线、中心线、人行道和车道发布线。
- [x] 为每条车行道生成带稳定边引用的内外断面,复杂进口面直接消费这些边;核心闭合边显式保留为待解,避免臆造跨分隔通行面。
- [x] 对每臂单一来源车行道,用入口内断面原始边闭合核心面并保持共享接缝;分隔/并行车行道无法确认中心通行关系时拒绝闭合并报告对象级诊断。
- [ ] 实现接入断面到固定远端过渡;以共享边界构建中心/进口/角部,取消独立半径拼接作为权威。
- [ ] 支持凹形与已知排除区域,检查环、自交、接缝、必要连接;设计边界可行域并由 solver/manifest 共用。
- [ ] 审计 roadSurface、sidewalkSurface、edgeLines、lane/center markings 的每个裁切入口,确保消费同一计划。
+8 -21
View File
@@ -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,
),
);
+62 -1
View File
@@ -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 };
+11 -2
View File
@@ -91,7 +91,16 @@ const complexGeometry = compiler.nativeRoad.compileGeometry(
const complexCore = complexGeometry.roadSurface.features.find(
(feature) => feature.properties?.kind === 'complex-core' && feature.properties?.cluster_id === 'fixture-five-arm',
);
assert.equal(complexCore?.properties?.shape_kind, 'multi-arm');
assert.equal(complexCore?.properties?.arm_count, 5);
// This fixture contains multiple source carriageways within several arms. The
// compiler must retain those independent sections rather than filling their
// unknown interstitial areas with a synthetic core.
assert.equal(complexCore, undefined);
assert.ok(
complexGeometry.diagnostics.some(
(item) =>
item.rule === 'complex-junction-core-closure-unsupported' &&
item.subjectId === 'junction-cluster:fixture-five-arm',
),
);
assert.ok(complexGeometry.roadSurface.features.some((feature) => feature.properties?.kind === 'complex-approach'));
console.log('road compiler package tests passed');
+15 -1
View File
@@ -4,7 +4,7 @@
const assert = require('assert/strict');
const { resolveJunctionBuildPlan, stationAtDistanceFrom } = require('../src/compile/junction-build-plan');
const { buildJunctionBoundaryGraph } = require('../src/compile/junction-boundary-graph');
const { buildJunctionBoundaryGraph, buildCoreClosure } = require('../src/compile/junction-boundary-graph');
const { classifyJunctionShape } = require('../src/compile/complex-junction');
const metersPerDegree = 111320;
@@ -101,6 +101,10 @@ assert.equal(dividedBoundaryGraph.status, 'entry-sections-only');
assert.equal(dividedBoundaryGraph.sections.length, divided.topology.carriageways.length);
assert.equal(new Set(dividedBoundaryGraph.sections.map((section) => section.carriagewayKey)).size, 4);
assert.equal(dividedBoundaryGraph.edges.length, dividedBoundaryGraph.sections.length * 4);
assert.equal(
buildCoreClosure(divided.topology, dividedBoundaryGraph, point(0, 0)).reason,
'parallel-carriageway-closure-unresolved',
);
// A T junction has explicit, source-stable entry sections. Closure edges are a
// later BoundaryGraph concern and must not be fabricated by topology parsing.
@@ -112,6 +116,16 @@ const tee = topology('tee', [
assert.equal(tee.topology.arms.length, 3);
assert.equal(classifyJunctionShape(tee.topology.arms, point(0, 0), tee.helpers).kind, 't-junction');
assert.ok(tee.topology.carriageways.every((item) => item.entrySection.feasibility === 'supported'));
const teeBoundaryGraph = buildJunctionBoundaryGraph(
tee.topology,
point(0, 0),
{ outerRadiusFor: () => 30, innerRadiusFor: () => 10 },
tee.helpers,
);
const teeCore = buildCoreClosure(tee.topology, teeBoundaryGraph, point(0, 0));
assert.equal(teeCore.status, 'supported');
assert.equal(teeCore.sharedEdgeRefs.length, teeBoundaryGraph.sections.length);
assert.ok(teeCore.ring.every((coordinate) => coordinate.every(Number.isFinite)));
// Offset and unequal-width approaches preserve individual source sections and
// local section tangents rather than a single arm envelope.