feat: complete complex junction transition editing
This commit is contained in:
1 parent
801d8be980
commit
79f83412e6
18 files changed
+400
-59
No files matched your search
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user