feat(junction): enable complex carriageway width editing
This commit is contained in:
1 parent
56647fcdaa
commit
c4bcbe8ff9
22 files changed
+449
-52
No files matched your search
@@ -354,10 +354,42 @@ const clusterResolution = resolveDirectEditConstraints(junctionModel, document(a
|
||||
});
|
||||
const clusterPlan = clusterResolution.effectiveJunctionPlans.get('cluster:cluster-1');
|
||||
assert.ok(clusterPlan);
|
||||
assert.equal(clusterPlan.readOnly, true);
|
||||
assert.equal(clusterPlan.readOnly, false);
|
||||
assert.deepEqual(clusterPlan.junctionRef, { type: 'cluster', id: 'cluster-1' });
|
||||
assert.equal(clusterPlan.approaches.find((item) => item.segmentId === 'segment:a').widthMeters, 7);
|
||||
|
||||
const clusterHandleResolution = resolveDirectEditConstraints(junctionModel, document([]), {
|
||||
junctionClusters: [{ id: 'cluster-1', nodeIds: ['junction'] }],
|
||||
selection: { type: 'cluster', id: 'cluster-1' },
|
||||
});
|
||||
const clusterWidthHandle = clusterHandleResolution.handles.handles.find(
|
||||
(handle) => handle.kind === 'cluster-carriageway-width',
|
||||
);
|
||||
assert.ok(clusterWidthHandle, 'a cluster selection publishes only its external carriageway widths');
|
||||
const widenedCluster = resolveDirectEditConstraints(
|
||||
junctionModel,
|
||||
document([
|
||||
constraint({
|
||||
id: 'cluster-carriageway-width',
|
||||
kind: 'cluster-carriageway-width',
|
||||
anchor: clusterWidthHandle.anchor,
|
||||
value: { widthMeters: clusterWidthHandle.value.current + 0.5 },
|
||||
}),
|
||||
]),
|
||||
{ junctionClusters: [{ id: 'cluster-1', nodeIds: ['junction'] }] },
|
||||
);
|
||||
assert.equal(widenedCluster.constraintStates[0].applied, true);
|
||||
assert.equal(
|
||||
widenedCluster.clusterPlans.get('cluster-1').get(clusterWidthHandle.anchor.carriagewayKey),
|
||||
clusterWidthHandle.value.current + 0.5,
|
||||
);
|
||||
assert.equal(
|
||||
widenedCluster.effectiveJunctionPlans
|
||||
.get('cluster:cluster-1')
|
||||
.carriageways.find((item) => item.key === clusterWidthHandle.anchor.carriagewayKey).widthMeters,
|
||||
clusterWidthHandle.value.current + 0.5,
|
||||
);
|
||||
|
||||
const recheckResolution = resolveDirectEditConstraints(
|
||||
junctionModel,
|
||||
{ ...document([anchored]), base: { compilerGeometryVersion: 'old-geometry' } },
|
||||
|
||||
@@ -244,8 +244,16 @@ test.describe('workbench editing shell', () => {
|
||||
const scoped = await page.request
|
||||
.get(`/api/edit-state?cluster=${encodeURIComponent(id)}`)
|
||||
.then((response) => response.json());
|
||||
expect(scoped.handles.handles).toEqual([]);
|
||||
expect(scoped.handles.handles.length).toBeGreaterThan(0);
|
||||
expect(
|
||||
scoped.handles.handles.every(
|
||||
(handle: { kind: string; editable: boolean }) => handle.kind === 'cluster-carriageway-width' && handle.editable,
|
||||
),
|
||||
).toBe(true);
|
||||
expect(scoped.junctionStructure.topologyFingerprint).toBe(structure.topologyFingerprint);
|
||||
await page.getByRole('button', { name: '开启编辑模式' }).click();
|
||||
await expect(workspace.getByText('路口参数', { exact: true })).toBeVisible();
|
||||
await expect(workspace.getByText(/车行道宽度/).first()).toBeVisible();
|
||||
await page.reload();
|
||||
await expect(armButtons).toHaveCount(structure.arms.length);
|
||||
await expect(armButtons.first()).toHaveAttribute('aria-pressed', 'false');
|
||||
|
||||
@@ -25,6 +25,14 @@ function anchorFor(kind) {
|
||||
if (type === 'road-interval')
|
||||
return { type, roadId: 'road:way/1:forward', startStation: 0.25, endStation: 0.75, side: 'left' };
|
||||
if (type === 'junction-approach') return { type, nodeId: 'node/9', segmentId: 'road:way/1:segment/0' };
|
||||
if (type === 'cluster-carriageway')
|
||||
return {
|
||||
type,
|
||||
clusterId: 'cluster/9',
|
||||
carriagewayKey: 'cluster:cluster%2F9:carriageway:node%2F9/road%3Away%2F1%3Asegment%2F0/road%3Away%2F1%3Aforward',
|
||||
sourceNodeIds: ['node/9', 'node/10'],
|
||||
sourceRoadIds: ['road:way/1:forward'],
|
||||
};
|
||||
if (type === 'lane') return { type, laneId: 'lane:road:way/1:forward:1' };
|
||||
return { type, nodeId: 'node/9', incomingRoadId: 'road:way/1:forward', outgoingRoadId: 'road:way/2:forward' };
|
||||
}
|
||||
@@ -42,6 +50,8 @@ function valueFor(kind) {
|
||||
return { boundaryIndex: 2, offsetMeters: -1.6, transition: 'smoothstep' };
|
||||
case 'junction-approach-width':
|
||||
return { widthMeters: 12.5 };
|
||||
case 'cluster-carriageway-width':
|
||||
return { widthMeters: 12.5 };
|
||||
case 'junction-cutback':
|
||||
return { cutbackMeters: 4 };
|
||||
case 'junction-corner-radius':
|
||||
@@ -102,6 +112,7 @@ assert.deepEqual(CONSTRAINT_KINDS, [
|
||||
'road-sidewalk-width',
|
||||
'road-lane-divider',
|
||||
'junction-approach-width',
|
||||
'cluster-carriageway-width',
|
||||
'junction-cutback',
|
||||
'junction-corner-radius',
|
||||
'junction-crosswalk-inset',
|
||||
|
||||
@@ -256,10 +256,18 @@ const complexInput = {
|
||||
};
|
||||
const complexArea = compileInput(complexInput).area;
|
||||
const clusterState = editState(complexArea, selectionFrom({ cluster: cluster.id }));
|
||||
assert.deepEqual(clusterState.handles.handles, [], 'cluster selection must never fall through to node handles');
|
||||
assert.ok(
|
||||
clusterState.handles.handles.every((handle) => handle.kind === 'cluster-carriageway-width'),
|
||||
'cluster selection publishes only scoped complex carriageway width handles',
|
||||
);
|
||||
assert.ok(clusterState.handles.handles.length, 'the complex fixture must publish editable carriageways');
|
||||
assert.deepEqual(clusterState.junctionStructure.junctionRef, { type: 'cluster', id: cluster.id });
|
||||
assert.equal(clusterState.junctionStructure.shape.effectiveArmCount, 5);
|
||||
assert.equal(clusterState.junctionStructure.capability.editable, false);
|
||||
assert.equal(
|
||||
clusterState.junctionStructure.capability.editable,
|
||||
false,
|
||||
'structure capability opens with the frontend stage',
|
||||
);
|
||||
const complexTracked = trackedFiles.map(({ file }) => ({
|
||||
file,
|
||||
bytes: fs.readFileSync(file),
|
||||
@@ -267,12 +275,51 @@ const complexTracked = trackedFiles.map(({ file }) => ({
|
||||
}));
|
||||
const emptyDocument = { ...clusterState.document, constraints: [], operations: [] };
|
||||
const clusterPreview = editPreview(complexArea, { document: emptyDocument, selection: { cluster: cluster.id } });
|
||||
assert.deepEqual(clusterPreview.handles.handles, []);
|
||||
assert.deepEqual(clusterPreview.handles.handles, clusterState.handles.handles);
|
||||
assert.deepEqual(
|
||||
clusterPreview.junctionStructure,
|
||||
clusterState.junctionStructure,
|
||||
'preview and persisted compiler structure agree',
|
||||
);
|
||||
const complexWidthHandle = clusterState.handles.handles[0];
|
||||
const complexWidthConstraint = {
|
||||
id: 'constraint:complex-width',
|
||||
kind: 'cluster-carriageway-width',
|
||||
anchor: complexWidthHandle.anchor,
|
||||
anchorSnapshot: {
|
||||
coordinate: complexWidthHandle.position,
|
||||
tangentAzimuth: complexWidthHandle.axisAzimuth,
|
||||
roadLengthMeters: 120,
|
||||
osmNodeIds: complexWidthHandle.anchor.sourceNodeIds,
|
||||
},
|
||||
value: { widthMeters: complexWidthHandle.value.current + 0.25 },
|
||||
enabled: true,
|
||||
status: 'exact',
|
||||
provenance: { operationId: 'operation:complex-width', createdAt: '2026-09-08T00:00:00.000Z' },
|
||||
};
|
||||
const widenedClusterPreview = editPreview(complexArea, {
|
||||
document: {
|
||||
...emptyDocument,
|
||||
constraints: [complexWidthConstraint],
|
||||
operations: [
|
||||
{
|
||||
id: 'operation:complex-width',
|
||||
createdAt: '2026-09-08T00:00:00.000Z',
|
||||
constraintIds: [complexWidthConstraint.id],
|
||||
},
|
||||
],
|
||||
},
|
||||
selection: { cluster: cluster.id },
|
||||
});
|
||||
const complexSurface = (preview) =>
|
||||
preview.layers.roadSurface.features.find(
|
||||
(feature) => feature.properties.carriageway_key === complexWidthHandle.anchor.carriagewayKey,
|
||||
);
|
||||
assert.notDeepEqual(
|
||||
complexSurface(widenedClusterPreview).geometry,
|
||||
complexSurface(clusterPreview).geometry,
|
||||
'a cluster carriageway constraint must change compiled complex geometry',
|
||||
);
|
||||
const browsing = browseState(complexArea);
|
||||
const unavailableStructureState = browseState({
|
||||
...complexArea,
|
||||
|
||||
Reference in new issue
Block a user