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:
que01andClaude Opus 5 committed 2026-08-28 15:01:36 +08:00
1 parent 813809d25e
commit c7425f5ed4
47 files changed
+10496 -28

No files matched your search

+30 -2
View File
@@ -856,6 +856,11 @@ function applyDirectJunctionPlans(plans, directEdit) {
approach.cutbackMeters = override.cutbackMeters;
changed = true;
}
// Control-marking offsets move where the zebra and stop line sit; they do not
// reshape the junction, so they deliberately do not set `changed` and trigger
// a boundary recompute.
if (Number.isFinite(override.crosswalkInsetMeters)) approach.crosswalkInsetMeters = override.crosswalkInsetMeters;
if (Number.isFinite(override.stopLineOffsetMeters)) approach.stopLineOffsetMeters = override.stopLineOffsetMeters;
}
const cutbacks = Object.values(directPlan.approaches || {})
.map((entry) => entry.cutbackMeters)
@@ -1279,7 +1284,11 @@ function compileControlMarkings(model, lanes, diagnostics, junctionPlans = new M
const laneOffset = rawRoadPlacement ? project(approach.placement.point, rawRoadPlacement.point) : [0, 0];
const lateralOffset = laneOffset[0] * across[0] + laneOffset[1] * across[1];
const laneCenterAtCrossing = offsetByMeters(controlCenter, across, lateralOffset);
const stopCenter = offsetByMeters(laneCenterAtCrossing, approach.placement.axis, -STOP_LINE_OFFSET_METERS);
const stopCenter = offsetByMeters(
laneCenterAtCrossing,
approach.placement.axis,
-approachControls(junctionPlans, approach.road).stopLineOffsetMeters,
);
stopLines.push(
controlFeature(
'stop-line',
@@ -1294,11 +1303,30 @@ function compileControlMarkings(model, lanes, diagnostics, junctionPlans = new M
return { crosswalks, stopLines };
}
/**
* Per-approach overrides for the control markings, falling back to the module
* defaults. The junction a road approaches is the one at its far node, which is
* how `crossingJunctionInset()` has always resolved it.
*/
function approachControls(junctionPlans, road) {
const plan = junctionPlans.get(road?.sourceNodeIds?.at(-1));
const approach = plan?.approaches?.find?.((item) => item.segmentId === road.segmentId);
return {
crosswalkInsetMeters: Number.isFinite(approach?.crosswalkInsetMeters)
? approach.crosswalkInsetMeters
: CROSSWALK_JUNCTION_INSET_METERS,
stopLineOffsetMeters: Number.isFinite(approach?.stopLineOffsetMeters)
? approach.stopLineOffsetMeters
: STOP_LINE_OFFSET_METERS,
};
}
function crossingJunctionInset(candidate, junctionPlans) {
const junctionNodeId = candidate.road.sourceNodeIds.at(-1);
const plan = junctionPlans.get(junctionNodeId);
if (!plan) return 0;
const targetDistance = Math.max(0, plan.cutbackMeters - CROSSWALK_JUNCTION_INSET_METERS);
const inset = approachControls(junctionPlans, candidate.road).crosswalkInsetMeters;
const targetDistance = Math.max(0, plan.cutbackMeters - inset);
return Math.min(CROSSWALK_MAX_JUNCTION_INSET_METERS, Math.max(0, candidate.junctionDistanceMeters - targetDistance));
}