feat: make crosswalk size a constraint the geometry stage reads

Every zebra was six stripes at 3m by 0.45m on a 0.9m pitch, all literals. Depth
and stripe count are now a constraint, junction-crosswalk-size, and the loop
reads them.

The span across the road stays derived rather than stored: it is count times
pitch, and pitch is fixed because stripe and gap widths are standardised while
the road they cross is not. Widening a crossing means adding stripes, which is
what a real one does, and it is why the span quantises in 0.9m steps.

That also fixes a span pinned at 4.95m regardless of the street. Measured, every
crossing sat on a 6.50m carriageway and covered under four fifths of it. The
default now follows the segment width — both directions, since a crossing spans
the carriageway — giving eight stripes and 6.74m, reaching the kerb rather than
stopping short. Fixture baselines move for exactly two entries on the one area
with crossings; the area without them is untouched.

No handle is published yet. design.md requires proving compileGeometry() consumes
a parameter before any grip is drawn — the rule left over from profile.interval
shipping a handle that did nothing — so the grips come next, on a value already
known to work.

Adding the kind made the client's exhaustive scalar switch fail to compile, which
is the check working: size is a pair and has no dragged-scalar form, so that case
now says so and throws rather than writing half a value.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
que01andClaude Opus 5 committed 2026-08-31 17:10:45 +08:00
1 parent 84c82f3f09
commit f3924caa5c
10 files changed
+176 -13

No files matched your search

