diff --git a/.trellis/spec/backend/direct-edit-api.md b/.trellis/spec/backend/direct-edit-api.md index 61f5338..b065b0c 100644 --- a/.trellis/spec/backend/direct-edit-api.md +++ b/.trellis/spec/backend/direct-edit-api.md @@ -379,3 +379,20 @@ projectJunctionStructure({ model, layers }); projectJunctionStructure({ model, layers, trafficSignals, junctionRef: { type: 'cluster', id: selectedClusterId } }); ``` + +## Complex carriageway transition length + +`cluster-carriageway-transition-length` uses the source-checked +`cluster-carriageway` anchor and `value.transitionLengthMeters`. Replay verifies +source road/node membership before solving. The resolved `clusterTransitions` +map is separate from `clusterCutbacks`: the outer source seam is fixed, and the +inner station is `outerStation - transitionLengthMeters` along the source +polyline. Radial distance differences are not lengths on curved approaches. +The maximum is the available outer station; the minimum is the smaller of the +configured minimum and the existing source-derived transition (short existing +approaches remain representable). Impossible surface geometry still requires +compiler validation. A saved transition is never silently clamped. + +Regression evidence: solver rejects out-of-range/source-mismatched values; +API preview measures the requested length and preserves the outer seam; +save/read/replay reproduces preview geometry; browser input sends the new kind. diff --git a/.trellis/spec/frontend/direct-edit-client.md b/.trellis/spec/frontend/direct-edit-client.md index bfabae9..63b374c 100644 --- a/.trellis/spec/frontend/direct-edit-client.md +++ b/.trellis/spec/frontend/direct-edit-client.md @@ -318,3 +318,17 @@ Map capability reason codes into user-facing Chinese descriptions. Required checks: opposite node/cluster scopes with equal raw IDs, unknown scope, list-to-feature grouping and feature-to-list identity, foreign-cluster exclusion, raw signal UID selection, map identity preservation, and reload stability. + +### Junction workspace save and grouped ranges + +Workspace actions must include `EditSession.dirty`, `canUndo`, and `canRedo`; +`JunctionSession.dirty` alone misses settled grouped edits. Reuse the global +commands and expose save status in the junction route, where the main header is +hidden. The edit render revision is not a persisted document version: a save +changes it, so comparing a captured render revision after saving can crash React. +The API owns version conflict checks. + +A grouped scalar is available only if the individual ranges intersect. Otherwise +show why a common value is unavailable and expand individual controls; never +render a minimum larger than the maximum. Transition length uses the same input, +preview, history, and persistence path as other geometry parameters. diff --git a/.trellis/tasks/09-08-junction-reference-fidelity/implement.md b/.trellis/tasks/09-08-junction-reference-fidelity/implement.md index 73eb7e0..50cbd6a 100644 --- a/.trellis/tasks/09-08-junction-reference-fidelity/implement.md +++ b/.trellis/tasks/09-08-junction-reference-fidelity/implement.md @@ -25,7 +25,7 @@ - [ ] 支持凹形与已知排除区域,检查环、自交、接缝、必要连接;设计边界可行域并由 solver/manifest 共用。 - [ ] 审计 roadSurface、sidewalkSurface、edgeLines、lane/center markings 的每个裁切入口,确保消费同一计划。 - [ ] 出口 A3:接缝≤1 cm,必要区域连通,无自交与排除区侵占;自动测试验证实际几何,不只是参数回显。 - - 已验证:3~6 臂核心环闭合、正面积、无自交、共享内边连续并报告 maxSharedSeamErrorMeters≤1cm;入口 ring 闭合/有限/正面积;短过渡、零长度边、零宽度和排除区相切均有失败回归。 + - 已验证:3~6 臂核心环闭合、正面积、无自交、共享内边邻接;当前 maxSharedSeamErrorMeters 仅以邻接成立返回 0、不成立返回 Infinity,不等同于全图层实际接缝测量;入口 ring 闭合/有限/正面积;短过渡、零长度边、零宽度和排除区相切均有失败回归。 - 待完成:凹形/多区域/孔洞、全图层连通性和统一接缝误差测量。 - [ ] 此阶段不通过,不开启新几何控件。 @@ -50,7 +50,7 @@ 已完成并验证的通用底座:共享来源拓扑、3~6 臂结构矩阵、重排/平移/旋转稳定性、核心与入口边界不变量、排除区域保护、入口过渡状态诊断、设施来源证据、预览/保存/刷新基础回归及端到端工作台流程。 -明确遗留:接入位置/方向/左右边界/过渡长度的完整编辑闭环,凹形与多区域连通性,全图层接缝测量,真实 OSM 视觉验收。导流岛自由编辑和独立右转通道继续留在后续任务。 +明确遗留:接入位置/方向/左右边界的完整编辑闭环(过渡长度本次补齐),凹形与多区域连通性,全图层接缝测量,真实 OSM 视觉验收。导流岛自由编辑和独立右转通道继续留在后续任务。 ## 5. 通用性验收与发布 @@ -72,3 +72,11 @@ complex-junction.js / native-road.js:构建与全部消费者;direct-edit-solver.js / native-road-edits.js:纯求解与兼容;junction-structure.js / junction-topology.js / junction-projection.js:身份及投影;server.js:预览保存一致性;App.tsx / ParameterPanel.tsx / MapCanvas.tsx / edit/*:输入和状态。 每个阶段独立可回滚。几何更换前保存原始文档和输出比较,禁止先更新 fixture baseline 掩盖差异。任何大幅缩减支持范围或迁移语义变更先更新规划供用户审阅。 + +## 过渡长度编辑交付记录 + +已接通过渡长度的文档回放、独立 solver 结果、沿来源折线的内部断面定位、客户端输入映射与手柄。外部接缝保持固定,独立于收口距离。API 验证实际长度、保存再读取重放;浏览器验证参数输入请求被应用。曲线进口有沿线长度回归。此交付不代表接入位置/方向/左右边界、全图层几何及真实数据视觉验收完成。 + +本次进一步修复路口面板保存按钮漏读 EditSession.dirty、缺少撤销重做入口、保存回调误用渲染计数导致白屏,以及长短进口没有共同范围时仍显示统一输入的问题。浏览器回归覆盖单独过渡长度输入、撤销、重做、保存重编译与刷新;后端覆盖拒绝的收口约束不影响有效过渡范围。保持父任务进行中,不将本次编辑闭环等同于全部几何验收完成。 + +本轮质量门: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 大小提示。遵循用户“整体任务完成再提交”,本轮未提交、未归档父任务。 diff --git a/src/compile/direct-edit-solver.js b/src/compile/direct-edit-solver.js index 16303d9..95ca01d 100644 --- a/src/compile/direct-edit-solver.js +++ b/src/compile/direct-edit-solver.js @@ -344,6 +344,30 @@ function numericValue(constraint, key, fallback) { return Number.isFinite(value) ? value : fallback; } +function transitionBounds(model, cluster, item, constraints) { + const metrics = complexJunctionMetrics(cluster); + const cutback = constraintFor(constraints, 'cluster-carriageway-cutback', { + clusterId: String(cluster.id), + carriagewayKey: item.key, + }); + const cutbackValue = numericValue(cutback, 'cutbackMeters', item.approach.cutback); + const effectiveCutback = + cutback && + ACTIVE_STATUSES.has(cutback.status) && + cutbackValue >= 1 && + cutbackValue <= clusterCutbackMaximum(cluster, item.approach.length) + ? cutbackValue + : item.approach.cutback; + const radius = Math.max(metrics.coreRadius + 4, metrics.approachOuterRadius - effectiveCutback); + const center = clusterCenter(model, cluster) || item.approach.line[0]; + const outer = stationAtDistanceFrom(item.approach.line, center, radius, { distanceMeters: haversineMeters }); + const inner = stationAtDistanceFrom(item.approach.line, center, metrics.approachInnerRadius, { + distanceMeters: haversineMeters, + }); + const current = Math.max(0, outer - inner); + return { min: Math.min(metrics.minimumTransitionMeters, current), max: outer, current, outer }; +} + function clusterCutbackMaximum(cluster, approachLength) { const metrics = complexJunctionMetrics(cluster); // Keep a measurable local taper between the source-road outer section and @@ -452,7 +476,10 @@ function reconcileConstraints(model, constraints, base, junctionData, context) { if (versionChanged) return { ...constraint, status: 'recheck' }; return constraint; } - if (constraint.kind === 'cluster-carriageway-width') { + if ( + constraint.kind === 'cluster-carriageway-width' || + constraint.kind === 'cluster-carriageway-transition-length' + ) { const item = clusterItems .get(String(constraint.anchor.clusterId)) ?.find((candidate) => candidate.key === constraint.anchor.carriagewayKey); @@ -839,6 +866,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster const crossingControls = new Map(); const clusterPlans = new Map(); const clusterCutbacks = new Map(); + const clusterTransitions = new Map(); const clusterCorners = new Map(); const clusterCrossings = new Map(); const clusterItems = clusterCarriageways(model, junctionData, clusters); @@ -873,6 +901,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster const crossingSnapshot = new Map([...crossingControls].map(([key, value]) => [key, { ...value }])); const clusterSnapshot = new Map([...clusterPlans].map(([key, value]) => [key, new Map(value)])); const cutbackSnapshot = new Map([...clusterCutbacks].map(([key, value]) => [key, new Map(value)])); + const transitionSnapshot = new Map([...clusterTransitions].map(([key, value]) => [key, new Map(value)])); const cornerSnapshot = new Map([...clusterCorners].map(([key, value]) => [key, new Map(value)])); const crossingClusterSnapshot = new Map([...clusterCrossings].map(([key, value]) => [key, new Map(value)])); const junctionSnapshot = new Map( @@ -903,8 +932,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster ); const cluster = clusters.find((candidate) => String(candidate.id) === String(item?.clusterId)); const cutbackMax = cluster ? clusterCutbackMaximum(cluster, item?.approach.length || 0) : 0; - const metrics = cluster ? complexJunctionMetrics(cluster) : null; - const transitionMax = metrics ? metrics.approachOuterRadius - metrics.approachInnerRadius : 0; + const transitionMax = item && cluster ? transitionBounds(model, cluster, item, constraints).max : 0; if (!item) { blocking(diagnostics, constraint, 'direct-edit-cluster-carriageway-missing', '复杂路口车行道锚点不存在。'); applied = false; @@ -915,7 +943,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster value > item.widthMeters * 2)) || (constraint.kind === 'cluster-carriageway-cutback' && (value < 1 || value > cutbackMax)) || (constraint.kind === 'cluster-carriageway-transition-length' && - (value < (metrics?.minimumTransitionMeters || 0) || value > transitionMax)) + (value < transitionBounds(model, cluster, item, constraints).min || value > transitionMax)) ) { blocking( diagnostics, @@ -925,11 +953,14 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster ); applied = false; } else { - const target = constraint.kind === 'cluster-carriageway-width' ? clusterPlans : clusterCutbacks; + const target = + constraint.kind === 'cluster-carriageway-width' + ? clusterPlans + : constraint.kind === 'cluster-carriageway-transition-length' + ? clusterTransitions + : clusterCutbacks; if (!target.has(item.clusterId)) target.set(item.clusterId, new Map()); - const derivedCutback = - constraint.kind === 'cluster-carriageway-transition-length' ? Math.max(0, transitionMax - value) : value; - target.get(item.clusterId).set(item.key, derivedCutback); + target.get(item.clusterId).set(item.key, value); applied = true; } } else if (constraint.kind === 'cluster-corner-radius') { @@ -1007,6 +1038,8 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster for (const [key, value] of clusterSnapshot) clusterPlans.set(key, value); clusterCutbacks.clear(); for (const [key, value] of cutbackSnapshot) clusterCutbacks.set(key, value); + clusterTransitions.clear(); + for (const [key, value] of transitionSnapshot) clusterTransitions.set(key, value); clusterCorners.clear(); for (const [key, value] of cornerSnapshot) clusterCorners.set(key, value); clusterCrossings.clear(); @@ -1021,6 +1054,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics, cluster crossingControls, clusterPlans, clusterCutbacks, + clusterTransitions, clusterCorners, clusterCrossings, states, @@ -1460,35 +1494,27 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster clusterId, carriagewayKey: item.key, }); - handles.push({ - handleId: `handle:cluster-carriageway-transition-length:${item.key}`, - kind: 'cluster-carriageway-transition-length', - anchor: { - type: 'cluster-carriageway', - clusterId, - carriagewayKey: item.key, - sourceNodeIds: item.sourceNodeIds, - sourceRoadIds: item.sourceRoadIds, - }, - position: point, - axisAzimuth: tangentAzimuth(line, station), - value: { - current: numericValue( - transitionConstraint, - 'transitionLengthMeters', - Math.max(0, item.approach.length - item.approach.cutback), - ), - min: complexJunctionMetrics(cluster).minimumTransitionMeters, - max: Math.max( - complexJunctionMetrics(cluster).minimumTransitionMeters, - complexJunctionMetrics(cluster).approachOuterRadius - complexJunctionMetrics(cluster).approachInnerRadius, - ), - unit: 'meter', - }, - ...(transitionConstraint ? { constraintId: transitionConstraint.id } : {}), - affects: [`complex-junction:${clusterId}:carriageway:${item.approach.segmentId}`], - editable: true, - }); + const bounds = transitionBounds(model, cluster, item, constraints); + const transitionValue = numericValue(transitionConstraint, 'transitionLengthMeters', bounds.current); + const transitionStation = Math.max(0, bounds.outer - transitionValue) / Math.max(item.length, 1); + if (bounds.max > 0 && bounds.max >= bounds.min) + handles.push({ + handleId: `handle:cluster-carriageway-transition-length:${item.key}`, + kind: 'cluster-carriageway-transition-length', + anchor: { + type: 'cluster-carriageway', + clusterId, + carriagewayKey: item.key, + sourceNodeIds: item.sourceNodeIds, + sourceRoadIds: item.sourceRoadIds, + }, + position: coordinateAt(line, transitionStation), + axisAzimuth: (tangentAzimuth(line, transitionStation) + 180) % 360, + value: { current: transitionValue, min: bounds.min, max: bounds.max, unit: 'meter' }, + ...(transitionConstraint ? { constraintId: transitionConstraint.id } : {}), + affects: [`complex-junction:${clusterId}:carriageway:${item.approach.segmentId}`], + editable: true, + }); const cutbackConstraint = constraintFor(constraints, 'cluster-carriageway-cutback', { clusterId, carriagewayKey: item.key, @@ -1696,6 +1722,7 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {}) crossingControls: solved.crossingControls, clusterPlans: solved.clusterPlans, clusterCutbacks: solved.clusterCutbacks, + clusterTransitions: solved.clusterTransitions, clusterCorners: solved.clusterCorners, clusterCrossings: solved.clusterCrossings, laneManeuvers: solved.laneManeuvers, diff --git a/src/compile/junction-boundary-graph.js b/src/compile/junction-boundary-graph.js index c2bd27e..31e42c4 100644 --- a/src/compile/junction-boundary-graph.js +++ b/src/compile/junction-boundary-graph.js @@ -39,8 +39,9 @@ function offsetCoordinate(point, heading, meters) { ]; } -function sectionAt(item, radius, center, widthMeters, helpers) { - const station = Math.min(item.length, stationAtDistanceFrom(item.approach.line, center, radius, helpers)); +function sectionAt(item, radius, center, widthMeters, helpers, explicitStation) { + const station = + explicitStation ?? Math.min(item.length, stationAtDistanceFrom(item.approach.line, center, radius, helpers)); const point = pointAtStation(item.approach.line, station, helpers); const tangent = tangentAtStation(item.approach.line, station, helpers); const halfWidth = Math.max(0, Number(widthMeters) || 0) / 2; @@ -63,7 +64,16 @@ function buildJunctionBoundaryGraph(topology, center, radii, helpers, exclusionR const outerWidthMeters = Number(item.approach.sourceWidthMeters) || item.approach.widthMeters; const innerWidthMeters = item.approach.widthMeters; const outer = sectionAt(item, outerRadius, center, outerWidthMeters, helpers); - const inner = sectionAt(item, innerRadius, center, innerWidthMeters, helpers); + const inner = sectionAt( + item, + innerRadius, + center, + innerWidthMeters, + helpers, + Number.isFinite(item.approach.transitionLengthMeters) + ? outer.stationMeters - item.approach.transitionLengthMeters + : undefined, + ); const key = `boundary:${item.key}`; const sectionRing = [outer.right, inner.right, inner.left, outer.left, outer.right]; const exclusion = exclusionRegions.find((region) => ringsOverlap(region.ring, sectionRing)); diff --git a/src/compile/native-road.js b/src/compile/native-road.js index 0df256f..291f129 100644 --- a/src/compile/native-road.js +++ b/src/compile/native-road.js @@ -970,10 +970,12 @@ function applyDirectJunctionPlans(plans, directEdit) { } function applyDirectClusterPlans(model, junctionPlans, directEdit, clusters) { - if (!directEdit?.clusterPlans?.size && !directEdit?.clusterCutbacks?.size) return; + if (!directEdit?.clusterPlans?.size && !directEdit?.clusterCutbacks?.size && !directEdit?.clusterTransitions?.size) + return; const clusterIds = new Set([ ...(directEdit.clusterPlans || new Map()).keys(), ...(directEdit.clusterCutbacks || new Map()).keys(), + ...(directEdit.clusterTransitions || new Map()).keys(), ]); for (const clusterId of clusterIds) { const widths = directEdit.clusterPlans?.get(clusterId) || new Map(); @@ -997,6 +999,8 @@ function applyDirectClusterPlans(model, junctionPlans, directEdit, clusters) { } const cutback = cutbacks.get(item.key); if (Number.isFinite(cutback)) item.approach.cutback = cutback; + const transition = directEdit.clusterTransitions?.get(clusterId)?.get(item.key); + if (Number.isFinite(transition)) item.approach.transitionLengthMeters = transition; } } } diff --git a/test/direct-edit-solver.js b/test/direct-edit-solver.js index df07796..8e37f5b 100644 --- a/test/direct-edit-solver.js +++ b/test/direct-edit-solver.js @@ -775,3 +775,61 @@ assert.equal( ); console.log('direct edit solver tests passed'); + +const transitionHandle = clusterHandleResolution.handles.handles.find( + (handle) => handle.kind === 'cluster-carriageway-transition-length', +); +assert.ok(transitionHandle); +assert.ok( + transitionHandle.value.current >= transitionHandle.value.min && + transitionHandle.value.current <= transitionHandle.value.max, +); +const transitionConstraint = constraint({ + id: 'transition-complete', + kind: 'cluster-carriageway-transition-length', + anchor: transitionHandle.anchor, + value: { transitionLengthMeters: (transitionHandle.value.min + transitionHandle.value.max) / 2 }, +}); +const resolveTransition = (value) => + resolveDirectEditConstraints(junctionModel, document([value]), { + junctionClusters: [{ id: 'cluster-1', nodeIds: ['junction'] }], + }); +const appliedTransition = resolveTransition(transitionConstraint); +assert.equal(appliedTransition.constraintStates[0].applied, true); +assert.equal( + appliedTransition.clusterTransitions.get('cluster-1').get(transitionHandle.anchor.carriagewayKey), + transitionConstraint.value.transitionLengthMeters, +); +assert.equal( + appliedTransition.clusterCutbacks.size, + 0, + 'transition length must not move the outer seam through cutback', +); +assert.equal( + resolveTransition({ ...transitionConstraint, value: { transitionLengthMeters: transitionHandle.value.max + 1 } }) + .constraintStates[0].applied, + false, +); +assert.equal( + resolveTransition({ ...transitionConstraint, anchor: { ...transitionConstraint.anchor, sourceRoadIds: ['missing'] } }) + .constraintStates[0].applied, + false, +); +assert.equal(resolveTransition({ ...transitionConstraint, enabled: false }).clusterTransitions.size, 0); + +const rejectedCutback = constraint({ + id: 'transition-invalid-cutback', + kind: 'cluster-carriageway-cutback', + anchor: transitionHandle.anchor, + value: { cutbackMeters: 999 }, +}); +const mixedTransition = resolveDirectEditConstraints(junctionModel, document([rejectedCutback, transitionConstraint]), { + junctionClusters: [{ id: 'cluster-1', nodeIds: ['junction'] }], +}); +assert.equal(mixedTransition.constraintStates[0].applied, false); +assert.equal(mixedTransition.constraintStates[1].applied, true); +assert.equal( + mixedTransition.handles.handles.find((handle) => handle.handleId === transitionHandle.handleId).value.max, + transitionHandle.value.max, + 'a rejected cutback must not move transition bounds away from the effective outer seam', +); diff --git a/test/e2e/workbench.spec.ts b/test/e2e/workbench.spec.ts index bffad7a..5e0b009 100644 --- a/test/e2e/workbench.spec.ts +++ b/test/e2e/workbench.spec.ts @@ -199,6 +199,7 @@ test.describe('workbench editing shell', () => { }); test('keeps complex junction structure and map selection linked across reload', async ({ page }) => { + test.setTimeout(60_000); const initial = await page.request.get('/api/state').then((response) => response.json()); const candidate = initial.debug.junctionCandidates.find((item: { nodeIds: string[] }) => item.nodeIds.length >= 3); expect(candidate).toBeTruthy(); @@ -251,6 +252,7 @@ test.describe('workbench editing shell', () => { [ 'cluster-carriageway-width', 'cluster-carriageway-cutback', + 'cluster-carriageway-transition-length', 'cluster-corner-radius', 'cluster-crossing-inset', 'cluster-stop-line-offset', @@ -297,6 +299,58 @@ test.describe('workbench editing shell', () => { await page.reload(); await expect(armButtons).toHaveCount(structure.arms.length); await expect(armButtons.first()).toHaveAttribute('aria-pressed', 'false'); + const transitionGroup = workspace.locator('.parameter-group').filter({ hasText: '车行道过渡长度' }); + await expect(transitionGroup).toBeVisible(); + const expandTransition = transitionGroup.getByRole('button', { name: '展开单独定制' }); + if (await expandTransition.count()) await expandTransition.click(); + const transitionHandle = scoped.handles.handles.find( + (handle: { kind: string; value: { min: number; max: number } }) => + handle.kind === 'cluster-carriageway-transition-length' && handle.value.max - handle.value.min > 1, + ); + expect(transitionHandle).toBeTruthy(); + const transitionInput = transitionGroup.locator(`[data-handle-id="${transitionHandle.handleId}"] .parameter-input`); + const originalTransitionValue = await transitionInput.inputValue(); + const transitionValue = Math.round(((transitionHandle.value.min + transitionHandle.value.max) / 2) * 100) / 100; + + const transitionResponse = page.waitForResponse( + (response) => + response.request().method() === 'POST' && + response.url().endsWith('/api/edit-preview') && + response + .request() + .postDataJSON() + ?.constraints?.some( + (constraint: { kind: string }) => constraint.kind === 'cluster-carriageway-transition-length', + ), + ); + await transitionInput.fill(String(transitionValue)); + await transitionInput.press('Enter'); + const transitionResult = await (await transitionResponse).json(); + expect(transitionResult.constraintStates.length).toBeGreaterThan(0); + expect(transitionResult.constraintStates.every((state: { applied: boolean }) => state.applied)).toBe(true); + await expect(transitionInput).toHaveValue(String(transitionValue)); + await page.getByRole('button', { name: '撤销', exact: true }).click(); + await expect(transitionInput).toHaveValue(originalTransitionValue); + await expect(page.getByRole('button', { name: '重做', exact: true })).toBeEnabled(); + await page.getByRole('button', { name: '重做', exact: true }).click(); + await expect(transitionInput).toHaveValue(String(transitionValue)); + await page + .getByRole('region', { name: '路口编辑工作区' }) + .getByRole('button', { name: '保存', exact: true }) + .click(); + await expect(page.getByRole('status')).toHaveText('已保存并重新生成', { timeout: 30_000 }); + await page.reload(); + await expect(transitionGroup).toBeVisible(); + if (await expandTransition.count()) await expandTransition.click(); + await expect(transitionInput).toHaveValue(String(transitionValue)); + + const transitionRow = transitionGroup.locator(`[data-handle-id="${transitionHandle.handleId}"]`); + await transitionRow.getByRole('button', { name: '重置', exact: true }).click(); + await expect(transitionInput).toHaveValue(originalTransitionValue); + await workspace.getByRole('button', { name: '放弃草稿', exact: true }).click(); + await expect(transitionInput).toHaveValue(String(transitionValue)); + await expect(workspace.getByRole('button', { name: '保存', exact: true })).toBeDisabled(); + const refreshed = await page.request.get('/api/state').then((response) => response.json()); expect(refreshed.junctionStructures[`cluster:${id}`].arms.map((arm: { key: string }) => arm.key)).toEqual( structure.arms.map((arm: { key: string }) => arm.key), diff --git a/test/junction-build-plan-counterexamples.js b/test/junction-build-plan-counterexamples.js index 825ce0b..c025482 100644 --- a/test/junction-build-plan-counterexamples.js +++ b/test/junction-build-plan-counterexamples.js @@ -586,3 +586,26 @@ assert.equal(transitionLengthForCutback(transitionMetrics, 5), 19); assert.equal(transitionLengthForCutback(transitionMetrics, 100), 0); assert.equal(transitionLengthForCutback(transitionMetrics, 0, 6), 6); assert.equal(transitionLengthForCutback(transitionMetrics, 0, 0), 0); + +const curvedTransition = topology('curved-transition', [ + { widthMeters: 4, line: [point(0, 0), point(0, 15), point(15, 30), point(15, 50)] }, + { widthMeters: 4, line: [point(0, 0), point(50, 0)] }, + { widthMeters: 4, line: [point(0, 0), point(-50, 0)] }, +]); +const curvedRadii = { outerRadiusFor: () => 35, innerRadiusFor: () => 10 }; +const originalCurvedGraph = buildJunctionBoundaryGraph( + curvedTransition.topology, + point(0, 0), + curvedRadii, + curvedTransition.helpers, +); +curvedTransition.topology.carriageways[0].approach.transitionLengthMeters = 16; +const editedCurvedGraph = buildJunctionBoundaryGraph( + curvedTransition.topology, + point(0, 0), + curvedRadii, + curvedTransition.helpers, +); +assert.deepEqual(editedCurvedGraph.sections[0].outer, originalCurvedGraph.sections[0].outer); +assert.ok(Math.abs(editedCurvedGraph.sections[0].transitionMeters - 16) < 1e-9); +assert.notDeepEqual(editedCurvedGraph.sections[0].inner, originalCurvedGraph.sections[0].inner); diff --git a/test/workbench-edit-api.js b/test/workbench-edit-api.js index 15c9faf..2a72d86 100644 --- a/test/workbench-edit-api.js +++ b/test/workbench-edit-api.js @@ -261,6 +261,7 @@ assert.ok( [ 'cluster-carriageway-width', 'cluster-carriageway-cutback', + 'cluster-carriageway-transition-length', 'cluster-corner-radius', 'cluster-crossing-inset', 'cluster-stop-line-offset', @@ -365,6 +366,48 @@ assert.notDeepEqual( stopLineForCarriageway(clusterPreview).geometry, 'a local width correction must update its final stop-line geometry', ); +const transitionHandle = clusterState.handles.handles.find( + (handle) => + handle.kind === 'cluster-carriageway-transition-length' && + handle.anchor.carriagewayKey === complexWidthHandle.anchor.carriagewayKey, +); +assert.ok(transitionHandle); +const transitionConstraint = { + ...complexWidthConstraint, + kind: 'cluster-carriageway-transition-length', + value: { transitionLengthMeters: transitionHandle.value.max - 1 }, +}; +const transitionPreview = editPreview(complexArea, { + document: { + ...emptyDocument, + constraints: [transitionConstraint], + operations: [ + { + id: 'operation:complex-width', + createdAt: '2026-09-08T00:00:00.000Z', + constraintIds: [transitionConstraint.id], + }, + ], + }, + selection: { cluster: cluster.id }, +}); +assert.equal(transitionPreview.constraintStates[0].applied, true); +const transitionedRing = complexSurface(transitionPreview).geometry.coordinates[0]; +assert.deepEqual( + [transitionedRing[0], transitionedRing[3]], + [baselineApproachRing[0], baselineApproachRing[3]], + 'transition edit must preserve the outer seam', +); +assert.ok( + Math.abs( + complexSurface(transitionPreview).properties.transition_length_m - + transitionConstraint.value.transitionLengthMeters, + ) <= 0.1, + 'compiled transition length must match the requested meters', +); + +assert.notDeepEqual(complexSurface(transitionPreview).geometry, complexSurface(clusterPreview).geometry); + const complexCrossingHandle = clusterState.handles.handles.find((handle) => handle.kind === 'cluster-crossing-inset'); assert.ok(complexCrossingHandle, 'the complex fixture must publish grouped crossing handles'); const renderedComplexCrosswalk = clusterPreview.layers.crosswalks.features.find( @@ -519,5 +562,21 @@ for (const tracked of complexTracked) { assert.equal(fs.statSync(tracked.file).mtimeMs, tracked.mtimeMs); } +const transitionSaved = saveEdits(complexArea, { + expectedDocumentVersion: emptyDocument.documentVersion, + constraints: [transitionConstraint], + operations: [ + { id: 'operation:complex-width', createdAt: '2026-09-08T00:00:00.000Z', constraintIds: [transitionConstraint.id] }, + ], +}); +assert.ok(transitionSaved.documentVersion > emptyDocument.documentVersion); +const transitionReloaded = editState(complexArea, selectionFrom({ cluster: cluster.id })); +const replayedTransition = editPreview(complexArea, { + document: transitionReloaded.document, + selection: { cluster: cluster.id }, +}); +assert.equal(replayedTransition.constraintStates[0].applied, true); +assert.deepEqual(complexSurface(replayedTransition).geometry, complexSurface(transitionPreview).geometry); + fs.rmSync(workspace, { recursive: true, force: true }); console.log('workbench edit API tests passed'); diff --git a/workbench/client/src/App.tsx b/workbench/client/src/App.tsx index c6e0c57..fd5a0ce 100644 --- a/workbench/client/src/App.tsx +++ b/workbench/client/src/App.tsx @@ -269,6 +269,7 @@ function App() { (handle) => (handle.kind === 'cluster-carriageway-width' || handle.kind === 'cluster-carriageway-cutback' || + handle.kind === 'cluster-carriageway-transition-length' || handle.kind === 'cluster-corner-radius' || handle.kind === 'cluster-crossing-inset' || handle.kind === 'cluster-stop-line-offset') && @@ -1272,7 +1273,12 @@ function App() { void compile().then((ok) => { - if (ok) setJunctionSession((current) => (current ? saveJunctionSession(current, editRevision) : current)); + // The API checks documentVersion. editRevision is only a render counter + // and advances during this save, so it cannot validate its completion. + if (ok) + setJunctionSession((current) => + current?.ref.type === junctionDescriptor.ref.type && current.ref.id === junctionDescriptor.ref.id + ? saveJunctionSession(current) + : current, + ); }) } editMode={editMode} diff --git a/workbench/client/src/components/ParameterPanel.tsx b/workbench/client/src/components/ParameterPanel.tsx index d3ef748..c4f3486 100644 --- a/workbench/client/src/components/ParameterPanel.tsx +++ b/workbench/client/src/components/ParameterPanel.tsx @@ -382,7 +382,8 @@ function GroupedParameterList({ max: Math.min(...items.map((item) => item.value.max)), }, }; - const expandedGroup = Boolean(expanded[kind]); + const hasSharedRange = globalHandle.value.min <= globalHandle.value.max; + const expandedGroup = !hasSharedRange || Boolean(expanded[kind]); const globalDraft = callbacks.onDraftGroup ?? ((group: EditHandle[], value: number) => callbacks.onDraft?.(group[0], value)); const globalSettle = @@ -392,25 +393,32 @@ function GroupedParameterList({
{groupLabel(kind, representative)} - 统一设置 · {items.length} 项 + + {hasSharedRange ? '统一设置' : '单独设置'} · {items.length} 项 +
- globalDraft(items, value)} - onSettle={(handle, value) => globalSettle(items, value)} - labelForHandle={() => '统一值'} - /> + {hasSharedRange ? ( + globalDraft(items, value)} + onSettle={(handle, value) => globalSettle(items, value)} + labelForHandle={() => '统一值'} + /> + ) : ( +

各项允许范围没有交集,请分别调整。

+ )} {expandedGroup ? (
    {items.map((handle) => ( diff --git a/workbench/client/src/edit/parameter.ts b/workbench/client/src/edit/parameter.ts index bf92b34..2a75c5b 100644 --- a/workbench/client/src/edit/parameter.ts +++ b/workbench/client/src/edit/parameter.ts @@ -115,6 +115,7 @@ const KIND_LABELS: Record = { 'junction-approach-width': '进口宽度', 'cluster-carriageway-width': '车行道宽度', 'cluster-carriageway-cutback': '车行道收口距离', + 'cluster-carriageway-transition-length': '车行道过渡长度', 'cluster-corner-radius': '角部圆角', 'cluster-crossing-inset': '斑马线退让', 'cluster-stop-line-offset': '停止线偏移', diff --git a/workbench/client/src/edit/projection.test.ts b/workbench/client/src/edit/projection.test.ts index a0cfe89..f7961b2 100644 --- a/workbench/client/src/edit/projection.test.ts +++ b/workbench/client/src/edit/projection.test.ts @@ -328,3 +328,25 @@ describe('draft constraint', () => { expect(operationFor(constraint).author).toBe('dingkang'); }); }); + +describe('complex transition length projection', () => { + it('maps dragging to a bounded length constraint', () => { + const handle = makeHandle( + 'cluster-carriageway-transition-length', + { + type: 'cluster-carriageway', + clusterId: 'cluster-1', + carriagewayKey: 'entry-1', + sourceNodeIds: ['node-1'], + sourceRoadIds: ['road-1'], + }, + 12, + 8, + 20, + ); + const scalar = projectHandleValue(handle, ...dragBy(handle.axisAzimuth, 2)); + expect(scalar).toBeCloseTo(14, 3); + expect(constraintValueFor(handle, scalar)).toEqual({ transitionLengthMeters: scalar }); + expect(projectHandleValue(handle, ...dragBy(handle.axisAzimuth, 100))).toBe(20); + }); +}); diff --git a/workbench/client/src/edit/projection.ts b/workbench/client/src/edit/projection.ts index 2240e75..668b781 100644 --- a/workbench/client/src/edit/projection.ts +++ b/workbench/client/src/edit/projection.ts @@ -106,6 +106,8 @@ export function constraintValueFor( return { widthMeters: Math.max(0, scalar) }; case 'cluster-carriageway-cutback': return { cutbackMeters: Math.max(0, scalar) }; + case 'cluster-carriageway-transition-length': + return { transitionLengthMeters: Math.max(0, scalar) }; case 'cluster-corner-radius': return { radiusMeters: Math.max(0, scalar) }; case 'junction-cutback': diff --git a/workbench/client/src/edit/types.ts b/workbench/client/src/edit/types.ts index c9e97a2..9d7ffb7 100644 --- a/workbench/client/src/edit/types.ts +++ b/workbench/client/src/edit/types.ts @@ -33,6 +33,7 @@ export const JUNCTION_KINDS = [ 'junction-approach-width', 'cluster-carriageway-width', 'cluster-carriageway-cutback', + 'cluster-carriageway-transition-length', 'cluster-corner-radius', 'junction-cutback', 'junction-corner-radius', @@ -126,6 +127,7 @@ export type ConstraintValue = | { boundaryIndex: number; offsetMeters: number; transition?: Transition } | { depthMeters: number; stripeCount: number } | { cutbackMeters: number } + | { transitionLengthMeters: number } | { radiusMeters: number } | { insetMeters: number }; export interface LaneManeuverValue { diff --git a/workbench/client/src/junction/JunctionWorkspace.tsx b/workbench/client/src/junction/JunctionWorkspace.tsx index deff923..579be9f 100644 --- a/workbench/client/src/junction/JunctionWorkspace.tsx +++ b/workbench/client/src/junction/JunctionWorkspace.tsx @@ -26,6 +26,11 @@ interface Props { onApply: () => void; onDiscard: () => void; onSave: () => void; + onUndo?: () => void; + onRedo?: () => void; + canUndo?: boolean; + canRedo?: boolean; + status?: string; editMode?: boolean; onEnableEdit?: () => void; onEnableComplex?: (nodeIds: string[]) => void; @@ -61,6 +66,11 @@ export function JunctionWorkspace({ onApply, onDiscard, onSave, + onUndo, + onRedo, + canUndo = false, + canRedo = false, + status, editMode = false, onEnableEdit, onEnableComplex, @@ -202,8 +212,8 @@ export function JunctionWorkspace({ {complexEnabled ? editable ? editMode - ? '可编辑外部车行道宽度' - : '当前按复杂路口渲染,开启编辑后可调整外部车行道宽度' + ? '可编辑车行道与路口几何参数' + : '当前按复杂路口渲染,开启编辑后可调整几何参数' : '当前按复杂路口渲染' : descriptor.status === 'candidate' ? '当前按普通路口渲染,可切换为复杂路口' @@ -519,7 +529,14 @@ export function JunctionWorkspace({ update={onUpdateSignal} /> ) : null} + {status ?

    {status}

    : null}
    + + diff --git a/workbench/client/src/junction/labels.ts b/workbench/client/src/junction/labels.ts index 6d80fa2..912fc65 100644 --- a/workbench/client/src/junction/labels.ts +++ b/workbench/client/src/junction/labels.ts @@ -60,7 +60,9 @@ export function junctionLabelForHandle(handle: EditHandle, roads: Road[], juncti } const clusterAnchor = handle.anchor; if ( - (handle.kind === 'cluster-carriageway-width' || handle.kind === 'cluster-carriageway-cutback') && + (handle.kind === 'cluster-carriageway-width' || + handle.kind === 'cluster-carriageway-cutback' || + handle.kind === 'cluster-carriageway-transition-length') && clusterAnchor.type === 'cluster-carriageway' ) { const road = roads.find((item) => clusterAnchor.sourceRoadIds.includes(item.id));