feat(workbench): unify lane maneuver edits in v2
This commit is contained in:
1 parent
118dc8e9aa
commit
c804a373ca
15 files changed
+337
-263
No files matched your search
@@ -81,7 +81,7 @@ const junctionModel = {
|
||||
};
|
||||
const junctionResolution = resolveDirectEditConstraints(junctionModel, document([]), { revisionId: 'rev-junction' });
|
||||
assert.equal(junctionResolution.handles.reserves.length, 3);
|
||||
assert.equal(new Set(junctionResolution.handles.handles.map((handle) => handle.kind)).size, 8);
|
||||
assert.equal(new Set(junctionResolution.handles.handles.map((handle) => handle.kind)).size, 9);
|
||||
assert.ok(junctionResolution.handles.handles.every((handle) => handle.position.every(Number.isFinite)));
|
||||
assert.ok(junctionResolution.handles.handles.every((handle) => Number.isFinite(handle.axisAzimuth)));
|
||||
assert.ok(junctionResolution.handles.handles.some((handle) => handle.affects.includes('junction:node/junction')));
|
||||
@@ -145,7 +145,11 @@ assert.ok(
|
||||
);
|
||||
assert.ok(
|
||||
segmentScoped.every((handle) =>
|
||||
handle.kind.startsWith('road-') ? handle.anchor.roadId === 'road:a' : handle.anchor.segmentId === 'segment:a',
|
||||
handle.kind.startsWith('road-')
|
||||
? handle.anchor.roadId === 'road:a'
|
||||
: handle.kind === 'lane-maneuver'
|
||||
? handle.anchor.roadId === 'road:a'
|
||||
: handle.anchor.segmentId === 'segment:a',
|
||||
),
|
||||
'a segment selection must only carry that segment’s handles',
|
||||
);
|
||||
@@ -154,7 +158,9 @@ assert.deepEqual(
|
||||
segmentScoped.map((handle) => handle.handleId).sort(),
|
||||
unscoped
|
||||
.filter((handle) =>
|
||||
handle.kind.startsWith('road-') ? handle.anchor.roadId === 'road:a' : handle.anchor.segmentId === 'segment:a',
|
||||
handle.kind.startsWith('road-') || handle.kind === 'lane-maneuver'
|
||||
? handle.anchor.roadId === 'road:a'
|
||||
: handle.anchor.segmentId === 'segment:a',
|
||||
)
|
||||
.filter((handle) => !SHAPE_KINDS.includes(handle.kind))
|
||||
.map((handle) => handle.handleId)
|
||||
|
||||
@@ -28,54 +28,4 @@ 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));
|
||||
assert.doesNotThrow(() =>
|
||||
validateOverrides(wrap({ ...maneuver('through;left'), placementDistanceMeters: 12.5 }), 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'), placementDistanceMeters: -1 }), laneModel),
|
||||
/Invalid lane maneuver placement/,
|
||||
);
|
||||
assert.throws(
|
||||
() => validateOverrides(wrap({ ...maneuver('left'), placementDistanceMeters: '12' }), laneModel),
|
||||
/Invalid lane maneuver placement/,
|
||||
);
|
||||
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');
|
||||
@@ -25,6 +25,7 @@ function anchorFor(kind) {
|
||||
if (type === 'road-interval')
|
||||
return { type, roadId: 'road:way/1:forward', startStation: 0.25, endStation: 0.75, side: 'left' };
|
||||
if (type === 'junction-approach') return { type, nodeId: 'node/9', segmentId: 'road:way/1:segment/0' };
|
||||
if (type === 'lane') return { type, laneId: 'lane:road:way/1:forward:1' };
|
||||
return { type, nodeId: 'node/9', incomingRoadId: 'road:way/1:forward', outgoingRoadId: 'road:way/2:forward' };
|
||||
}
|
||||
|
||||
@@ -51,6 +52,8 @@ function valueFor(kind) {
|
||||
return { depthMeters: 3, stripeCount: 8 };
|
||||
case 'junction-stop-line-offset':
|
||||
return { offsetMeters: 2.7 };
|
||||
case 'lane-maneuver':
|
||||
return { maneuver: 'left', placementDistanceMeters: 8 };
|
||||
default:
|
||||
throw new Error(`valueFor has no case for ${kind}; the taxonomy grew without this fixture`);
|
||||
}
|
||||
@@ -104,6 +107,7 @@ assert.deepEqual(CONSTRAINT_KINDS, [
|
||||
'junction-crosswalk-inset',
|
||||
'junction-crosswalk-size',
|
||||
'junction-stop-line-offset',
|
||||
'lane-maneuver',
|
||||
]);
|
||||
|
||||
// --- round trip is lossless --------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user