fix: share complex junction entry sections across layers

This commit is contained in:
que01 committed 2026-09-09 17:23:17 +08:00
1 parent 49212b3f34
commit cd65dbe879
5 files changed
+221 -50

No files matched your search

+13
View File
@@ -405,3 +405,16 @@ placeholder. Explicit transition stations are clamped to the source polyline
range for legacy/direct compiler inputs and marked
`insufficient-source-length` when the requested length cannot fit. The solver
rejects such values before they can be saved.
## Shared complex approach consumers
`compileGeometry()` builds each complex approach BoundaryGraph once. External
road surfaces, edges, sidewalks, center markings and published lane centerlines
read its source-polyline `outer.stationMeters`; do not independently reconstruct
`outerRadius - cutback` in a consumer. The complex surface generator receives the
same graph instance. Transition lane endpoints interpolate the respective outer
and inner section edges, preserving the fixed source width when the inner width
changes. Unsupported, invalid or excluded transitions do not publish preview
lanes or their derived markings. This contract does not yet replace the separate
corner sidewalk overrun geometry or validate all short-road suppression paths.
@@ -1,6 +1,6 @@
# 实施计划与阶段出口
当前为 planning;用户正在审阅通用方向。创建任务不等于实施批准。单一任务按串行里程碑交付;每阶段必须提交证据,不能以接口有返回代替效果验收。
当前为 in_progress;用户已批准实施。单一任务按串行里程碑交付;每阶段必须提交证据,不能以接口有返回代替效果验收。
## 0. 契约与最小反例
@@ -25,7 +25,7 @@
- [ ] 支持凹形与已知排除区域,检查环、自交、接缝、必要连接;设计边界可行域并由 solver/manifest 共用。
- [ ] 审计 roadSurface、sidewalkSurface、edgeLines、lane/center markings 的每个裁切入口,确保消费同一计划。
- [ ] 出口 A3:接缝≤1 cm,必要区域连通,无自交与排除区侵占;自动测试验证实际几何,不只是参数回显。
- 已验证:3~6 臂核心环闭合、正面积、无自交、共享内边邻接;当前 maxSharedSeamErrorMeters 仅以邻接成立返回 0、不成立返回 Infinity,不等同于全图层实际接缝测量;入口 ring 闭合/有限/正面积;短过渡、零长度边、零宽度和排除区相切均有失败回归。
- 已验证:3~6 臂核心环闭合、正面积、无自交、共享内边邻接;maxSharedSeamErrorMeters 已测量核心与入口内边端点的实际米制误差,尚不等同于全图层接缝测量;入口 ring 闭合/有限/正面积;短过渡、零长度边、零宽度和排除区相切均有失败回归。
- 待完成:凹形/多区域/孔洞、全图层连通性和统一接缝误差测量。
- [ ] 此阶段不通过,不开启新几何控件。
@@ -82,3 +82,12 @@ complex-junction.js / native-road.js:构建与全部消费者;direct-edit-so
本轮质量门:npm test 通过;npm run test:client 通过;npm run test:client:unit 15 文件/188 测试通过;npm run test:e2e(包含 production build)11 测试通过,包含保存后重置与放弃恢复;npm run format:check 与 git diff --check 通过。构建仍有既有 bundle 大小提示。遵循用户“整体任务完成再提交”,本轮未提交、未归档父任务。
下一阶段已实现共享内边的实际米制端点误差:`sharedSeamErrors` 逐车行道报告,缺失/非邻接为 Infinity;回归通过人为 2 米偏移验证指标变化。显式过渡站点统一限制在来源折线范围,超长请求标记来源长度不足并由 solver 拒绝。全图层接缝、凹形多区域和真实 OSM 视觉验收仍未完成。
## 共享入口断面消费交付记录
编译器现在只生成一次复杂入口 BoundaryGraph,外部道路面、边线、中心线、人行道、车道发布线的裁切直接读取其 outer.stationMeters;复杂过渡面复用同一图实例。过渡车道线按内外断面分别插值,局部展宽保持外侧车道端点固定,内部端点响应宽度与过渡长度。无效、来源长度不足或侵入已知排除区的过渡不发布预览车道线及其派生标线。
回归证据:真实 OSM fixture 的可配对外部道路面接缝实际误差 ≤1 cm;过渡车道起点与外断面一致;局部展宽保持外部道路面、边线、人行道、中心线和车道发布线不变;不可构建过渡不发布悬空预览车道线。npm test、客户端类型检查、188 项客户端单测、11 项浏览器测试、格式检查通过。
仍未关闭阶段 2:外侧偏移曲线的顶点切向统一、短道路被整体吞入路口时所有附属图层的发布一致性、角部步行带独立半径与 overrun 拼接、凹形/多区域/孔洞连通性仍需处理。当前回归证明了现有 fixture 的接缝,不冒称任意曲线与相邻多路口已全部满足 A3。父任务保持进行中。
+19 -10
View File
@@ -106,16 +106,9 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
(crossingPlans.get(arm.key)?.baseRadius || coreRadius * 0.68) +
(crossingControls.get(`crossing:${arm.key}`)?.crosswalkInsetMeters || 0),
);
const boundaryGraph = buildJunctionBoundaryGraph(
topology,
center,
{
outerRadiusFor: (item) => Math.max(coreRadius + 4, outerRadius - Math.max(0, Number(item.approach.cutback) || 0)),
innerRadiusFor: () => complexJunctionMetrics(cluster).approachInnerRadius,
},
helpers,
model.exclusionRegions || [],
);
const boundaryGraph =
helpers.boundaryGraph ||
buildComplexApproachBoundaryGraph(topology, center, cluster, helpers, model.exclusionRegions || []);
for (const section of boundaryGraph.sections) {
const item = carriageways.find((candidate) => candidate.key === section.carriagewayKey);
if (!item) continue;
@@ -639,6 +632,21 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
};
}
function buildComplexApproachBoundaryGraph(topology, center, cluster, helpers, exclusionRegions = []) {
const metrics = complexJunctionMetrics(cluster);
return buildJunctionBoundaryGraph(
topology,
center,
{
outerRadiusFor: (item) =>
Math.max(metrics.coreRadius + 4, metrics.approachOuterRadius - Math.max(0, Number(item.approach.cutback) || 0)),
innerRadiusFor: () => metrics.approachInnerRadius,
},
helpers,
exclusionRegions,
);
}
function classifyJunctionShape(arms, center, helpers) {
const headings = arms.map((arm) => arm.heading);
const throughPairs = [];
@@ -903,6 +911,7 @@ function directionalProjectionMeters(origin, point, heading) {
module.exports = {
resolveComplexJunctionTopology,
buildComplexJunctionGeometry,
buildComplexApproachBoundaryGraph,
classifyJunctionShape,
complexJunctionMetrics,
};
+56 -38
View File
@@ -5,6 +5,7 @@ const path = require('path');
const { arrowRingsAt, normalizeManeuver } = require('./turn-lane-arrows');
const {
buildComplexJunctionGeometry,
buildComplexApproachBoundaryGraph,
complexJunctionMetrics,
resolveComplexJunctionTopology,
} = require('./complex-junction');
@@ -672,9 +673,9 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
const generatedComplexCrosswalks = [];
const generatedComplexStopLines = [];
// The external road and its complex-junction carriageway must end at the
// same radial boundary. A fixed outer radius here while the carriageway used
// its per-arm cutback left a visible asphalt gap between the two surfaces.
const complexApproachBoundaries = complexApproachBoundaryRadii(model, activeClusters, junctionPlans);
// same source section. The graph is built once and reused by surfaces,
// road trims, and transition markings rather than re-solving each radius.
const complexApproachBoundaries = complexApproachBoundarySections(model, activeClusters, junctionPlans);
for (const road of model.roads) {
const segmentKey = road.segmentId;
if (emittedSegments.has(segmentKey)) continue;
@@ -792,6 +793,7 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
headingAtEndpoint,
headingVector,
circleRing,
boundaryGraph: complexApproachBoundaries.get(cluster.id)?.boundaryGraph,
clusterCornerRadii: options.directEdit?.clusterCorners?.get(String(cluster.id)),
clusterCrossingControls: options.directEdit?.clusterCrossings?.get(String(cluster.id)),
});
@@ -2323,21 +2325,26 @@ function compileLaneCenterlines(
const corridorRoads = approach.roadIds
.map((roadId) => model.roads.find((road) => road.id === roadId))
.filter(Boolean);
const boundaryRadii = corridorRoads
.map((road) => complexBoundaries.get(cluster.id)?.get(road.id))
.filter(Number.isFinite);
const outerRadius = boundaryRadii[0] ?? complexJunctionMetrics(cluster).approachOuterRadius;
const length = Math.min(
distanceAlongLineToRadius(approach.line, compositeCenter, outerRadius),
lineLengthMeters(approach.line),
);
const section = corridorRoads.map((road) => complexBoundaries.get(cluster.id)?.get(road.id)).find(Boolean);
if (
cluster.template === 'complex-junction-v1' &&
(!section ||
section.ringStatus !== 'supported' ||
section.transitionStatus !== 'supported' ||
section.exclusionStatus !== 'clear')
)
continue;
const length =
section?.outer.stationMeters ??
distanceAlongLineToRadius(approach.line, compositeCenter, complexJunctionMetrics(cluster).approachOuterRadius);
if (length < 12) continue;
const line = approach.line;
const outer = pointAlongLine(line, Math.max(0, length));
const inner = pointAlongLine(
line,
Math.min(Math.max(3, Number(cluster.coreRadiusMeters || 28) * 0.14), Math.max(3, length - 8)),
);
const outer = section?.outer.point || pointAlongLine(approach.line, length);
const inner =
section?.inner.point ||
pointAlongLine(
approach.line,
Math.min(Math.max(3, Number(cluster.coreRadiusMeters || 28) * 0.14), Math.max(3, length - 8)),
);
const incoming = corridorRoads.some((road) => String(road.sourceNodeIds.at(-1)) === String(corridor.nodeId));
const count = Math.max(
1,
@@ -2351,8 +2358,13 @@ function compileLaneCenterlines(
const across = [-normalized[1], normalized[0]];
for (let index = 0; index < count; index += 1) {
const offset = approach.widthMeters / 2 - laneWidth * (index + 0.5);
const start = unproject([across[0] * offset, across[1] * offset], outer);
const end = unproject([across[0] * offset, across[1] * offset], inner);
const ratio = (index + 0.5) / count;
const start = section
? interpolate(section.outer.right, section.outer.left, ratio)
: unproject([across[0] * offset, across[1] * offset], outer);
const end = section
? interpolate(section.inner.right, section.inner.left, ratio)
: unproject([across[0] * offset, across[1] * offset], inner);
const maneuver = incoming ? (index === 0 ? 'left' : index === count - 1 ? 'right' : 'through') : 'outbound';
// Preview lanes are laid out radially from the outer radius inwards, so
// an untrimmed one runs straight over the arm crossing. Stop it at the
@@ -2371,6 +2383,8 @@ function compileLaneCenterlines(
road_id: corridorRoads[0]?.id || null,
cluster_id: cluster.id,
cluster_preview: true,
carriageway_key: section?.carriagewayKey || null,
boundary_refs: section?.edgeRefs || null,
incoming,
lane_index: index + 1,
maneuver,
@@ -3294,40 +3308,44 @@ function trimLineAtJunctions(line, sourceNodeIds, junctionPlans) {
return result;
}
function trimLineAtComplexCluster(line, sourceNodeIds, junctionPlans, cluster, center, boundaryRadius) {
function trimLineAtComplexCluster(line, sourceNodeIds, junctionPlans, cluster, center, boundarySection) {
if (!center || line.length < 2) return trimLineAtJunctions(line, sourceNodeIds, junctionPlans);
const radius = Number.isFinite(boundaryRadius) ? boundaryRadius : complexJunctionMetrics(cluster).approachOuterRadius;
const radius = complexJunctionMetrics(cluster).approachOuterRadius;
const startInCluster = cluster.nodeIds.map(String).includes(String(sourceNodeIds[0]));
const endInCluster = cluster.nodeIds.map(String).includes(String(sourceNodeIds.at(-1)));
const available = lineLengthMeters(line);
const startDistance = startInCluster ? distanceAlongLineToRadius(line, center, radius) : 0;
const endDistance = endInCluster ? distanceAlongLineToRadius([...line].reverse(), center, radius) : 0;
const startDistance = startInCluster
? (boundarySection?.outer.stationMeters ?? distanceAlongLineToRadius(line, center, radius))
: 0;
const endDistance = endInCluster
? (boundarySection?.outer.stationMeters ?? distanceAlongLineToRadius([...line].reverse(), center, radius))
: 0;
const startCutback = startDistance > 0 && available > startDistance + 1 ? startDistance : 0;
const endCutback = endDistance > 0 && available > endDistance + 1 ? endDistance : 0;
if (!startCutback && !endCutback) return line;
return trimLineRange(line, startCutback, endCutback);
}
function complexApproachBoundaryRadii(model, clusters, junctionPlans) {
function complexApproachBoundarySections(model, clusters, junctionPlans) {
const result = new Map();
const helpers = { junctionPlans, distanceMeters, lineLengthMeters, headingAtEndpoint };
for (const cluster of clusters) {
if (cluster.template !== 'complex-junction-v1') continue;
const outerRadius = complexJunctionMetrics(cluster).approachOuterRadius;
const topology = resolveComplexJunctionTopology(model, cluster, {
junctionPlans,
distanceMeters,
lineLengthMeters,
headingAtEndpoint,
});
const radii = new Map();
const topology = resolveComplexJunctionTopology(model, cluster, helpers);
const graph = buildComplexApproachBoundaryGraph(
topology,
clusterCenter(cluster, junctionPlans),
cluster,
helpers,
model.exclusionRegions || [],
);
const sections = new Map();
sections.boundaryGraph = graph;
for (const item of topology.carriageways) {
const radius = Math.max(
complexJunctionMetrics(cluster).coreRadius + 4,
outerRadius - Math.max(0, item.approach.cutback || 0),
);
for (const roadId of item.approach.roadIds) radii.set(roadId, radius);
const section = graph.sections.find((candidate) => candidate.carriagewayKey === item.key);
for (const roadId of item.approach.roadIds) sections.set(roadId, section);
}
result.set(cluster.id, radii);
result.set(cluster.id, sections);
}
return result;
}
+122
View File
@@ -146,6 +146,128 @@ for (const feature of complexApproachFeatures) {
);
assert.ok(area > 0, 'compiled complex approach surface must have positive area');
}
// Published transition lanes share the fixed source seam, including when the
// inner width is edited. Their outer endpoints must remain inside that seam.
const previewLanes = complexGeometry.laneCenterlines.features.filter((feature) => feature.properties.cluster_preview);
assert.ok(previewLanes.length > 0);
for (const lane of previewLanes) {
const approach = complexApproachFeatures.find(
(feature) => feature.properties.carriageway_key === lane.properties.carriageway_key,
);
assert.ok(approach, 'a transition lane must have a supported approach surface');
const ring = approach.geometry.coordinates[0];
const ratio = (lane.properties.lane_index - 0.5) / approach.properties.lane_count;
const expected = ring[0].map((value, axis) => value + (ring[3][axis] - value) * ratio);
assert.ok(
Math.hypot(...expected.map((value, axis) => value - lane.geometry.coordinates[0][axis])) < 1e-9,
'transition lane starts on its actual outer seam',
);
}
const boundaryEditOptions = {
junctionTemplates: {
enabled: true,
clusters: [
{
id: 'fixture-five-arm',
template: 'complex-junction-v1',
nodeIds: ['8005332807', '8024512135', '8024512145', '8024512147', '8613058676'],
coreRadiusMeters: 24,
},
],
},
directEdit: {
clusterPlans: new Map([
[
'fixture-five-arm',
new Map([[compiledApproach.properties.carriageway_key, compiledApproach.properties.width_m * 1.2]]),
],
]),
},
};
const widenedGeometry = compiler.nativeRoad.compileGeometry(complexModel, { overrides: [] }, boundaryEditOptions);
const exteriorBaseline = compiler.nativeRoad.compileGeometry(
complexModel,
{ overrides: [] },
{ junctionTemplates: boundaryEditOptions.junctionTemplates },
);
// External pavement and all linear consumers retain the same geometry when
// only the internal width changes; measure the pavement seam in metres too.
for (const layerName of ['roadSurface', 'edgeLines', 'sidewalkSurface', 'centerLines', 'laneCenterlines']) {
const external = (geometry) =>
geometry[layerName].features.filter((feature) =>
layerName === 'roadSurface'
? Boolean(feature.properties.directional_road_ids)
: layerName === 'sidewalkSurface'
? feature.properties.provenance === 'native-road-sidewalk/v1'
: !feature.properties.cluster_preview,
);
assert.deepEqual(
external(widenedGeometry),
external(exteriorBaseline),
`${layerName} must keep the fixed exterior geometry during local widening`,
);
}
let checkedExteriorSeams = 0;
for (const approach of complexApproachFeatures) {
const lane = previewLanes.find(
(candidate) => candidate.properties.carriageway_key === approach.properties.carriageway_key,
);
const surface = complexGeometry.roadSurface.features.find((candidate) =>
String(candidate.properties.directional_road_ids || '')
.split(',')
.includes(lane?.properties.road_id),
);
if (!surface) continue;
const ring = approach.geometry.coordinates[0];
for (const endpoint of [ring[0], ring[3]]) {
const error = Math.min(
...surface.geometry.coordinates[0].map((coordinate) =>
Math.hypot(
(coordinate[0] - endpoint[0]) * 111320 * Math.cos((endpoint[1] * Math.PI) / 180),
(coordinate[1] - endpoint[1]) * 111320,
),
),
);
assert.ok(error <= 0.01, `external pavement seam error ${error} exceeds one centimetre`);
}
checkedExteriorSeams++;
}
assert.ok(checkedExteriorSeams > 0);
const widenedLanes = widenedGeometry.laneCenterlines.features.filter(
(feature) =>
feature.properties.cluster_preview &&
feature.properties.carriageway_key === compiledApproach.properties.carriageway_key,
);
assert.ok(widenedLanes.length > 0);
for (const lane of widenedLanes) {
const before = previewLanes.find((candidate) => candidate.properties.native_id === lane.properties.native_id);
assert.deepEqual(
lane.geometry.coordinates[0],
before.geometry.coordinates[0],
'local widening preserves the outer lane seam',
);
}
const rejectedGeometry = compiler.nativeRoad.compileGeometry(
complexModel,
{ overrides: [] },
{
...boundaryEditOptions,
directEdit: {
clusterTransitions: new Map([
['fixture-five-arm', new Map([[compiledApproach.properties.carriageway_key, 10000]])],
]),
},
},
);
assert.equal(
rejectedGeometry.laneCenterlines.features.some(
(feature) =>
feature.properties.cluster_preview &&
feature.properties.carriageway_key === compiledApproach.properties.carriageway_key,
),
false,
'an unsupported transition must not publish floating lanes',
);
const complexFeatures = Object.values(complexGeometry).flatMap((layer) => layer?.features || []);
assert.equal(
complexFeatures.some((feature) => feature.properties?.kind === 'complex-corner-island'),