fix: publish the crosswalk inset ceiling that actually moves the zebra
Every junction-crosswalk-inset handle advertised max 8. Sweeping the real response across eight groups, the ceiling ran 1.0 to 4.5 and varied per approach, so 44-88% of the declared range moved nothing and returned no diagnostic. Two approaches had a ceiling at or below the 1.5 default, meaning dragging outward there did nothing at all — which is what made direct editing look broken rather than limited. crossingJunctionInset() stops responding once the inset reaches the cutback, and sooner still when the crossing sits beyond the 4m cap, giving cutback - max(0, junctionDistance - 4). Predicted ceilings matched all eight measurements within the 0.5m sweep step, and the published max now matches them 8/8 where it used to be a flat 8. The distance needs to know which crossing an approach serves, which lived only inside compileControlMarkings(). crossing-approach.js now holds that rule at road level, which is model-only and so usable from the solver. Behaviour is unchanged: every lane of a road shares its junction distance, so the compiler's (road, lane) ordering already grouped by road — fixtures confirm the geometry is byte-identical. Both directional roads of a segment can meet at one junction serving different crossings; taking the first match published one road's ceiling on the other's handle. The road that ends at this node wins, which is the same rule the client uses to find the handle and the same one crossingJunctionInset() applies. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8a039f47ab
commit
479ffd00ed
3 files changed
+184
-3
No files matched your search
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { diagnostic } = require('./diagnostics');
|
||||
const { approachForCrossing, arrivalEndpointIds, effectiveCrosswalkInsetMax } = require('./crossing-approach');
|
||||
const { haversineMeters, metersAt, polylineLength } = require('../geometry/lane-geometry');
|
||||
const {
|
||||
roadSurfaceId,
|
||||
@@ -642,6 +643,15 @@ function junctionAffects(model, nodeId, segmentIds) {
|
||||
|
||||
function makeJunctionHandles(model, junctionData, constraints) {
|
||||
const handles = [];
|
||||
// Which crossing each approach road serves, so the crosswalk handle can publish
|
||||
// a ceiling that actually moves the zebra. Built once: `approachForCrossing()`
|
||||
// scans the roads per crossing.
|
||||
const crossingByRoadId = new Map();
|
||||
const arrivals = arrivalEndpointIds(model || {});
|
||||
for (const crossing of model.crossings || []) {
|
||||
const match = approachForCrossing(model, crossing, arrivals);
|
||||
if (match) crossingByRoadId.set(match.road.id, match);
|
||||
}
|
||||
for (const [nodeId, approaches] of junctionData.approaches) {
|
||||
const segmentIds = new Set(approaches.map((item) => item.segmentId));
|
||||
for (const approach of approaches) {
|
||||
@@ -701,18 +711,47 @@ function makeJunctionHandles(model, junctionData, constraints) {
|
||||
);
|
||||
// Control markings sit inside the reserve but are not junction *shape*, so
|
||||
// they drag along the approach tangent like the cutback does.
|
||||
//
|
||||
// The ceiling is per-approach, not the flat MAX_CROSSWALK_INSET_METERS this
|
||||
// used to publish: `crossingJunctionInset()` saturates once the inset
|
||||
// reaches the cutback, and sooner when the crossing sits far from the
|
||||
// junction. Measured across eight groups the real ceiling ran 1.0–4.5m
|
||||
// against a declared 8, leaving 44–88% of the range moving nothing and
|
||||
// saying nothing — the dead-control failure `flag.ts` exists to prevent.
|
||||
// `approach.items` can hold both directional roads of a segment, and each
|
||||
// may serve a different crossing at a different junction. Take the one that
|
||||
// actually ends here — the same last-source-node rule
|
||||
// `crossingJunctionInset()` uses to find its junction plan. Without the
|
||||
// filter, two handles on one segment published the same ceiling, and one of
|
||||
// them was wrong.
|
||||
const crossing = approach.items
|
||||
.filter((item) => String(item.road.sourceNodeIds?.at(-1)) === String(nodeId))
|
||||
.map((item) => crossingByRoadId.get(item.road.id))
|
||||
.find(Boolean);
|
||||
const crosswalkConstraint = constraintFor(constraints, 'junction-crosswalk-inset', anchor);
|
||||
const insetValue = numericValue(crosswalkConstraint, 'insetMeters', CROSSWALK_JUNCTION_INSET_METERS);
|
||||
const cutbackValue = numericValue(cutbackConstraint, 'cutbackMeters', approach.cutback);
|
||||
const ceiling = crossing
|
||||
? effectiveCrosswalkInsetMax(cutbackValue, crossing.junctionDistanceMeters)
|
||||
: MAX_CROSSWALK_INSET_METERS;
|
||||
// Never below the value already in force: a max under `current` would be a
|
||||
// manifest that contradicts itself. Equal to it is honest — it says this
|
||||
// approach has no headroom left, which is a real state.
|
||||
const insetMax = Math.min(
|
||||
MAX_CROSSWALK_INSET_METERS,
|
||||
Math.max(insetValue, Number.isFinite(ceiling) ? ceiling : MAX_CROSSWALK_INSET_METERS),
|
||||
);
|
||||
add(
|
||||
'junction-crosswalk-inset',
|
||||
numericValue(crosswalkConstraint, 'insetMeters', CROSSWALK_JUNCTION_INSET_METERS),
|
||||
insetValue,
|
||||
0,
|
||||
MAX_CROSSWALK_INSET_METERS,
|
||||
insetMax,
|
||||
// The approach tangent points away from the junction. Increasing an
|
||||
// inset moves the crosswalk toward the junction, so expose the inverse
|
||||
// axis to keep positive drag values aligned with the handle's meaning.
|
||||
(tangent + 180) % 360,
|
||||
crosswalkConstraint,
|
||||
controlPoint(numericValue(crosswalkConstraint, 'insetMeters', CROSSWALK_JUNCTION_INSET_METERS), -1),
|
||||
controlPoint(insetValue, -1),
|
||||
);
|
||||
const stopLineConstraint = constraintFor(constraints, 'junction-stop-line-offset', anchor);
|
||||
add(
|
||||
|
||||
Reference in new issue
Block a user