fix: close divided two-node T junction pavement

This commit is contained in:
que01 committed 2026-09-15 09:54:46 +08:00
1 parent fda733ce72
commit f122e8236a
3 files changed
+49 -5

No files matched your search

+18 -2
View File
@@ -259,8 +259,24 @@ function buildCoreClosure(topology, graph, center) {
const coreSections = graph.sections.filter((section) => section.ringStatus === 'supported'); const coreSections = graph.sections.filter((section) => section.ringStatus === 'supported');
if (topology.arms.length < 3 || topology.arms.length > 6) if (topology.arms.length < 3 || topology.arms.length > 6)
return { status: 'unsupported', reason: 'unsupported-arm-count' }; return { status: 'unsupported', reason: 'unsupported-arm-count' };
if (topology.arms.length === 3 && topology.arms.some((arm) => arm.members.length !== 1)) if (topology.arms.length === 3 && topology.arms.some((arm) => arm.members.length !== 1)) {
return { status: 'unsupported', reason: 'parallel-carriageway-closure-unresolved' }; // A short source link between clustered junction nodes can split one
// physical T arm into parallel carriageways while still describing one
// continuous paved core. Keep rejecting arbitrary divided T junctions;
// only a configured cluster with a link that fits inside its core may use
// the constrained entry-cell union below.
const coreRadius = Number(topology.cluster?.coreRadiusMeters);
const shortInternalLink =
Number.isFinite(coreRadius) &&
topology.internalRoadIds?.length > 0 &&
topology.internalLinkLengths?.some((length) => length <= coreRadius * 2) &&
topology.arms.some(
(arm) =>
arm.members.length > 1 &&
arm.members.every((member) => Number.isFinite(member.length) && member.length > coreRadius * 2),
);
if (!shortInternalLink) return { status: 'unsupported', reason: 'parallel-carriageway-closure-unresolved' };
}
// Sort whole entry edges, never their individual endpoints. Each valid // Sort whole entry edges, never their individual endpoints. Each valid
// carriageway contributes its full inner seam, including divided arms. // carriageway contributes its full inner seam, including divided arms.
const angle = (point) => Math.atan2(point[1] - center[1], point[0] - center[0]); const angle = (point) => Math.atan2(point[1] - center[1], point[0] - center[0]);
+17 -2
View File
@@ -116,6 +116,8 @@ function resolveJunctionBuildPlan(model, cluster, helpers) {
.map((id) => helpers.junctionPlans.get(id)?.node) .map((id) => helpers.junctionPlans.get(id)?.node)
.filter(Boolean); .filter(Boolean);
const carriageways = []; const carriageways = [];
const internalRoadIds = new Set();
const internalLinkLengths = [];
for (const [nodeId, plan] of helpers.junctionPlans) { for (const [nodeId, plan] of helpers.junctionPlans) {
if (!nodeIds.has(String(nodeId))) continue; if (!nodeIds.has(String(nodeId))) continue;
for (const approach of plan.approaches || []) { for (const approach of plan.approaches || []) {
@@ -126,7 +128,12 @@ function resolveJunctionBuildPlan(model, cluster, helpers) {
(road) => nodeIds.has(String(road.sourceNodeIds[0])) && nodeIds.has(String(road.sourceNodeIds.at(-1))), (road) => nodeIds.has(String(road.sourceNodeIds[0])) && nodeIds.has(String(road.sourceNodeIds.at(-1))),
) )
: nodes.some((node) => node !== plan.node && helpers.distanceMeters(approach.line.at(-1), node) < 4); : nodes.some((node) => node !== plan.node && helpers.distanceMeters(approach.line.at(-1), node) < 4);
if (internal) continue; if (internal) {
roads.forEach((road) => internalRoadIds.add(String(road.id)));
if (Number.isFinite(helpers.lineLengthMeters(approach.line)))
internalLinkLengths.push(helpers.lineLengthMeters(approach.line));
continue;
}
carriageways.push({ carriageways.push({
nodeId: String(nodeId), nodeId: String(nodeId),
approach, approach,
@@ -179,7 +186,15 @@ function resolveJunctionBuildPlan(model, cluster, helpers) {
} }
for (let index = 0; index < arms.length; index += 1) for (let index = 0; index < arms.length; index += 1)
arms[index].cornerKey = `corner:${arms[index].key}>${arms[(index + 1) % arms.length].key}`; arms[index].cornerKey = `corner:${arms[index].key}>${arms[(index + 1) % arms.length].key}`;
return { schema: 'junction-build-plan/v1', cluster, nodeIds: [...nodeIds].sort(), carriageways, arms }; return {
schema: 'junction-build-plan/v1',
cluster,
nodeIds: [...nodeIds].sort(),
internalRoadIds: [...internalRoadIds].sort(),
internalLinkLengths,
carriageways,
arms,
};
} }
module.exports = { MIN_ENTRY_SECTION_METERS, resolveJunctionBuildPlan, stationAtDistanceFrom }; module.exports = { MIN_ENTRY_SECTION_METERS, resolveJunctionBuildPlan, stationAtDistanceFrom };
+14 -1
View File
@@ -19,6 +19,7 @@ const model = compileRoadModel(fs.readFileSync('./inputs/osm/枫树二路.osm',
for (const [name, nodeIds] of Object.entries({ for (const [name, nodeIds] of Object.entries({
cross: ['8005332807', '8024512135', '8024512145', '8024512147'], cross: ['8005332807', '8024512135', '8024512145', '8024512147'],
tee: ['8005332807', '8024512135', '8024512145'], tee: ['8005332807', '8024512135', '8024512145'],
dividedTee: ['1590698046', '6538106539'],
})) { })) {
const geometry = compileGeometry( const geometry = compileGeometry(
model, model,
@@ -27,7 +28,14 @@ for (const [name, nodeIds] of Object.entries({
edgeLines: false, edgeLines: false,
junctionTemplates: { junctionTemplates: {
enabled: true, enabled: true,
clusters: [{ id: name, template: 'complex-junction-v1', coreRadiusMeters: 21, nodeIds }], clusters: [
{
id: name,
template: 'complex-junction-v1',
coreRadiusMeters: name === 'dividedTee' ? 18 : 21,
nodeIds,
},
],
}, },
}, },
); );
@@ -41,6 +49,11 @@ for (const [name, nodeIds] of Object.entries({
geometry.diagnostics.some((item) => item.rule === 'complex-junction-pavement-region-disconnected'), geometry.diagnostics.some((item) => item.rule === 'complex-junction-pavement-region-disconnected'),
false, false,
); );
if (name === 'dividedTee')
assert.ok(
geometry.roadSurface.features.some((feature) => feature.properties.kind === 'complex-core'),
'dividedTee must publish a closed complex core',
);
// The region owns road-arm crossings. The island-hypotenuse crossing is a // The region owns road-arm crossings. The island-hypotenuse crossing is a
// pedestrian facility above the road layer and does not expand pavement. // pedestrian facility above the road layer and does not expand pavement.
for (const stripe of geometry.crosswalks.features.filter( for (const stripe of geometry.crosswalks.features.filter(