feat(junction): classify complex junction shapes
This commit is contained in:
1 parent
38ea779d9b
commit
a359f88edc
13 files changed
+440
-14
No files matched your search
@@ -74,6 +74,23 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
(candidate) => Math.abs(normalizeHeading(candidate.heading - representative.heading)) < 20,
|
||||
),
|
||||
}));
|
||||
const shape = classifyJunctionShape(arms, center, helpers);
|
||||
if (shape.kind === 'unsupported')
|
||||
return {
|
||||
features: [],
|
||||
diagnostics: [
|
||||
helpers.diagnostic(
|
||||
'warning',
|
||||
`junction-cluster:${cluster.id}`,
|
||||
[...nodeIds],
|
||||
'complex-junction-shape-fallback',
|
||||
`${shape.label},已回退为普通路口渲染。`,
|
||||
center,
|
||||
),
|
||||
],
|
||||
shape,
|
||||
center,
|
||||
};
|
||||
const outerRadius = complexJunctionMetrics(cluster).approachOuterRadius;
|
||||
const boundaryParts = [];
|
||||
const crosswalks = [];
|
||||
@@ -447,15 +464,25 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
geometry: { type: 'Polygon', coordinates: [sidewalkRing] },
|
||||
});
|
||||
}
|
||||
const corePoints = boundaryParts
|
||||
.flatMap(({ item, inner, innerHalf }) => [
|
||||
helpers.offsetCoordinate(inner, item.heading + 90, innerHalf),
|
||||
helpers.offsetCoordinate(inner, item.heading - 90, innerHalf),
|
||||
])
|
||||
// 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 coreRing = roundedPolygonRing(corePoints, 0.16);
|
||||
const features = [
|
||||
{
|
||||
const coreValid = corePoints.length >= 6 && !ringSelfIntersects([...corePoints, corePoints[0]]);
|
||||
const coreRing = coreValid ? roundedPolygonRing(corePoints, 0.16) : null;
|
||||
const features = [];
|
||||
if (coreRing)
|
||||
features.push({
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
native_id: `complex-junction:${cluster.id}:core`,
|
||||
@@ -467,13 +494,28 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
configured_radius_m: cluster.coreRadiusMeters,
|
||||
approach_count: approaches.length,
|
||||
carriageway_count: carriageways.length,
|
||||
shape_kind: shape.kind,
|
||||
shape_label: shape.label,
|
||||
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',
|
||||
},
|
||||
geometry: { type: 'Polygon', coordinates: [coreRing] },
|
||||
},
|
||||
];
|
||||
});
|
||||
else {
|
||||
cornerDiagnostics.push(
|
||||
helpers.diagnostic(
|
||||
'warning',
|
||||
`junction-cluster:${cluster.id}`,
|
||||
[...nodeIds],
|
||||
'complex-junction-core-fallback',
|
||||
'路口中心区域几何不可靠,已跳过复杂中心面并保留各进口道路面。',
|
||||
center,
|
||||
),
|
||||
);
|
||||
}
|
||||
for (const { item, outer, inner, outerHalf, innerHalf } of boundaryParts) {
|
||||
const ring = [
|
||||
helpers.offsetCoordinate(outer, item.heading + 90, outerHalf),
|
||||
@@ -526,6 +568,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
crosswalks,
|
||||
stopLines,
|
||||
center,
|
||||
shape,
|
||||
approaches,
|
||||
diagnostics: [
|
||||
...cornerDiagnostics,
|
||||
@@ -536,14 +579,49 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
[...nodeIds],
|
||||
calibration ? 'complex-junction-reference-calibrated' : 'complex-junction-generated',
|
||||
calibration
|
||||
? `已使用参考几何校准参数后,由 OSM/native 重新生成 ${approaches.length} 个进口、道路面、中央分隔带、斑马线和停止线。`
|
||||
: `已独立生成 ${approaches.length} 个进口、道路面、中央分隔带、斑马线和停止线。`,
|
||||
? `已识别为${shape.label},使用参考几何校准参数后重新生成 ${approaches.length} 个进口、道路面、斑马线和停止线。`
|
||||
: `已识别为${shape.label},独立生成 ${approaches.length} 个进口、道路面、斑马线和停止线。`,
|
||||
center,
|
||||
),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function classifyJunctionShape(arms, center, helpers) {
|
||||
const headings = arms.map((arm) => arm.heading);
|
||||
const throughPairs = [];
|
||||
for (let first = 0; first < headings.length; first += 1) {
|
||||
for (let second = first + 1; second < headings.length; second += 1) {
|
||||
const delta = Math.abs(normalizeHeading(headings[first] - headings[second]));
|
||||
if (delta >= 155) throughPairs.push([first, second]);
|
||||
}
|
||||
}
|
||||
const sorted = [...headings].sort((a, b) => a - b);
|
||||
const gaps = sorted.map((heading, index) => positiveHeadingDelta(heading, sorted[(index + 1) % sorted.length]));
|
||||
const hasRightAngleCross =
|
||||
arms.length === 4 && gaps.filter((gap) => gap >= 55 && gap <= 125).length >= 3 && throughPairs.length >= 2;
|
||||
const hasOppositePair = throughPairs.length >= 1;
|
||||
if (arms.length === 3 && hasOppositePair)
|
||||
return { kind: 't-junction', label: '3 臂 T 字路口', throughPairCount: throughPairs.length };
|
||||
if (hasRightAngleCross) {
|
||||
const centers = arms.map((arm) => arm.members[0]?.approach?.line?.at?.(-1)).filter(Boolean);
|
||||
const spread =
|
||||
centers.length === arms.length
|
||||
? Math.max(...centers.map((point) => helpers.distanceMeters(point, center))) -
|
||||
Math.min(...centers.map((point) => helpers.distanceMeters(point, center)))
|
||||
: 0;
|
||||
return {
|
||||
kind: spread > 12 ? 'offset-cross' : 'cross',
|
||||
label: spread > 12 ? '4 臂偏置十字路口' : '4 臂十字路口',
|
||||
throughPairCount: throughPairs.length,
|
||||
};
|
||||
}
|
||||
if (arms.length >= 3 && arms.length <= 8) {
|
||||
return { kind: 'multi-arm', label: `${arms.length} 臂非规则路口`, throughPairCount: throughPairs.length };
|
||||
}
|
||||
return { kind: 'unsupported', label: '暂不支持的路口形态', throughPairCount: throughPairs.length };
|
||||
}
|
||||
|
||||
function readReferenceCalibration(cluster) {
|
||||
if (!cluster.referenceFile || !fs.existsSync(cluster.referenceFile)) return null;
|
||||
try {
|
||||
@@ -829,4 +907,4 @@ function interpolateCoordinate(first, second, ratio) {
|
||||
return [first[0] + (second[0] - first[0]) * ratio, first[1] + (second[1] - first[1]) * ratio];
|
||||
}
|
||||
|
||||
module.exports = { buildComplexJunctionGeometry, complexJunctionMetrics };
|
||||
module.exports = { buildComplexJunctionGeometry, classifyJunctionShape, complexJunctionMetrics };
|
||||
Reference in new issue
Block a user