94 lines
3.7 KiB
JavaScript
94 lines
3.7 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert/strict');
|
|
const fs = require('fs');
|
|
const clipping = require('polygon-clipping');
|
|
const { compileRoadModel, compileGeometry } = require('../src/compile/native-road');
|
|
|
|
const ringArea = (ring) =>
|
|
Math.abs(
|
|
ring.slice(1).reduce((sum, point, index) => sum + ring[index][0] * point[1] - point[0] * ring[index][1], 0) / 2,
|
|
);
|
|
const multiArea = (multiPolygon) =>
|
|
multiPolygon.reduce(
|
|
(sum, polygon) => sum + ringArea(polygon[0]) - polygon.slice(1).reduce((holes, hole) => holes + ringArea(hole), 0),
|
|
0,
|
|
);
|
|
|
|
const model = compileRoadModel(fs.readFileSync('./inputs/osm/枫树二路.osm', 'utf8'), { overrides: [] });
|
|
for (const [name, nodeIds] of Object.entries({
|
|
cross: ['8005332807', '8024512135', '8024512145', '8024512147'],
|
|
tee: ['8005332807', '8024512135', '8024512145'],
|
|
dividedTee: ['1590698046', '6538106539'],
|
|
})) {
|
|
const geometry = compileGeometry(
|
|
model,
|
|
{ overrides: [] },
|
|
{
|
|
edgeLines: false,
|
|
junctionTemplates: {
|
|
enabled: true,
|
|
clusters: [
|
|
{
|
|
id: name,
|
|
template: 'complex-junction-v1',
|
|
coreRadiusMeters: name === 'dividedTee' ? 18 : 21,
|
|
nodeIds,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
);
|
|
const pavement = geometry.roadSurface.features.find(
|
|
(feature) => feature.properties.kind === 'complex-pavement-region',
|
|
);
|
|
assert.ok(pavement, `${name} must publish an authoritative pavement region`);
|
|
assert.equal(pavement.geometry.coordinates.length, 1, `${name} pavement must be one connected region`);
|
|
assert.equal(pavement.geometry.coordinates[0].length, 1, `${name} pavement must not expose internal holes`);
|
|
assert.equal(
|
|
geometry.diagnostics.some((item) => item.rule === 'complex-junction-pavement-region-disconnected'),
|
|
false,
|
|
);
|
|
if (name === 'dividedTee')
|
|
assert.ok(
|
|
geometry.roadSurface.features.some((feature) => feature.properties.kind === 'complex-core'),
|
|
'dividedTee must publish a closed complex core',
|
|
);
|
|
// The region owns road-arm crossings. The island-hypotenuse crossing is a
|
|
// pedestrian facility above the road layer and does not expand pavement.
|
|
for (const stripe of geometry.crosswalks.features.filter(
|
|
(feature) => feature.properties.cluster_id === name && feature.properties.kind === 'complex-crosswalk',
|
|
))
|
|
assert.ok(
|
|
multiArea(clipping.difference(stripe.geometry.coordinates, pavement.geometry.coordinates)) < 1e-10,
|
|
`${name} ${stripe.properties.native_id} must lie on the unified pavement`,
|
|
);
|
|
}
|
|
|
|
// A valid five-arm corner-radius edit used to let polygon-clipping throw while
|
|
// assembling connector pavement, aborting the entire preview. It must instead
|
|
// retain the changed structural pavement and defer only unverifiable routes.
|
|
{
|
|
const cluster = {
|
|
id: 'five-arm-pavement-assembly',
|
|
template: 'complex-junction-v1',
|
|
coreRadiusMeters: 32,
|
|
nodeIds: ['8005332807', '8024512135', '8024512145', '8024512147', '8613058676'],
|
|
};
|
|
const options = { edgeLines: false, junctionTemplates: { enabled: true, clusters: [cluster] } };
|
|
const baseline = compileGeometry(model, { overrides: [] }, options);
|
|
const cornerKeys = baseline.roadSurface.features
|
|
.filter((feature) => feature.properties.kind === 'complex-corner-fillet')
|
|
.map((feature) => feature.properties.corner_key);
|
|
const edited = compileGeometry(
|
|
model,
|
|
{ overrides: [] },
|
|
{
|
|
...options,
|
|
directEdit: { clusterCorners: new Map([[cluster.id, new Map(cornerKeys.map((key) => [key, 14]))]]) },
|
|
},
|
|
);
|
|
assert.ok(edited.roadSurface.features.some((feature) => feature.properties.kind === 'complex-corner-fillet'));
|
|
}
|
|
console.log('junction pavement region tests passed');
|