129 lines
5.1 KiB
JavaScript
129 lines
5.1 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const compiler = require('../src');
|
|
|
|
assert.equal(typeof compiler.laneGeometry.laneCenterline, 'function');
|
|
assert.equal(typeof compiler.gaodeReference.convertGeoJson, 'function');
|
|
assert.equal(typeof compiler.turnLaneArrows.buildCustomTurnLaneArrows, 'function');
|
|
assert.equal(typeof compiler.complexJunction.buildComplexJunctionGeometry, 'function');
|
|
assert.equal(typeof compiler.complexJunction.classifyJunctionShape, 'function');
|
|
assert.equal(typeof compiler.junctionStructure.buildJunctionStructure, 'function');
|
|
assert.equal(typeof compiler.junctionStandards.validateStandardsProfile, 'function');
|
|
assert.equal(typeof compiler.junctionProjection.projectJunctionStructure, 'function');
|
|
const shapeHelpers = { distanceMeters: (a, b) => Math.hypot(a[0] - b[0], a[1] - b[1]) };
|
|
const arm = (heading, distance = 20) => ({
|
|
heading,
|
|
members: [
|
|
{
|
|
approach: {
|
|
line: [
|
|
[0, 0],
|
|
[0, distance],
|
|
],
|
|
},
|
|
},
|
|
],
|
|
});
|
|
assert.equal(
|
|
compiler.complexJunction.classifyJunctionShape([arm(0), arm(90), arm(180), arm(270)], [0, 0], shapeHelpers).kind,
|
|
'cross',
|
|
);
|
|
assert.equal(
|
|
compiler.complexJunction.classifyJunctionShape([arm(0), arm(120), arm(180)], [0, 0], shapeHelpers).kind,
|
|
't-junction',
|
|
);
|
|
assert.equal(
|
|
compiler.complexJunction.classifyJunctionShape([arm(0), arm(80), arm(140)], [0, 0], shapeHelpers).kind,
|
|
'multi-arm',
|
|
);
|
|
assert.equal(
|
|
compiler.complexJunction.classifyJunctionShape([arm(0), arm(90), arm(180), arm(270)], [0, 0], shapeHelpers).label,
|
|
'4 臂十字路口',
|
|
);
|
|
assert.equal(
|
|
compiler.complexJunction.classifyJunctionShape([arm(0), arm(90)], [0, 0], shapeHelpers).kind,
|
|
'unsupported',
|
|
);
|
|
assert.equal(typeof compiler.nativeRoad.compileRoadModel, 'function');
|
|
assert.equal(typeof compiler.check.checkOutput, 'function');
|
|
assert.equal(typeof compiler.layerManifest.manifestForArea, 'function');
|
|
const manifest = compiler.layerManifest.manifestForArea('fixture');
|
|
assert.equal(manifest.contract, 'native-road-package/v1.1');
|
|
assert.equal(manifest.layers.length, 12);
|
|
assert.deepEqual(
|
|
manifest.layers.filter((layer) => layer.role === 'semantic').map((layer) => layer.source),
|
|
['lane_centerlines', 'connectors'],
|
|
);
|
|
assert.equal(manifest.layers.find((layer) => layer.source === 'center_lines').splitBy.cases[0].match, 'white');
|
|
const fixture = path.join(__dirname, 'fixtures', 'fengshu-er-road.osm');
|
|
assert.ok(fs.existsSync(fixture));
|
|
assert.throws(() => compiler.compiler.validateInput({ id: 'area' }), /RoadCompilerInput/);
|
|
const model = compiler.nativeRoad.compileRoadModel(fs.readFileSync(fixture, 'utf8'), {
|
|
schema: 'native-road-overrides/v1',
|
|
overrides: [],
|
|
});
|
|
assert.equal(model.roads.length, 24);
|
|
const islandModel = compiler.nativeRoad.compileRoadModel(
|
|
`<osm>
|
|
<node id="1" lon="120" lat="30"/><node id="2" lon="120.0001" lat="30"/>
|
|
<node id="3" lon="120.0001" lat="30.0001"/><node id="4" lon="120" lat="30.0001"/>
|
|
<way id="island"><nd ref="1"/><nd ref="2"/><nd ref="3"/><nd ref="4"/><nd ref="1"/><tag k="highway" v="traffic_island"/></way>
|
|
</osm>`,
|
|
{ schema: 'native-road-overrides/v1', overrides: [] },
|
|
);
|
|
assert.deepEqual(
|
|
islandModel.exclusionRegions.map((region) => [region.id, region.source]),
|
|
[['island', 'osm-traffic-island']],
|
|
);
|
|
const complexModel = compiler.nativeRoad.compileRoadModel(fs.readFileSync(fixture, 'utf8'), {
|
|
schema: 'native-road-overrides/v1',
|
|
overrides: [],
|
|
});
|
|
const complexGeometry = compiler.nativeRoad.compileGeometry(
|
|
complexModel,
|
|
{ schema: 'native-road-overrides/v1', overrides: [] },
|
|
{
|
|
edgeLines: false,
|
|
junctionTemplates: {
|
|
enabled: true,
|
|
clusters: [
|
|
{
|
|
id: 'fixture-five-arm',
|
|
template: 'complex-junction-v1',
|
|
nodeIds: ['8005332807', '8024512135', '8024512145', '8024512147', '8613058676'],
|
|
coreRadiusMeters: 24,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
);
|
|
const complexCore = complexGeometry.roadSurface.features.find(
|
|
(feature) => feature.properties?.kind === 'complex-core' && feature.properties?.cluster_id === 'fixture-five-arm',
|
|
);
|
|
// This fixture contains multiple source carriageways within several arms. The
|
|
// compiler must retain those independent sections rather than filling their
|
|
// unknown interstitial areas with a synthetic core.
|
|
assert.equal(complexCore, undefined);
|
|
assert.ok(
|
|
complexGeometry.diagnostics.some(
|
|
(item) =>
|
|
item.rule === 'complex-junction-core-closure-unsupported' &&
|
|
item.subjectId === 'junction-cluster:fixture-five-arm',
|
|
),
|
|
);
|
|
assert.ok(complexGeometry.roadSurface.features.some((feature) => feature.properties?.kind === 'complex-approach'));
|
|
const complexFeatures = Object.values(complexGeometry).flatMap((layer) => layer?.features || []);
|
|
assert.equal(
|
|
complexFeatures.some((feature) => feature.properties?.kind === 'complex-corner-island'),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
complexFeatures.some((feature) => feature.properties?.kind === 'complex-corner-crosswalk'),
|
|
false,
|
|
);
|
|
assert.ok(complexGeometry.diagnostics.some((item) => item.rule === 'complex-junction-corner-facilities-omitted'));
|
|
console.log('road compiler package tests passed');
|