fix: align carriageway edge handles with entry geometry

This commit is contained in:
que01 committed 2026-09-11 09:36:31 +08:00
1 parent 44fa82299b
commit a5089220b5
5 files changed
+157 -3

No files matched your search

+25 -3
View File
@@ -1625,6 +1625,25 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster
editable: true,
});
}
const positionEdit = constraintFor(constraints, 'cluster-carriageway-position', {
clusterId,
carriagewayKey: item.key,
});
const directionEdit = constraintFor(constraints, 'cluster-carriageway-direction', {
clusterId,
carriagewayKey: item.key,
});
// Match JunctionBoundaryGraph's effective inner section. The old handle
// placement used the legacy cutback station, which diverges as soon as a
// transition length is edited (and is especially visible on curves).
const effectiveStationMeters = Math.max(
0,
Math.min(item.length, bounds.outer - transitionValue + numericValue(positionEdit, 'offsetMeters', 0)),
);
const effectiveStation = effectiveStationMeters / Math.max(item.length, 1);
const effectiveCenter = coordinateAt(line, effectiveStation);
const effectiveTangent = tangentAzimuth(line, effectiveStation) + numericValue(directionEdit, 'offsetDegrees', 0);
const effectiveWidth = numericValue(constraint, 'widthMeters', item.widthMeters);
for (const side of ['left', 'right']) {
const candidates = constraints.filter(
(edit) =>
@@ -1636,6 +1655,8 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster
);
const edgeConstraint = candidates.at(-1);
const edgeValue = edgeConstraint?.value || {};
const current = Number(edgeValue[`${side}OffsetMeters`]) || 0;
const sideAzimuth = effectiveTangent + (side === 'left' ? -90 : 90);
handles.push({
handleId: `handle:cluster-carriageway-edge-offset:${side}:${item.key}`,
kind: 'cluster-carriageway-edge-offset',
@@ -1647,9 +1668,10 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster
sourceNodeIds: item.sourceNodeIds,
sourceRoadIds: item.sourceRoadIds,
},
position: point,
axisAzimuth: (tangentAzimuth(line, station) + (side === 'left' ? 270 : 90)) % 360,
value: { current: Number(edgeValue[`${side}OffsetMeters`]) || 0, min: -10, max: 10, unit: 'meter' },
position: offsetCoordinate(effectiveCenter, sideAzimuth, effectiveWidth / 2 + current),
// The client reverses this shared rightward normal for a left-side drag.
axisAzimuth: (effectiveTangent + 90) % 360,
value: { current, min: -10, max: 10, unit: 'meter' },
...(edgeConstraint?.anchor.side === side ? { constraintId: edgeConstraint.id } : {}),
affects: [`complex-junction:${clusterId}:carriageway:${item.approach.segmentId}`],
editable: true,