feat: complete carriageway direction interaction
This commit is contained in:
1 parent
a5089220b5
commit
067c0e370d
10 files changed
+251
-41
No files matched your search
@@ -545,7 +545,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
center,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
} else if (!coreRing) {
|
||||
cornerDiagnostics.push(
|
||||
helpers.diagnostic(
|
||||
'warning',
|
||||
|
||||
@@ -390,6 +390,19 @@ function clusterCutbackMaximum(cluster, approachLength) {
|
||||
);
|
||||
}
|
||||
|
||||
function clusterEdgeOffsetRange(item, widthMeters, side, edgeOffsets = {}) {
|
||||
if (!item || !['left', 'right'].includes(side)) return null;
|
||||
const width = Number(widthMeters);
|
||||
const minimumWidth = Number(item.laneCount) * MIN_LANE_WIDTH_METERS;
|
||||
if (!Number.isFinite(width) || !Number.isFinite(minimumWidth)) return null;
|
||||
const otherSide = side === 'left' ? 'right' : 'left';
|
||||
const otherOffset = Number(edgeOffsets[`${otherSide}OffsetMeters`]) || 0;
|
||||
return {
|
||||
min: Math.max(-width / 2, minimumWidth - width - otherOffset),
|
||||
max: width / 2,
|
||||
};
|
||||
}
|
||||
|
||||
function roadGroups(model) {
|
||||
const groups = new Map();
|
||||
for (const road of Array.isArray(model?.roads) ? model.roads : []) {
|
||||
@@ -963,18 +976,30 @@ 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 transitionMax = item && cluster ? transitionBounds(model, cluster, item, constraints).max : 0;
|
||||
const widthConstraint = item
|
||||
? constraintFor(constraints, 'cluster-carriageway-width', {
|
||||
clusterId: item.clusterId,
|
||||
carriagewayKey: item.key,
|
||||
})
|
||||
: null;
|
||||
const effectiveWidth = item ? numericValue(widthConstraint, 'widthMeters', item.widthMeters) : 0;
|
||||
const previousEdges = item
|
||||
? clusterEdgeOffsets.get(item.clusterId)?.get(item.key) || { leftOffsetMeters: 0, rightOffsetMeters: 0 }
|
||||
: null;
|
||||
const edgeSides = constraint.anchor?.side ? [constraint.anchor.side] : ['left', 'right'];
|
||||
if (!item) {
|
||||
blocking(diagnostics, constraint, 'direct-edit-cluster-carriageway-missing', '复杂路口车行道锚点不存在。');
|
||||
applied = false;
|
||||
} else if (
|
||||
(constraint.kind !== 'cluster-carriageway-edge-offset' && !Number.isFinite(value)) ||
|
||||
(constraint.kind === 'cluster-carriageway-edge-offset' &&
|
||||
(!Number.isFinite(value.leftOffsetMeters) ||
|
||||
!Number.isFinite(value.rightOffsetMeters) ||
|
||||
value.leftOffsetMeters < -10 ||
|
||||
value.leftOffsetMeters > 10 ||
|
||||
value.rightOffsetMeters < -10 ||
|
||||
value.rightOffsetMeters > 10)) ||
|
||||
(edgeSides.some((side) => !['left', 'right'].includes(side)) ||
|
||||
edgeSides.some((side) => {
|
||||
const field = `${side}OffsetMeters`;
|
||||
const candidate = value?.[field];
|
||||
const combined = { ...previousEdges, ...value, [field]: candidate };
|
||||
return !inRange(candidate, clusterEdgeOffsetRange(item, effectiveWidth, side, combined));
|
||||
}))) ||
|
||||
(constraint.kind === 'cluster-carriageway-width' &&
|
||||
(value < Math.max(MIN_LANE_WIDTH_METERS, item.laneCount * MIN_LANE_WIDTH_METERS) ||
|
||||
value > item.widthMeters * 2)) ||
|
||||
@@ -1520,12 +1545,34 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster
|
||||
for (const item of items) {
|
||||
const road = item.roads[0];
|
||||
const line = item.approach.endpoint.side === 'start' ? road.centerline : [...road.centerline].reverse();
|
||||
const station = Math.min(0.95, Math.max(0.05, item.approach.cutback / Math.max(item.approach.length, 1)));
|
||||
const point = coordinateAt(line, station);
|
||||
const constraint = constraintFor(constraints, 'cluster-carriageway-width', {
|
||||
clusterId,
|
||||
carriagewayKey: item.key,
|
||||
});
|
||||
const transitionConstraint = constraintFor(constraints, 'cluster-carriageway-transition-length', {
|
||||
clusterId,
|
||||
carriagewayKey: item.key,
|
||||
});
|
||||
const bounds = transitionBounds(model, cluster, item, constraints);
|
||||
const transitionValue = numericValue(transitionConstraint, 'transitionLengthMeters', bounds.current);
|
||||
const positionEdit = constraintFor(constraints, 'cluster-carriageway-position', {
|
||||
clusterId,
|
||||
carriagewayKey: item.key,
|
||||
});
|
||||
const directionEdit = constraintFor(constraints, 'cluster-carriageway-direction', {
|
||||
clusterId,
|
||||
carriagewayKey: item.key,
|
||||
});
|
||||
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 sourceTangent = tangentAzimuth(line, effectiveStation);
|
||||
const directionValue = numericValue(directionEdit, 'offsetDegrees', 0);
|
||||
const effectiveTangent = sourceTangent + directionValue;
|
||||
const effectiveWidth = numericValue(constraint, 'widthMeters', item.widthMeters);
|
||||
handles.push({
|
||||
handleId: `handle:cluster-carriageway-width:${item.key}`,
|
||||
kind: 'cluster-carriageway-width',
|
||||
@@ -1536,8 +1583,8 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster
|
||||
sourceNodeIds: item.sourceNodeIds,
|
||||
sourceRoadIds: item.sourceRoadIds,
|
||||
},
|
||||
position: point,
|
||||
axisAzimuth: (tangentAzimuth(line, station) + 90) % 360,
|
||||
position: effectiveCenter,
|
||||
axisAzimuth: (effectiveTangent + 90) % 360,
|
||||
value: {
|
||||
current: numericValue(constraint, 'widthMeters', item.widthMeters),
|
||||
min: Math.max(MIN_LANE_WIDTH_METERS, item.laneCount * MIN_LANE_WIDTH_METERS),
|
||||
@@ -1548,12 +1595,6 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster
|
||||
affects: [`complex-junction:${clusterId}:carriageway:${item.approach.segmentId}`],
|
||||
editable: true,
|
||||
});
|
||||
const transitionConstraint = constraintFor(constraints, 'cluster-carriageway-transition-length', {
|
||||
clusterId,
|
||||
carriagewayKey: item.key,
|
||||
});
|
||||
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({
|
||||
@@ -1604,7 +1645,6 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster
|
||||
});
|
||||
for (const [kind, field, unit, min, max] of [
|
||||
['cluster-carriageway-position', 'offsetMeters', 'meter', -20, 20],
|
||||
['cluster-carriageway-direction', 'offsetDegrees', 'degree', -15, 15],
|
||||
]) {
|
||||
const edit = constraintFor(constraints, kind, { clusterId, carriagewayKey: item.key });
|
||||
handles.push({
|
||||
@@ -1617,33 +1657,47 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster
|
||||
sourceNodeIds: item.sourceNodeIds,
|
||||
sourceRoadIds: item.sourceRoadIds,
|
||||
},
|
||||
position: point,
|
||||
axisAzimuth: tangentAzimuth(line, station),
|
||||
position: effectiveCenter,
|
||||
axisAzimuth: sourceTangent,
|
||||
value: { current: numericValue(edit, field, 0), min, max, unit },
|
||||
...(edit ? { constraintId: edit.id } : {}),
|
||||
affects: [`complex-junction:${clusterId}:carriageway:${item.approach.segmentId}`],
|
||||
editable: true,
|
||||
});
|
||||
}
|
||||
const positionEdit = constraintFor(constraints, 'cluster-carriageway-position', {
|
||||
clusterId,
|
||||
carriagewayKey: item.key,
|
||||
const directionRadiusMeters = Math.max(4, effectiveWidth / 2 + 2);
|
||||
handles.push({
|
||||
handleId: `handle:cluster-carriageway-direction:${item.key}`,
|
||||
kind: 'cluster-carriageway-direction',
|
||||
anchor: {
|
||||
type: 'cluster-carriageway',
|
||||
clusterId,
|
||||
carriagewayKey: item.key,
|
||||
sourceNodeIds: item.sourceNodeIds,
|
||||
sourceRoadIds: item.sourceRoadIds,
|
||||
},
|
||||
position: offsetCoordinate(effectiveCenter, effectiveTangent, directionRadiusMeters),
|
||||
axisAzimuth: effectiveTangent,
|
||||
interaction: { kind: 'rotation', center: effectiveCenter, radiusMeters: directionRadiusMeters },
|
||||
value: { current: directionValue, min: -15, max: 15, unit: 'degree' },
|
||||
...(directionEdit ? { constraintId: directionEdit.id } : {}),
|
||||
affects: [`complex-junction:${clusterId}:carriageway:${item.approach.segmentId}`],
|
||||
editable: true,
|
||||
});
|
||||
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);
|
||||
const edgeValues = {};
|
||||
for (const side of ['left', 'right']) {
|
||||
const edge = constraints
|
||||
.filter(
|
||||
(edit) =>
|
||||
edit.enabled !== false &&
|
||||
edit.kind === 'cluster-carriageway-edge-offset' &&
|
||||
edit.anchor.clusterId === clusterId &&
|
||||
edit.anchor.carriagewayKey === item.key &&
|
||||
(!edit.anchor.side || edit.anchor.side === side),
|
||||
)
|
||||
.at(-1);
|
||||
edgeValues[`${side}OffsetMeters`] = Number(edge?.value?.[`${side}OffsetMeters`]) || 0;
|
||||
}
|
||||
for (const side of ['left', 'right']) {
|
||||
const candidates = constraints.filter(
|
||||
(edit) =>
|
||||
@@ -1656,6 +1710,7 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster
|
||||
const edgeConstraint = candidates.at(-1);
|
||||
const edgeValue = edgeConstraint?.value || {};
|
||||
const current = Number(edgeValue[`${side}OffsetMeters`]) || 0;
|
||||
const range = clusterEdgeOffsetRange(item, effectiveWidth, side, edgeValues);
|
||||
const sideAzimuth = effectiveTangent + (side === 'left' ? -90 : 90);
|
||||
handles.push({
|
||||
handleId: `handle:cluster-carriageway-edge-offset:${side}:${item.key}`,
|
||||
@@ -1671,7 +1726,7 @@ function makeClusterCarriagewayHandles(model, junctionData, constraints, cluster
|
||||
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' },
|
||||
value: { current, min: range.min, max: range.max, unit: 'meter' },
|
||||
...(edgeConstraint?.anchor.side === side ? { constraintId: edgeConstraint.id } : {}),
|
||||
affects: [`complex-junction:${clusterId}:carriageway:${item.approach.segmentId}`],
|
||||
editable: true,
|
||||
|
||||
Reference in new issue
Block a user