fix: fill junction core and connect cluster lane trajectories
This commit is contained in:
1 parent
695bf21a84
commit
6a8f026d12
12 files changed
+527
-83
No files matched your search
@@ -0,0 +1,122 @@
|
||||
'use strict';
|
||||
const assert = require('assert/strict');
|
||||
const fs = require('fs');
|
||||
const { compileRoadModel, compileGeometry } = require('../src/compile/native-road');
|
||||
|
||||
function vector(a, b) {
|
||||
return [(b[0] - a[0]) * Math.cos((a[1] * Math.PI) / 180), b[1] - a[1]];
|
||||
}
|
||||
function angle(a, b) {
|
||||
return (
|
||||
(Math.acos(Math.max(-1, Math.min(1, (a[0] * b[0] + a[1] * b[1]) / (Math.hypot(...a) * Math.hypot(...b))))) * 180) /
|
||||
Math.PI
|
||||
);
|
||||
}
|
||||
function check(geometry, label, clipped = false) {
|
||||
const lanes = new Map(
|
||||
geometry.laneCenterlines.features.map((f) => [
|
||||
f.properties.native_id,
|
||||
f.properties.cluster_preview && f.properties.incoming === false
|
||||
? [...f.geometry.coordinates].reverse()
|
||||
: f.geometry.coordinates,
|
||||
]),
|
||||
);
|
||||
let maximum = 0;
|
||||
let checked = 0;
|
||||
let unavailable = 0;
|
||||
for (const feature of geometry.connectors.features) {
|
||||
const line = feature.geometry.coordinates;
|
||||
const incoming = lanes.get(feature.properties.from_lane_id);
|
||||
const outgoing = lanes.get(feature.properties.to_lane_id);
|
||||
if (clipped && (!incoming || !outgoing)) {
|
||||
unavailable += 1;
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
clipped &&
|
||||
(JSON.stringify(line[0]) !== JSON.stringify(incoming.at(-1)) ||
|
||||
JSON.stringify(line.at(-1)) !== JSON.stringify(outgoing[0]))
|
||||
) {
|
||||
unavailable += 1;
|
||||
continue;
|
||||
}
|
||||
checked += 1;
|
||||
assert.deepEqual(line[0], incoming.at(-1));
|
||||
assert.deepEqual(line.at(-1), outgoing[0]);
|
||||
const error = Math.max(
|
||||
angle(vector(incoming.at(-2), incoming.at(-1)), vector(line[0], line[1])),
|
||||
angle(vector(outgoing[0], outgoing[1]), vector(line.at(-2), line.at(-1))),
|
||||
);
|
||||
maximum = Math.max(maximum, error);
|
||||
assert.ok(error <= 1.01, `${label} ${feature.properties.native_id}: tangent error ${error}`);
|
||||
assert.ok(line.every((p) => p.every(Number.isFinite)));
|
||||
}
|
||||
assert.ok(checked > 0);
|
||||
console.log(
|
||||
`${label}: ${checked} checked, ${unavailable} clipped/missing endpoint references, max tangent error ${maximum.toFixed(4)} deg`,
|
||||
);
|
||||
}
|
||||
// Oblique four-arm and T nodes exercise the former quadratic and straight
|
||||
// special cases using public compilation, not a duplicate curve implementation.
|
||||
for (const count of [3, 4]) {
|
||||
const coords = [
|
||||
[0, 0],
|
||||
[0, 0.001],
|
||||
[0.001, 0.0001],
|
||||
[0, -0.001],
|
||||
[-0.001, 0],
|
||||
];
|
||||
const osm = `<osm>${coords.map((p, i) => `<node id="${i}" lon="${p[0]}" lat="${p[1]}"/>`).join('')}${coords
|
||||
.slice(1, count + 1)
|
||||
.map(
|
||||
(_, i) =>
|
||||
`<way id="${i + 10}"><nd ref="0"/><nd ref="${i + 1}"/><tag k="highway" v="primary"/><tag k="lanes" v="4"/></way>`,
|
||||
)
|
||||
.join('')}</osm>`;
|
||||
check(compileGeometry(compileRoadModel(osm, { overrides: [] }), { overrides: [] }), `${count}-arm`);
|
||||
}
|
||||
if (process.argv[2]) {
|
||||
const root = process.argv[2];
|
||||
const overrides = JSON.parse(fs.readFileSync(`${root}/native-road-overrides.json`));
|
||||
const options = JSON.parse(fs.readFileSync(`${root}/active/area-config.snapshot.json`)).options;
|
||||
check(
|
||||
compileGeometry(compileRoadModel(fs.readFileSync(`${root}/source.osm`, 'utf8'), overrides), overrides, options),
|
||||
'saved workbench',
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
// The four-node configuration must publish whole cluster movements whose
|
||||
// endpoints refer to visible approach lanes, not invisible internal OSM lanes.
|
||||
{
|
||||
const model = compileRoadModel(
|
||||
fs.readFileSync(require('path').join(__dirname, '../inputs/osm/枫树二路.osm'), 'utf8'),
|
||||
{ overrides: [] },
|
||||
);
|
||||
const geometry = compileGeometry(
|
||||
model,
|
||||
{ overrides: [] },
|
||||
{
|
||||
edgeLines: false,
|
||||
junctionTemplates: {
|
||||
enabled: true,
|
||||
clusters: [
|
||||
{
|
||||
id: 'cluster-path-regression',
|
||||
template: 'complex-junction-v1',
|
||||
coreRadiusMeters: 21,
|
||||
nodeIds: ['8005332807', '8024512135', '8024512145', '8024512147'],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
);
|
||||
const paths = geometry.connectors.features.filter((f) => f.properties.cluster_id === 'cluster-path-regression');
|
||||
assert.ok(paths.length > 0);
|
||||
check({ ...geometry, connectors: { ...geometry.connectors, features: paths } }, 'whole cluster');
|
||||
for (const path of paths) {
|
||||
assert.equal(path.properties.cluster_internal, false);
|
||||
assert.ok(path.properties.source_movement_ids.length > 0);
|
||||
assert.ok(!path.properties.from_lane_id.includes('undefined'));
|
||||
}
|
||||
}
|
||||
+5
-11
@@ -113,17 +113,11 @@ const complexGeometry = compiler.nativeRoad.compileGeometry(
|
||||
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',
|
||||
),
|
||||
);
|
||||
// Every valid carriageway must participate in the continuous center region.
|
||||
assert.ok(complexCore);
|
||||
assert.equal(complexCore.properties.required_pavement_connected, true);
|
||||
assert.equal(complexCore.properties.shared_seam_error_m, 0);
|
||||
assert.equal(complexCore.properties.core_ring_self_intersects, false);
|
||||
assert.ok(complexGeometry.roadSurface.features.some((feature) => feature.properties?.kind === 'complex-approach'));
|
||||
const compiledApproach = complexGeometry.roadSurface.features.find(
|
||||
(feature) => feature.properties?.kind === 'complex-approach',
|
||||
|
||||
@@ -692,3 +692,22 @@ const editedCurvedGraph = buildJunctionBoundaryGraph(
|
||||
assert.deepEqual(editedCurvedGraph.sections[0].outer, originalCurvedGraph.sections[0].outer);
|
||||
assert.ok(Math.abs(editedCurvedGraph.sections[0].transitionMeters - 16) < 1e-9);
|
||||
assert.notDeepEqual(editedCurvedGraph.sections[0].inner, originalCurvedGraph.sections[0].inner);
|
||||
|
||||
// An internal seam must be covered along its full length, including between
|
||||
// sample positions. The narrow notch below would escape quarter-point probes.
|
||||
{
|
||||
const { segmentCoveredByRing } = require('../src/compile/junction-boundary-graph');
|
||||
const notch = [
|
||||
[0, 0],
|
||||
[1, 0],
|
||||
[1, 1],
|
||||
[0.15, 1],
|
||||
[0.15, 0.4],
|
||||
[0.1, 0.4],
|
||||
[0.1, 1],
|
||||
[0, 1],
|
||||
[0, 0],
|
||||
];
|
||||
assert.equal(segmentCoveredByRing([0, 0.5], [1, 0.5], notch), false);
|
||||
assert.equal(segmentCoveredByRing([0, 0], [1, 0], notch), true);
|
||||
}
|
||||
@@ -155,6 +155,12 @@ assert.equal(new Set(solvedContacts.greenRing.slice(0, -1).map((p) => p.join(','
|
||||
);
|
||||
const outer = geometry.sidewalkSurface.features.filter((f) => f.properties.kind === 'island');
|
||||
const green = geometry.sidewalkSurface.features.filter((f) => f.properties.kind === 'island-green');
|
||||
const core = geometry.roadSurface.features.find((f) => f.properties.kind === 'complex-core');
|
||||
assert.ok(core, 'saved four-node 21m configuration must publish center pavement');
|
||||
assert.equal(core.properties.connected_entry_count, 8);
|
||||
assert.equal(core.properties.required_pavement_connected, true);
|
||||
assert.equal(core.properties.shared_seam_error_m, 0);
|
||||
assert.equal(core.properties.core_ring_self_intersects, false);
|
||||
assert.equal(outer.length, 4, 'all four corners must publish islands');
|
||||
assert.equal(green.length, 4, 'all four islands must publish green contact polygons');
|
||||
assert.equal(new Set(green.map((f) => f.properties.corner_key)).size, 4);
|
||||
|
||||
Reference in new issue
Block a user