96 lines
2.9 KiB
JavaScript
96 lines
2.9 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert/strict');
|
|
const { projectJunctionStructure, standardsDiagnostics } = require('../src/compile/junction-projection');
|
|
|
|
const model = {
|
|
roads: [
|
|
{
|
|
id: 'road:north',
|
|
sourceNodeIds: ['junction'],
|
|
tags: { name: '北环路' },
|
|
direction: 'two-way',
|
|
laneCount: 2,
|
|
widthMeters: 7,
|
|
},
|
|
{
|
|
id: 'road:east',
|
|
sourceNodeIds: ['junction'],
|
|
tags: { name: '东环路' },
|
|
direction: 'oneway',
|
|
laneCount: 1,
|
|
widthMeters: 3.5,
|
|
},
|
|
{
|
|
id: 'road:remote',
|
|
sourceNodeIds: ['elsewhere'],
|
|
tags: { name: '不属于当前路口' },
|
|
direction: 'two-way',
|
|
laneCount: 2,
|
|
widthMeters: 7,
|
|
},
|
|
],
|
|
endpoints: [
|
|
{ nodeId: 'junction', coordinate: [120, 30] },
|
|
{ nodeId: 'elsewhere', coordinate: [120.01, 30.01] },
|
|
],
|
|
};
|
|
|
|
const structure = projectJunctionStructure({
|
|
model,
|
|
layers: {
|
|
crosswalks: {
|
|
type: 'FeatureCollection',
|
|
features: [{ type: 'Feature', properties: { native_id: 'crossing:north' }, geometry: null }],
|
|
},
|
|
vehicleStopLines: {
|
|
type: 'FeatureCollection',
|
|
features: [{ type: 'Feature', properties: { native_id: 'stop-line:north' }, geometry: null }],
|
|
},
|
|
islands: {
|
|
type: 'FeatureCollection',
|
|
features: [{ type: 'Feature', properties: { kind: 'island', native_id: 'island:north' }, geometry: null }],
|
|
},
|
|
medians: {
|
|
type: 'FeatureCollection',
|
|
features: [{ type: 'Feature', properties: { kind: 'median', native_id: 'median:center' }, geometry: null }],
|
|
},
|
|
sidewalkTurns: {
|
|
type: 'FeatureCollection',
|
|
features: [
|
|
{ type: 'Feature', properties: { kind: 'sidewalk-turn', native_id: 'sidewalk-turn:east' }, geometry: null },
|
|
],
|
|
},
|
|
intersectionSurface: { type: 'FeatureCollection', features: [] },
|
|
},
|
|
trafficSignals: {
|
|
assemblies: {
|
|
type: 'FeatureCollection',
|
|
features: [{ type: 'Feature', properties: { signal_uid: 'signal:north' }, geometry: null }],
|
|
},
|
|
},
|
|
});
|
|
|
|
assert.equal(structure.junctionKey, 'junction');
|
|
assert.equal(structure.shape.kind, 'unsupported');
|
|
assert.deepEqual(
|
|
structure.arms.map((arm) => arm.label),
|
|
['北环路', '东环路'],
|
|
);
|
|
assert.equal(structure.arms[1].directionality, 'one-way');
|
|
assert.equal(structure.arms[0].pedestrian.connected, false);
|
|
assert.equal(structure.arms[1].pedestrian.bicycleConnected, false);
|
|
assert.equal(structure.corners.length, 2);
|
|
assert.deepEqual(
|
|
structure.facilities.map((facility) => facility.kind),
|
|
['crossing', 'stop-line', 'signal', 'island', 'median', 'sidewalk-turn'],
|
|
);
|
|
|
|
const diagnostics = standardsDiagnostics(structure);
|
|
assert.equal(diagnostics.length, 2);
|
|
assert.equal(diagnostics[0].severity, 'pass');
|
|
assert.equal(diagnostics[1].severity, 'warning');
|
|
assert.equal(diagnostics[1].objectKey, 'road-arm:road:east');
|
|
|
|
console.log('junction projection tests passed');
|