feat: make crosswalk and stop-line offsets solvable
Step 1 of the control-marking task, and deliberately server-only: no handle is drawn yet. This project already shipped a range handle for `profile.interval`, which compileGeometry ignores, so the control dragged and changed nothing. The consumer comes first now. Two kinds join the taxonomy — `junction-crosswalk-inset` and `junction-stop-line-offset`, both on the existing `junction-approach` anchor. The solver writes them onto the approach entry, `applyDirectJunctionPlans` carries them onto the compiled approach, and `compileControlMarkings` reads them in place of the module constants it used for every junction. They move markings without reshaping the junction, so unlike width and cutback they deliberately do not trigger a boundary recompute. `applyJunctionConstraint` becomes an explicit switch. Its trailing `else` had meant every kind that was not approach-width fell through to the cutback validator, so a new kind would have been silently validated and written as a cutback. The same non-exhaustive shape in the test fixture's `valueFor` is fixed the same way, and now throws for an unnamed kind rather than answering with a corner radius. design.md's taxonomy is updated with it — a test asserts the two cannot drift, which is what caught the omission. Measured on a 41-road workspace with 8 crossings: both constraints change their marking geometry, neither drags the other, and out-of-range blocks instead of clamping. That measurement is not in the suite: the synthetic junction resolves `junction_inset_m` to 0 because its crossing never binds to a plan, and the committed OSM fixture has no crossings at all. The tests assert the wiring the handles will depend on — values reaching the approach entry, distinct branches, blocking diagnostics — and the gap is recorded in the test itself. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
813809d25e
commit
c7425f5ed4
47 files changed
+10496
-28
No files matched your search
@@ -23,6 +23,8 @@ const SOLVED_KINDS = new Set([
|
||||
'junction-approach-width',
|
||||
'junction-cutback',
|
||||
'junction-corner-radius',
|
||||
'junction-crosswalk-inset',
|
||||
'junction-stop-line-offset',
|
||||
]);
|
||||
const KINDS = [
|
||||
'road-edge-offset',
|
||||
@@ -31,8 +33,15 @@ const KINDS = [
|
||||
'junction-approach-width',
|
||||
'junction-cutback',
|
||||
'junction-corner-radius',
|
||||
'junction-crosswalk-inset',
|
||||
'junction-stop-line-offset',
|
||||
];
|
||||
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
|
||||
// crossing it protects.
|
||||
const MAX_CROSSWALK_INSET_METERS = 8;
|
||||
const MIN_STOP_LINE_OFFSET_METERS = 0.5;
|
||||
const GEOMETRY_VERSION = 'native-road-package/v1.1';
|
||||
|
||||
function emptyHandleManifest(context) {
|
||||
@@ -366,27 +375,65 @@ function applyJunctionConstraint(model, constraint, junctionPlans, junctionData,
|
||||
widthMeters: approach.items.reduce((sum, item) => sum + item.road.widthMeters, 0),
|
||||
cutbackMeters: approach.cutback,
|
||||
});
|
||||
if (constraint.kind === 'junction-approach-width') {
|
||||
const width = Number(constraint.value?.widthMeters);
|
||||
if (!Number.isFinite(width) || width < 2.4) {
|
||||
blocking(diagnostics, constraint, 'direct-edit-min-approach-width', '路口进口宽度不能小于 2.4 米。');
|
||||
return false;
|
||||
// An explicit branch per kind: the previous `else` meant every kind that was not
|
||||
// approach-width fell through to the cutback validator, so a new kind would have
|
||||
// been silently validated as, and written as, a cutback.
|
||||
switch (constraint.kind) {
|
||||
case 'junction-approach-width': {
|
||||
const width = Number(constraint.value?.widthMeters);
|
||||
if (!Number.isFinite(width) || width < MIN_LANE_WIDTH_METERS) {
|
||||
blocking(diagnostics, constraint, 'direct-edit-min-approach-width', '路口进口宽度不能小于 2.4 米。');
|
||||
return false;
|
||||
}
|
||||
entry.widthMeters = width;
|
||||
return true;
|
||||
}
|
||||
entry.widthMeters = width;
|
||||
} else {
|
||||
const cutback = Number(constraint.value?.cutbackMeters);
|
||||
if (!Number.isFinite(cutback) || cutback < 1 || cutback > approach.length * 0.45) {
|
||||
blocking(
|
||||
diagnostics,
|
||||
constraint,
|
||||
'direct-edit-cutback-invalid',
|
||||
'路口 cutback 必须落在进口可用长度的 45% 以内。',
|
||||
);
|
||||
return false;
|
||||
case 'junction-cutback': {
|
||||
const cutback = Number(constraint.value?.cutbackMeters);
|
||||
if (!Number.isFinite(cutback) || cutback < 1 || cutback > approach.length * 0.45) {
|
||||
blocking(
|
||||
diagnostics,
|
||||
constraint,
|
||||
'direct-edit-cutback-invalid',
|
||||
'路口 cutback 必须落在进口可用长度的 45% 以内。',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
entry.cutbackMeters = cutback;
|
||||
return true;
|
||||
}
|
||||
entry.cutbackMeters = cutback;
|
||||
case 'junction-crosswalk-inset': {
|
||||
const inset = Number(constraint.value?.insetMeters);
|
||||
if (!Number.isFinite(inset) || inset < 0 || inset > MAX_CROSSWALK_INSET_METERS) {
|
||||
blocking(
|
||||
diagnostics,
|
||||
constraint,
|
||||
'direct-edit-crosswalk-inset-invalid',
|
||||
`斑马线内缩必须在 0 到 ${MAX_CROSSWALK_INSET_METERS} 米之间。`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
entry.crosswalkInsetMeters = inset;
|
||||
return true;
|
||||
}
|
||||
case 'junction-stop-line-offset': {
|
||||
const offset = Number(constraint.value?.offsetMeters);
|
||||
if (!Number.isFinite(offset) || offset < MIN_STOP_LINE_OFFSET_METERS || offset > approach.length * 0.45) {
|
||||
blocking(
|
||||
diagnostics,
|
||||
constraint,
|
||||
'direct-edit-stop-line-offset-invalid',
|
||||
`停止线退距必须在 ${MIN_STOP_LINE_OFFSET_METERS} 米到进口可用长度的 45% 之间。`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
entry.stopLineOffsetMeters = offset;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
blocking(diagnostics, constraint, 'direct-edit-unknown-junction-kind', '未知的路口约束类型。');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function solveConstraints(model, constraints, junctionData, diagnostics) {
|
||||
|
||||
Reference in new issue
Block a user