fix complex junction island geometry
This commit is contained in:
1 parent
c3579074fd
commit
0c42eb46cd
19 files changed
+424
-44
No files matched your search
@@ -257,6 +257,7 @@ test.describe('workbench editing shell', () => {
|
||||
'cluster-carriageway-direction',
|
||||
'cluster-carriageway-edge-offset',
|
||||
'cluster-corner-radius',
|
||||
'cluster-island-offset',
|
||||
'cluster-crossing-inset',
|
||||
'cluster-stop-line-offset',
|
||||
].includes(handle.kind) && handle.editable,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert/strict');
|
||||
const clipping = require('polygon-clipping');
|
||||
const { buildPedestrianIsland, validateFacilityComposition } = require('../src/compile/junction-facility-composition');
|
||||
|
||||
const ring = [
|
||||
@@ -24,7 +25,6 @@ console.log('junction facility composition tests passed');
|
||||
// User's sketch: a horizontal crossing to the right, a vertical crossing down,
|
||||
// and the island in the upper-left quadrant, bounded by doubled short edges.
|
||||
const { buildIslandFromCrossingEdges } = require('../src/compile/junction-facility-composition');
|
||||
const clipping = require('polygon-clipping');
|
||||
const sketchIsland = buildIslandFromCrossingEdges([0, 0], [0, 6.8], [-6.8, 0]);
|
||||
assert.deepEqual(sketchIsland[0], sketchIsland.at(-1));
|
||||
assert.ok(sketchIsland.every(([x, y]) => x <= 0 && y >= 0));
|
||||
@@ -167,6 +167,7 @@ assert.equal(extendedContacts.status, 'solved');
|
||||
assert.ok(extendedContacts.legLengths.every((value) => value >= 9));
|
||||
|
||||
assert.equal(new Set(solvedContacts.greenRing.slice(0, -1).map((p) => p.join(','))).size, 6);
|
||||
assert.equal(clipping.difference([solvedContacts.greenRing], [solvedContacts.ring]).length, 0);
|
||||
|
||||
// Regression: the saved four-node, 21m cluster previously lost two islands.
|
||||
{
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert/strict');
|
||||
const { radialShift } = require('../src/compile/junction-island-offset');
|
||||
|
||||
const center = [114, 30];
|
||||
const islandCenter = [114.0001, 30.0001];
|
||||
const shift = radialShift(center, islandCenter, 2);
|
||||
assert.ok(Math.hypot(shift[0] * 111320 * Math.cos((center[1] * Math.PI) / 180), shift[1] * 111320) > 1.99);
|
||||
|
||||
// Real four-arm integration: the compiler receives one cluster value but moves
|
||||
// all four islands and their linked arm crossings in the same compilation pass.
|
||||
{
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { compileRoadModel, compileGeometry } = require('../src/compile/native-road');
|
||||
const cluster = {
|
||||
id: 'offset-four-arm',
|
||||
template: 'complex-junction-v1',
|
||||
coreRadiusMeters: 21,
|
||||
nodeIds: ['8005332807', '8024512135', '8024512145', '8024512147'],
|
||||
};
|
||||
const model = compileRoadModel(fs.readFileSync(path.join(__dirname, '../inputs/osm/枫树二路.osm'), 'utf8'), {
|
||||
overrides: [],
|
||||
});
|
||||
const options = { edgeLines: false, junctionTemplates: { enabled: true, clusters: [cluster] } };
|
||||
const base = compileGeometry(model, { overrides: [] }, options);
|
||||
const shifted = compileGeometry(
|
||||
model,
|
||||
{ overrides: [] },
|
||||
{
|
||||
...options,
|
||||
directEdit: { clusterIslandOffsets: new Map([[cluster.id, 2]]) },
|
||||
},
|
||||
);
|
||||
const byKind = (geometry, kind) =>
|
||||
geometry.sidewalkSurface.features.filter((feature) => feature.properties.kind === kind);
|
||||
const baseIslands = byKind(base, 'island');
|
||||
const shiftedIslands = byKind(shifted, 'island');
|
||||
assert.equal(baseIslands.length, 4);
|
||||
assert.equal(shiftedIslands.length, 4);
|
||||
for (const island of shiftedIslands) {
|
||||
const original = baseIslands.find((feature) => feature.properties.corner_key === island.properties.corner_key);
|
||||
assert.notDeepEqual(island.geometry.coordinates, original.geometry.coordinates, 'each island must move');
|
||||
}
|
||||
const baseCrosswalks = base.crosswalks.features.filter((feature) => feature.properties.kind === 'complex-crosswalk');
|
||||
const shiftedCrosswalks = shifted.crosswalks.features.filter(
|
||||
(feature) => feature.properties.kind === 'complex-crosswalk',
|
||||
);
|
||||
assert.equal(shiftedCrosswalks.length, baseCrosswalks.length);
|
||||
assert.ok(
|
||||
shiftedCrosswalks.some(
|
||||
(feature, index) =>
|
||||
JSON.stringify(feature.geometry.coordinates) !== JSON.stringify(baseCrosswalks[index].geometry.coordinates),
|
||||
),
|
||||
'linked arm crossings must be rebuilt with the islands',
|
||||
);
|
||||
const baseStops = base.vehicleStopLines.features.filter((feature) => feature.properties.kind === 'complex-stop-line');
|
||||
const shiftedStops = shifted.vehicleStopLines.features.filter(
|
||||
(feature) => feature.properties.kind === 'complex-stop-line',
|
||||
);
|
||||
assert.ok(
|
||||
shiftedStops.some(
|
||||
(feature, index) =>
|
||||
JSON.stringify(feature.geometry.coordinates) !== JSON.stringify(baseStops[index].geometry.coordinates),
|
||||
),
|
||||
'stop lines must retain their spacing from moved arm crossings',
|
||||
);
|
||||
const allStripeVertices = shifted.crosswalks.features.flatMap((feature) => feature.geometry.coordinates[0]);
|
||||
const metersBetween = (a, b) =>
|
||||
Math.hypot((a[0] - b[0]) * 111320 * Math.cos((a[1] * Math.PI) / 180), (a[1] - b[1]) * 111320);
|
||||
for (const green of byKind(shifted, 'island-green')) {
|
||||
for (const contactPoint of green.geometry.coordinates[0].slice(0, -1))
|
||||
assert.ok(
|
||||
Math.min(...allStripeVertices.map((vertex) => metersBetween(contactPoint, vertex))) < 0.01,
|
||||
'each green contact endpoint must remain on a linked crossing after the offset',
|
||||
);
|
||||
}
|
||||
const local = (point) => [
|
||||
(point[0] - 114.1229) * 111320 * Math.cos((point[1] * Math.PI) / 180),
|
||||
(point[1] - 30.4629) * 111320,
|
||||
];
|
||||
const cross = (a, b, c) => (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
|
||||
const properIntersection = (a, b, c, d) => {
|
||||
const ab = cross(a, b, c) * cross(a, b, d);
|
||||
const cd = cross(c, d, a) * cross(c, d, b);
|
||||
return ab < -1e-8 && cd < -1e-8;
|
||||
};
|
||||
const islandEdges = shiftedIslands.flatMap((island) =>
|
||||
island.geometry.coordinates[0]
|
||||
.slice(1)
|
||||
.map((point, index) => [local(island.geometry.coordinates[0][index]), local(point)]),
|
||||
);
|
||||
const laneSegments = shifted.laneCenterlines.features.flatMap((feature) => {
|
||||
const coordinates = feature.geometry.type === 'LineString' ? feature.geometry.coordinates : [];
|
||||
return coordinates.slice(1).map((point, index) => [local(coordinates[index]), local(point)]);
|
||||
});
|
||||
assert.equal(
|
||||
laneSegments.some(([a, b]) => islandEdges.some(([c, d]) => properIntersection(a, b, c, d))),
|
||||
false,
|
||||
'the shifted island boundary must stay outside vehicle lane centre lines',
|
||||
);
|
||||
}
|
||||
console.log('junction island offset tests passed');
|
||||
@@ -64,4 +64,30 @@ for (const [name, nodeIds] of Object.entries({
|
||||
`${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');
|
||||
@@ -78,6 +78,8 @@ function valueFor(kind) {
|
||||
return { leftOffsetMeters: 0.5, rightOffsetMeters: 0 };
|
||||
case 'cluster-corner-radius':
|
||||
return { radiusMeters: 6 };
|
||||
case 'cluster-island-offset':
|
||||
return { offsetMeters: 2 };
|
||||
case 'cluster-crossing-inset':
|
||||
return { insetMeters: 1.5 };
|
||||
case 'cluster-stop-line-offset':
|
||||
@@ -149,6 +151,7 @@ assert.deepEqual(CONSTRAINT_KINDS, [
|
||||
'cluster-carriageway-direction',
|
||||
'cluster-carriageway-edge-offset',
|
||||
'cluster-corner-radius',
|
||||
'cluster-island-offset',
|
||||
'cluster-crossing-inset',
|
||||
'cluster-stop-line-offset',
|
||||
'junction-cutback',
|
||||
|
||||
@@ -342,6 +342,7 @@ assert.ok(
|
||||
'cluster-carriageway-direction',
|
||||
'cluster-carriageway-edge-offset',
|
||||
'cluster-corner-radius',
|
||||
'cluster-island-offset',
|
||||
'cluster-crossing-inset',
|
||||
'cluster-stop-line-offset',
|
||||
].includes(handle.kind),
|
||||
|
||||
Reference in new issue
Block a user