fix: preserve exclusions in complex junction pavement

This commit is contained in:
que01 committed 2026-09-17 11:14:43 +08:00
1 parent e8ecfecbf4
commit 818d91d8b5
15 files changed
+606 -37

No files matched your search

+94
View File
@@ -4,6 +4,15 @@ const assert = require('assert/strict');
const fs = require('fs');
const clipping = require('polygon-clipping');
const { compileRoadModel, compileGeometry } = require('../src/compile/native-road');
const { solveComplexPavementRegion, segmentCoveredByPolygon } = require('../src/compile/junction-pavement-region');
const rectangle = (x1, y1, x2, y2) => [
[x1, y1],
[x2, y1],
[x2, y2],
[x1, y2],
[x1, y1],
];
const ringArea = (ring) =>
Math.abs(
@@ -90,4 +99,89 @@ for (const [name, nodeIds] of Object.entries({
);
assert.ok(edited.roadSurface.features.some((feature) => feature.properties.kind === 'complex-corner-fillet'));
}
// Construction gaps are filled; explicit exclusions are subtracted afterwards,
// including when a crossing footprint originally covers the same obstacle.
{
const parts = [rectangle(0, 0, 10, 2), rectangle(0, 8, 10, 10), rectangle(0, 0, 2, 10), rectangle(8, 0, 10, 10)];
assert.equal(multiArea(solveComplexPavementRegion(parts).regions), 100);
const holes = [rectangle(3, 3, 4, 4), rectangle(6, 6, 7, 7)];
const result = solveComplexPavementRegion(parts, [rectangle(2, 2, 8, 8)], holes);
assert.equal(result.status, 'supported');
assert.equal(result.regions[0].length, 3);
assert.equal(multiArea(result.regions), 98);
const overlapping = solveComplexPavementRegion(parts, [], [holes[0], rectangle(3.5, 3, 4.5, 4)]);
assert.equal(multiArea(overlapping.regions), 98.5);
assert.equal(solveComplexPavementRegion(parts, [], [rectangle(-1, -1, 11, 11)]).status, 'empty');
assert.equal(solveComplexPavementRegion(parts, [], [rectangle(4, -1, 6, 11)]).status, 'disconnected');
const notch = solveComplexPavementRegion(parts, [], [rectangle(4, -1, 6, 1)]);
assert.equal(notch.status, 'supported');
assert.equal(multiArea(notch.regions), 98);
assert.equal(
segmentCoveredByPolygon([2, 3.5], [8, 3.5], result.regions[0]),
false,
'interior hole must break seam coverage',
);
assert.equal(segmentCoveredByPolygon([0, 0], [10, 0], result.regions[0]), true);
assert.equal(
segmentCoveredByPolygon([0, 0], [10, 0], notch.regions[0]),
false,
'interior notch must break full seam coverage',
);
}
// Measure final published OSM pavement in local metres, independently of the
// construction solver. Core holes alone did not catch the original defect.
{
const cluster = {
id: 'exclusion-pavement',
template: 'complex-junction-v1',
coreRadiusMeters: 21,
nodeIds: ['8005332807', '8024512135', '8024512145', '8024512147'],
};
const options = { junctionTemplates: { enabled: true, clusters: [cluster] } };
const compile = (exclusionRegions = []) =>
compileGeometry({ ...model, exclusionRegions }, { overrides: [] }, options);
const pavementOf = (geometry) =>
geometry.roadSurface.features.find((feature) => feature.properties.kind === 'complex-pavement-region');
const baseline = compile();
const origin = pavementOf(baseline).properties.center;
const scale = 111320 * Math.cos((origin[1] * Math.PI) / 180);
const ll = ([x, y]) => [origin[0] + x / scale, origin[1] + y / 111320];
const xy = ([x, y]) => [(x - origin[0]) * scale, (y - origin[1]) * 111320];
const mask = (id, bounds) => ({ id, isHole: true, ring: rectangle(...bounds).map(ll) });
for (const exclusions of [
[mask('one-square-metre', [-0.5, -0.5, 0.5, 0.5])],
[mask('first-hole', [-1.5, -0.5, -0.5, 0.5]), mask('second-hole', [0.5, -0.5, 1.5, 0.5])],
[mask('overlap-a', [-0.5, -0.5, 0.5, 0.5]), mask('overlap-b', [0, -0.5, 1, 0.5])],
]) {
const published = pavementOf(compile(exclusions));
assert.ok(published, 'safe interior exclusions must retain a canonical pavement');
assert.ok(published.geometry.coordinates[0].length > 1, 'canonical pavement must retain explicit holes');
const pavementMeters = published.geometry.coordinates.map((polygon) => polygon.map((ring) => ring.map(xy)));
for (const exclusion of exclusions)
assert.ok(
multiArea(clipping.intersection(pavementMeters, [[exclusion.ring.map(xy)]])) < 1e-6,
`${exclusion.id} must remain unpaved`,
);
}
const approach = baseline.roadSurface.features.find((feature) => feature.properties.kind === 'complex-approach');
for (const exclusion of [
mask('fully-covered', [-200, -200, 200, 200]),
mask('split-region', [-0.5, -100, 0.5, 100]),
{ id: 'blocked-entry', ring: approach.geometry.coordinates[0] },
]) {
const result = compile([exclusion]);
assert.equal(pavementOf(result), undefined, `${exclusion.id} must refuse unified publication`);
const diagnostic = result.diagnostics.find((entry) => entry.rule.startsWith('complex-junction-pavement-region-'));
assert.ok(diagnostic, `${exclusion.id} requires a pavement rejection diagnostic`);
assert.deepEqual(diagnostic.exclusion_region_ids, [exclusion.id]);
assert.equal(diagnostic.subjectId, `junction-cluster:${cluster.id}`);
assert.equal(
result.roadSurface.features.some((feature) => feature.properties.pavement_input),
false,
);
if (exclusion.id === 'blocked-entry')
assert.ok(diagnostic.carriageway_keys.length, 'omitted required entry must be identified');
}
}
console.log('junction pavement region tests passed');