feat: override which turn arrow a lane shows
The arrow on a lane came from the OSM turn:lanes tag with no way to change it, and a lane the tag skipped got no arrow at all. lane-maneuver is a v1 override that sets it. v1 rather than a v2 constraint, because "which arrow" is a discrete attribute of a lane with no station to anchor to, while every v2 anchor is positional. The existing road override already covers OSM-derived values this way — laneCount, width, sidewalks — and this is the same kind of thing. Arrow *placement* is the positional half and stays out; it also still has an open question about whether a group is a lane or a single arrow. Three behaviours, each measured against compiled output: an override replaces the tag's maneuver, it adds arrows to a lane the tag never marked, and '' removes one the tag asked for. The empty string is therefore distinguished from "no override" rather than falling through to the tag. An empty override set leaves the arrows byte-identical and the fixtures untouched. Validation lists the accepted maneuvers and rejects anything else, including correctly-spelled components in the wrong order. It cannot be left to normalizeManeuver(), which returns unrecognised input unchanged — a typo would otherwise reach the template lookup and silently produce no arrow. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
15d41be444
commit
335c8ea68a
7 files changed
+173
-2
No files matched your search
@@ -28,4 +28,43 @@ const model = compiler.nativeRoad.compileRoadModel(fs.readFileSync(fixture, 'utf
|
||||
overrides: [],
|
||||
});
|
||||
assert.equal(model.roads.length, 24);
|
||||
// --- lane maneuver override ---------------------------------------------------
|
||||
//
|
||||
// The arrow a lane shows comes from the OSM `turn:lanes` tag, so overriding it is
|
||||
// a v1 override like `laneCount`, not a v2 positional constraint: "which arrow"
|
||||
// has no station to anchor to.
|
||||
{
|
||||
const { validateOverrides } = require('../src/compile/native-road');
|
||||
const laneModel = {
|
||||
roads: [{ id: 'road:way/1:forward', sourceRoadId: 'way/1', segmentId: 'segment:way/1/0', laneCount: 2 }],
|
||||
endpoints: [],
|
||||
connections: [],
|
||||
};
|
||||
const wrap = (item) => ({ schema: 'native-road-overrides/v1', overrides: [item] });
|
||||
const maneuver = (value, laneId = 'lane:road:way/1:forward:1') => ({
|
||||
id: 'm',
|
||||
kind: 'lane-maneuver',
|
||||
laneId,
|
||||
maneuver: value,
|
||||
});
|
||||
|
||||
assert.doesNotThrow(() => validateOverrides(wrap(maneuver('through;left')), laneModel));
|
||||
// '' is not "no override": it removes an arrow the tag asked for.
|
||||
assert.doesNotThrow(() => validateOverrides(wrap(maneuver('')), laneModel));
|
||||
assert.throws(() => validateOverrides(wrap(maneuver('u-turn')), laneModel), /Invalid lane maneuver/);
|
||||
// normalizeManeuver() returns unknown input unchanged, so the override layer is
|
||||
// the only thing standing between a typo and a silently missing arrow.
|
||||
assert.throws(() => validateOverrides(wrap(maneuver('left;through')), laneModel), /Invalid lane maneuver/);
|
||||
assert.throws(() => validateOverrides(wrap(maneuver(3)), laneModel), /Invalid lane maneuver/);
|
||||
assert.throws(
|
||||
() => validateOverrides(wrap(maneuver('left', 'lane:road:way/1:forward:9')), laneModel),
|
||||
/Unknown lane maneuver override target/,
|
||||
);
|
||||
// An unknown target retires like any other stale override rather than throwing.
|
||||
const stale = validateOverrides(wrap(maneuver('left', 'lane:road:way/9:forward:1')), laneModel, {
|
||||
skipStaleTargets: true,
|
||||
});
|
||||
assert.equal(stale.stale.length, 1);
|
||||
}
|
||||
|
||||
console.log('road compiler package tests passed');
|
||||
Reference in new issue
Block a user