+62 -8
View File
@@ -7,7 +7,15 @@ const { buildComplexJunctionGeometry, complexJunctionMetrics } = require('./comp
const { diagnostic } = require('./diagnostics');
// Default marking placement lives with the constraint bounds in the solver, which
// is the IO-free module; importing the other way would drag fs into it.
const { CROSSWALK_JUNCTION_INSET_METERS, STOP_LINE_OFFSET_METERS } = require('./direct-edit-solver');
const {
CROSSWALK_DEPTH_METERS,
CROSSWALK_JUNCTION_INSET_METERS,
CROSSWALK_STRIPE_PITCH_METERS,
CROSSWALK_STRIPE_WIDTH_METERS,
MAX_CROSSWALK_STRIPE_COUNT,
MIN_CROSSWALK_STRIPE_COUNT,
STOP_LINE_OFFSET_METERS,
} = require('./direct-edit-solver');
const {
roadSurfaceId,
sidewalkId,
@@ -861,6 +869,9 @@ function applyDirectJunctionPlans(plans, directEdit) {
// 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.crosswalkDepthMeters)) approach.crosswalkDepthMeters = override.crosswalkDepthMeters;
if (Number.isInteger(override.crosswalkStripeCount))
approach.crosswalkStripeCount = override.crosswalkStripeCount;
if (Number.isFinite(override.stopLineOffsetMeters)) approach.stopLineOffsetMeters = override.stopLineOffsetMeters;
}
const cutbacks = Object.values(directPlan.approaches || {})
@@ -1253,18 +1264,30 @@ function compileControlMarkings(model, lanes, diagnostics, junctionPlans = new M
(a, b) => a.junctionDistanceMeters - b.junctionDistanceMeters || a.placement.distance - b.placement.distance,
)[0];
const crosswalkCandidate = approach || candidate;
const junctionInsetMeters = approach ? crossingJunctionInset(approach, junctionPlans) : 0;
const junctionInsetMeters = approach ? crossingJunctionInset(approach, junctionPlans, model) : 0;
const controlCenter = offsetByMeters(crossing.coordinate, crosswalkCandidate.placement.axis, junctionInsetMeters);
const { axis } = crosswalkCandidate.placement;
const across = [-axis[1], axis[0]];
for (let index = 0; index < 6; index += 1)
// Depth and stripe count are the editable pair; the span across the road is
// `(count - 1) * pitch`, centred on the crossing, and therefore quantised.
const size = approachControls(junctionPlans, crosswalkCandidate.road, model);
const stripeCount = size.crosswalkStripeCount;
const firstOffset = -((stripeCount - 1) * CROSSWALK_STRIPE_PITCH_METERS) / 2;
for (let index = 0; index < stripeCount; index += 1)
crosswalks.push(
controlFeature(
'crosswalk',
crossing,
crosswalkCandidate,
index + 1,
rectangleAt(controlCenter, axis, across, 3, 0.45, -2.25 + index * 0.9),
rectangleAt(
controlCenter,
axis,
across,
size.crosswalkDepthMeters,
CROSSWALK_STRIPE_WIDTH_METERS,
firstOffset + index * CROSSWALK_STRIPE_PITCH_METERS,
),
{ junctionInsetMeters },
),
);
@@ -1288,7 +1311,7 @@ function compileControlMarkings(model, lanes, diagnostics, junctionPlans = new M
const stopCenter = offsetByMeters(
laneCenterAtCrossing,
approach.placement.axis,
-approachControls(junctionPlans, approach.road).stopLineOffsetMeters,
-approachControls(junctionPlans, approach.road, model).stopLineOffsetMeters,
);
stopLines.push(
controlFeature(
@@ -1309,10 +1332,41 @@ function compileControlMarkings(model, lanes, diagnostics, junctionPlans = new M
* 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) {
/**
* Stripes needed to carry a zebra across `widthMeters`.
*
* Span is `(count - 1) * pitch + stripeWidth`, so this inverts that and rounds
* up: a crossing that stops short of the kerb is worse than one that overruns it
* slightly. Pitch is fixed because stripe and gap widths are standardised while
* the road they cross is not — widening by adding stripes is what a real crossing
* does, and it is why the span quantises.
*/
function stripeCountForWidth(widthMeters) {
if (!Number.isFinite(widthMeters) || widthMeters <= 0) return MIN_CROSSWALK_STRIPE_COUNT;
const spans = Math.ceil((widthMeters - CROSSWALK_STRIPE_WIDTH_METERS) / CROSSWALK_STRIPE_PITCH_METERS);
return Math.min(MAX_CROSSWALK_STRIPE_COUNT, Math.max(MIN_CROSSWALK_STRIPE_COUNT, spans + 1));
}
/** Total carriageway width at a segment: a crossing spans both directions. */
function segmentWidthMeters(model, road) {
const roads = (model?.roads || []).filter((item) => item.segmentId === road?.segmentId);
const total = roads.reduce((sum, item) => sum + (Number(item.widthMeters) || 0), 0);
return total > 0 ? total : Number(road?.widthMeters) || 0;
}
function approachControls(junctionPlans, road, model) {
const plan = junctionPlans.get(road?.sourceNodeIds?.at(-1));
const approach = plan?.approaches?.find?.((item) => item.segmentId === road.segmentId);
return {
crosswalkDepthMeters: Number.isFinite(approach?.crosswalkDepthMeters)
? approach.crosswalkDepthMeters
: CROSSWALK_DEPTH_METERS,
// Default follows the road. The span used to be a hard-coded six stripes,
// i.e. 4.95m on every crossing whatever the street was — under half the
// carriageway on a wide one.
crosswalkStripeCount: Number.isInteger(approach?.crosswalkStripeCount)
? approach.crosswalkStripeCount
: stripeCountForWidth(segmentWidthMeters(model, road)),
crosswalkInsetMeters: Number.isFinite(approach?.crosswalkInsetMeters)
? approach.crosswalkInsetMeters
: CROSSWALK_JUNCTION_INSET_METERS,
@@ -1322,11 +1376,11 @@ function approachControls(junctionPlans, road) {
};
}
function crossingJunctionInset(candidate, junctionPlans) {
function crossingJunctionInset(candidate, junctionPlans, model) {
const junctionNodeId = candidate.road.sourceNodeIds.at(-1);
const plan = junctionPlans.get(junctionNodeId);
if (!plan) return 0;
const inset = approachControls(junctionPlans, candidate.road).crosswalkInsetMeters;
const inset = approachControls(junctionPlans, candidate.road, model).crosswalkInsetMeters;
const targetDistance = Math.max(0, plan.cutbackMeters - inset);
return Math.min(CROSSWALK_MAX_JUNCTION_INSET_METERS, Math.max(0, candidate.junctionDistanceMeters - targetDistance));
}