feat(workbench): unify lane maneuver edits in v2
This commit is contained in:
1 parent
118dc8e9aa
commit
c804a373ca
15 files changed
+337
-263
No files matched your search
@@ -27,6 +27,7 @@ const SOLVED_KINDS = new Set([
|
||||
'junction-crosswalk-inset',
|
||||
'junction-crosswalk-size',
|
||||
'junction-stop-line-offset',
|
||||
'lane-maneuver',
|
||||
]);
|
||||
const KINDS = [
|
||||
'road-edge-offset',
|
||||
@@ -38,7 +39,17 @@ const KINDS = [
|
||||
'junction-crosswalk-inset',
|
||||
'junction-crosswalk-size',
|
||||
'junction-stop-line-offset',
|
||||
'lane-maneuver',
|
||||
];
|
||||
const SUPPORTED_MANEUVERS = new Set([
|
||||
'',
|
||||
'through',
|
||||
'left',
|
||||
'right',
|
||||
'through;left',
|
||||
'through;right',
|
||||
'through;left;right',
|
||||
]);
|
||||
const MIN_LANE_WIDTH_METERS = 2.4;
|
||||
// Bounds for the control-marking offsets. The crosswalk may sit anywhere from the
|
||||
// junction boundary out to a few metres; the stop line must stay clear of the
|
||||
@@ -214,6 +225,15 @@ function snapshotCandidates(model, constraint) {
|
||||
return roads;
|
||||
}
|
||||
|
||||
function roadForLaneAnchor(model, laneAnchorId) {
|
||||
if (typeof laneAnchorId !== 'string') return null;
|
||||
for (const road of model.roads || []) {
|
||||
const count = Number(road.laneCount) || 0;
|
||||
for (let index = 1; index <= count; index += 1) if (laneId(road.id, index) === laneAnchorId) return road;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function reconcileConstraints(model, constraints, base, junctionData, context) {
|
||||
const versionChanged = Boolean(
|
||||
context.compilerGeometryVersion &&
|
||||
@@ -224,6 +244,12 @@ function reconcileConstraints(model, constraints, base, junctionData, context) {
|
||||
if (!constraint.enabled || !constraint.anchor || !['exact', 'recheck'].includes(constraint.status))
|
||||
return constraint;
|
||||
let matched = false;
|
||||
if (constraint.kind === 'lane-maneuver') {
|
||||
if (!roadForLaneAnchor(model, constraint.anchor.laneId))
|
||||
return { ...constraint, status: 'stale', replayReason: 'anchor-missing' };
|
||||
if (versionChanged) return { ...constraint, status: 'recheck' };
|
||||
return constraint;
|
||||
}
|
||||
if (constraint.kind.startsWith('road-')) {
|
||||
const road = roadForAnchor(model, constraint.anchor.roadId);
|
||||
matched = Boolean(road);
|
||||
@@ -537,6 +563,7 @@ function applyJunctionConstraint(model, constraint, junctionPlans, junctionData,
|
||||
function solveConstraints(model, constraints, junctionData, diagnostics) {
|
||||
const roadProfiles = new Map();
|
||||
const junctionPlans = new Map();
|
||||
const laneManeuvers = new Map();
|
||||
const states = [];
|
||||
for (const constraint of constraints) {
|
||||
if (!constraint.enabled) {
|
||||
@@ -564,6 +591,7 @@ function solveConstraints(model, constraints, junctionData, diagnostics) {
|
||||
},
|
||||
]),
|
||||
);
|
||||
const laneSnapshot = new Map(laneManeuvers);
|
||||
const junctionSnapshot = new Map(
|
||||
[...junctionPlans].map(([key, plan]) => [
|
||||
key,
|
||||
@@ -574,18 +602,44 @@ function solveConstraints(model, constraints, junctionData, diagnostics) {
|
||||
},
|
||||
]),
|
||||
);
|
||||
const applied = constraint.kind.startsWith('road-')
|
||||
? applyRoadConstraint(model, constraint, roadProfiles, diagnostics)
|
||||
: applyJunctionConstraint(model, constraint, junctionPlans, junctionData, diagnostics);
|
||||
let applied;
|
||||
if (constraint.kind === 'lane-maneuver') {
|
||||
const laneId = constraint.anchor?.laneId;
|
||||
const laneExists = Boolean(roadForLaneAnchor(model, laneId));
|
||||
const maneuver = constraint.value?.maneuver;
|
||||
const placement = constraint.value?.placementDistanceMeters;
|
||||
if (!laneExists) {
|
||||
blocking(diagnostics, constraint, 'direct-edit-lane-anchor-missing', '导向箭头车道锚点不存在。');
|
||||
applied = false;
|
||||
} else if (!SUPPORTED_MANEUVERS.has(maneuver)) {
|
||||
blocking(diagnostics, constraint, 'direct-edit-lane-maneuver-invalid', '导向箭头 maneuver 不受支持。');
|
||||
applied = false;
|
||||
} else if (placement !== undefined && (!Number.isFinite(placement) || placement < 0)) {
|
||||
blocking(diagnostics, constraint, 'direct-edit-lane-placement-invalid', '导向箭头位置必须是非负米数。');
|
||||
applied = false;
|
||||
} else {
|
||||
laneManeuvers.set(laneId, {
|
||||
maneuver,
|
||||
...(placement === undefined ? {} : { placementDistanceMeters: placement }),
|
||||
});
|
||||
applied = true;
|
||||
}
|
||||
} else {
|
||||
applied = constraint.kind.startsWith('road-')
|
||||
? applyRoadConstraint(model, constraint, roadProfiles, diagnostics)
|
||||
: applyJunctionConstraint(model, constraint, junctionPlans, junctionData, diagnostics);
|
||||
}
|
||||
if (!applied) {
|
||||
roadProfiles.clear();
|
||||
for (const [key, profile] of roadSnapshot) roadProfiles.set(key, profile);
|
||||
junctionPlans.clear();
|
||||
for (const [key, plan] of junctionSnapshot) junctionPlans.set(key, plan);
|
||||
laneManeuvers.clear();
|
||||
for (const [key, value] of laneSnapshot) laneManeuvers.set(key, value);
|
||||
}
|
||||
states.push(constraintState(constraint, applied, applied ? null : 'invalid'));
|
||||
}
|
||||
return { roadProfiles, junctionPlans, states };
|
||||
return { roadProfiles, junctionPlans, laneManeuvers, states };
|
||||
}
|
||||
|
||||
function roadAffects(roads, model, side, boundaryIndex) {
|
||||
@@ -717,6 +771,38 @@ function makeRoadHandles(model, groups, reserves, constraints, roadProfiles) {
|
||||
return handles;
|
||||
}
|
||||
|
||||
function makeLaneManeuverHandles(model, constraints) {
|
||||
const handles = [];
|
||||
for (const road of model.roads || []) {
|
||||
const laneCount = Number(road.laneCount) || 0;
|
||||
const length = polylineLength(road.centerline);
|
||||
if (!(length > 0) || road.centerline.length < 2) continue;
|
||||
for (let index = 1; index <= laneCount; index += 1) {
|
||||
const laneAnchorId = laneId(road.id, index);
|
||||
const constraint = constraints.find(
|
||||
(item) => item.kind === 'lane-maneuver' && item.anchor?.type === 'lane' && item.anchor.laneId === laneAnchorId,
|
||||
);
|
||||
const value = constraint?.value || {};
|
||||
const placement = Number.isFinite(value.placementDistanceMeters) ? value.placementDistanceMeters : 6;
|
||||
const station = Math.max(0, Math.min(1, 1 - placement / length));
|
||||
const position = coordinateAt(road.centerline, station);
|
||||
const axis = tangentAzimuth(road.centerline, station);
|
||||
handles.push({
|
||||
handleId: `handle:lane-maneuver:${laneAnchorId}`,
|
||||
kind: 'lane-maneuver',
|
||||
anchor: { type: 'lane', laneId: laneAnchorId, roadId: road.id },
|
||||
position,
|
||||
axisAzimuth: axis,
|
||||
value: { current: placement, min: 0, max: length, unit: 'meter' },
|
||||
...(constraint ? { constraintId: constraint.id } : {}),
|
||||
affects: [`turn-arrow:${laneAnchorId}`],
|
||||
editable: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
return handles;
|
||||
}
|
||||
|
||||
function junctionAffects(model, nodeId, segmentIds) {
|
||||
const roads = (model.roads || []).filter((road) => segmentIds.has(road.segmentId));
|
||||
const ids = [junctionSurfaceId(nodeId), ...roadAffects(roads, model)];
|
||||
@@ -927,6 +1013,9 @@ function selectHandles(handles, model, selection) {
|
||||
// they name their segment directly. Junction *shape* kinds stay out: those
|
||||
// are JunctionTools', and the main map must not offer a second way in.
|
||||
if (CONTROL_KINDS.has(handle.kind)) return handle.anchor.segmentId === wanted;
|
||||
if (handle.kind === 'lane-maneuver') {
|
||||
return handle.anchor?.type === 'lane' && segmentOf.get(handle.anchor.roadId) === wanted;
|
||||
}
|
||||
return handle.kind.startsWith('road-') && segmentOf.get(handle.anchor.roadId) === wanted;
|
||||
});
|
||||
}
|
||||
@@ -950,6 +1039,7 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {})
|
||||
[
|
||||
...makeRoadHandles(model || {}, groups, handles.reserves, reconciled, solved.roadProfiles),
|
||||
...makeJunctionHandles(model || {}, junctionData, reconciled),
|
||||
...makeLaneManeuverHandles(model || {}, reconciled),
|
||||
],
|
||||
model || {},
|
||||
context.selection,
|
||||
@@ -958,6 +1048,7 @@ function resolveDirectEditConstraints(model, editDocument = null, context = {})
|
||||
schema: RESOLUTION_SCHEMA,
|
||||
roadProfiles: solved.roadProfiles,
|
||||
junctionPlans: solved.junctionPlans,
|
||||
laneManeuvers: solved.laneManeuvers,
|
||||
handles,
|
||||
constraintStates: solved.states,
|
||||
diagnostics,
|
||||
@@ -979,5 +1070,6 @@ module.exports = {
|
||||
KINDS,
|
||||
GEOMETRY_VERSION,
|
||||
roadEdgeOffsetRange,
|
||||
SUPPORTED_MANEUVERS,
|
||||
resolveDirectEditConstraints,
|
||||
};
|
||||
Reference in new issue
Block a user