fix: publish unified complex junction pavement
This commit is contained in:
1 parent
787faa7604
commit
8882754b23
5 files changed
+155
-1
No files matched your search
+1
-1
@@ -8,7 +8,7 @@
|
||||
"road-compiler": "bin/road-compiler.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/index.js && node test/junction-structure.js && node test/connector-trajectories.js && node test/junction-projection.js && node test/junction-build-plan-counterexamples.js && node test/junction-polygon-ops.js && node test/junction-region-solver.js && node test/junction-facility-composition.js && node test/junction-marking-containment.js && node test/native-road-edits.js && node test/road-revisions.js && node test/direct-edit-solver.js && node test/workbench-edit-api.js && node test/workbench-import-compile.js && node test/fixtures.js",
|
||||
"test": "node test/index.js && node test/junction-structure.js && node test/connector-trajectories.js && node test/junction-projection.js && node test/junction-build-plan-counterexamples.js && node test/junction-polygon-ops.js && node test/junction-region-solver.js && node test/junction-facility-composition.js && node test/junction-pavement-region.js && node test/junction-marking-containment.js && node test/native-road-edits.js && node test/road-revisions.js && node test/direct-edit-solver.js && node test/workbench-edit-api.js && node test/workbench-import-compile.js && node test/fixtures.js",
|
||||
"test:fixtures:update-baseline": "node test/update-fixture-baselines.js",
|
||||
"road:workbench": "node bin/road-workbench.js",
|
||||
"road:export": "node bin/road-compiler.js",
|
||||
|
||||
@@ -5,6 +5,7 @@ const { COMPLEX_CROSSWALK_DEPTH_METERS } = require('./junction-metrics');
|
||||
const { structureFromTopology } = require('./junction-topology');
|
||||
const { resolveJunctionBuildPlan, stationAtDistanceFrom } = require('./junction-build-plan');
|
||||
const { buildJunctionBoundaryGraph, buildCoreClosure, ringsOverlap } = require('./junction-boundary-graph');
|
||||
const { solveComplexPavementRegion, rectangle, connectCornerCrossing } = require('./junction-pavement-region');
|
||||
const {
|
||||
buildIslandFromCrossingEdges,
|
||||
orthogonalCrossingHeadings,
|
||||
@@ -84,6 +85,8 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
const boundaryParts = [];
|
||||
const transitionDiagnostics = [];
|
||||
const crosswalks = [];
|
||||
const crossingRegions = [];
|
||||
const cornerCrossingFrames = [];
|
||||
const stopLines = [];
|
||||
const islands = [];
|
||||
const crossingControls = helpers.clusterCrossingControls || new Map();
|
||||
@@ -340,6 +343,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
arm.crosswalkFrame.endpoints = endpoints;
|
||||
arm.crosswalkFrame.spanMeters = usableSpan;
|
||||
arm.crosswalkFrame.roadEdgeInsetMeters = roadEdgeInset;
|
||||
crossingRegions.push(rectangle(arm.crosswalkFrame.center, crossingHeading, groupDepth, usableSpan));
|
||||
for (let stripe = 0; stripe < stripeCount; stripe += 1) {
|
||||
const along = layout.centers[stripe];
|
||||
const centerPoint = helpers.offsetCoordinate(endpoints[0], bearing(...endpoints), along);
|
||||
@@ -606,6 +610,12 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
const diagonalHeading = outwardHeading;
|
||||
const diagonalCenter = helpers.offsetCoordinate(outerMidpoint, outwardHeading, diagonalDepth / 2);
|
||||
const diagonalSpan = COMPLEX_CROSSWALK_DEPTH_METERS;
|
||||
cornerCrossingFrames.push({
|
||||
center: diagonalCenter,
|
||||
heading: diagonalHeading,
|
||||
depth: diagonalDepth,
|
||||
span: diagonalSpan,
|
||||
});
|
||||
const layout = stripeLayout(diagonalDepth);
|
||||
const stripeCount = layout.centers.length;
|
||||
const stripeSpacing = layout.pitch;
|
||||
@@ -811,6 +821,46 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
// they are smoothing; they never replace an OSM-derived road surface.
|
||||
features.push(...cornerFills);
|
||||
if (coreFeature) features.push(coreFeature);
|
||||
// Publish a single canonical pavement region last. The individual approach,
|
||||
// core and corner polygons above remain structural inputs for editing and
|
||||
// diagnostics; they are no longer the visible authority at the junction.
|
||||
const basePavement = features.map((feature) => feature.geometry.coordinates[0]);
|
||||
const connectedCrossings = [...crossingRegions];
|
||||
const connectors = [];
|
||||
for (const frame of cornerCrossingFrames) {
|
||||
const solved = connectCornerCrossing(basePavement, connectedCrossings, frame);
|
||||
connectedCrossings.push(solved.region);
|
||||
if (solved.connector) connectors.push(solved.connector);
|
||||
}
|
||||
const pavementRegion = solveComplexPavementRegion(basePavement, [...connectedCrossings, ...connectors]);
|
||||
if (pavementRegion.status === 'supported') {
|
||||
for (const feature of features) feature.properties.pavement_input = true;
|
||||
features.push({
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
native_id: `complex-junction:${cluster.id}:pavement-region`,
|
||||
cluster_id: cluster.id,
|
||||
kind: 'complex-pavement-region',
|
||||
complex_part: 'pavement-region',
|
||||
center,
|
||||
region_status: 'supported',
|
||||
region_input_count: pavementRegion.inputCount,
|
||||
crossing_connector_count: connectors.length,
|
||||
provenance: 'native-road-complex-junction-pavement-region/v1',
|
||||
},
|
||||
geometry: { type: 'MultiPolygon', coordinates: pavementRegion.regions },
|
||||
});
|
||||
} else
|
||||
cornerDiagnostics.push(
|
||||
helpers.diagnostic(
|
||||
'warning',
|
||||
`junction-cluster:${cluster.id}`,
|
||||
[...nodeIds],
|
||||
'complex-junction-pavement-region-disconnected',
|
||||
'过街与入口无法组成连续铺装区域,保留结构输入面并拒绝发布统一铺装面。',
|
||||
center,
|
||||
),
|
||||
);
|
||||
// `coreRadiusMeters` is only consulted when there is no reference geometry.
|
||||
// Under calibration the radius comes from the reference span, so a configured
|
||||
// value that silently does nothing has to be reported, not swallowed.
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
|
||||
const { union } = require('./junction-polygon-ops');
|
||||
|
||||
/**
|
||||
* The road layer has one authoritative complex-junction region. Construction
|
||||
* parts are inputs only; crossings contribute their complete rectangular
|
||||
* carriageway footprint rather than disconnected white stripes.
|
||||
*/
|
||||
function solveComplexPavementRegion(parts, crossingRegions = []) {
|
||||
const inputs = [...parts, ...crossingRegions].filter(
|
||||
(ring) => Array.isArray(ring) && ring.length >= 4 && ring.every((point) => point?.every(Number.isFinite)),
|
||||
);
|
||||
const regions = union(...inputs.map((ring) => [ring]));
|
||||
return {
|
||||
status: regions.length === 1 ? 'supported' : 'disconnected',
|
||||
regions,
|
||||
inputCount: inputs.length,
|
||||
};
|
||||
}
|
||||
|
||||
function offset(point, heading, meters) {
|
||||
const radians = (heading * Math.PI) / 180;
|
||||
const scale = 111320 * Math.cos((point[1] * Math.PI) / 180);
|
||||
return [point[0] + (Math.sin(radians) * meters) / scale, point[1] + (Math.cos(radians) * meters) / 111320];
|
||||
}
|
||||
|
||||
function rectangle(center, heading, depth, span) {
|
||||
const first = offset(offset(center, heading + 90, -span / 2), heading, -depth / 2);
|
||||
const second = offset(offset(center, heading + 90, span / 2), heading, -depth / 2);
|
||||
const third = offset(offset(center, heading + 90, span / 2), heading, depth / 2);
|
||||
const fourth = offset(offset(center, heading + 90, -span / 2), heading, depth / 2);
|
||||
return [first, second, third, fourth, first];
|
||||
}
|
||||
|
||||
// A corner crossing keeps its island landing fixed. When its carriageway-side
|
||||
// edge does not meet the main paved component, seek the shortest narrow
|
||||
// connector behind it. This is a region constraint, not a move of the zebra.
|
||||
function connectCornerCrossing(parts, crossingRegions, crossing) {
|
||||
const original = rectangle(crossing.center, crossing.heading, crossing.depth, crossing.span);
|
||||
const baseline = solveComplexPavementRegion(parts, [...crossingRegions, original]);
|
||||
if (baseline.status === 'supported') return { region: original, connector: null };
|
||||
for (let along = 0.5; along <= 10; along += 0.5) {
|
||||
for (const lateral of [0, -0.5, 0.5, -1, 1, -1.5, 1.5, -2, 2]) {
|
||||
const center = offset(offset(crossing.center, crossing.heading, -along / 2), crossing.heading + 90, lateral);
|
||||
const connector = rectangle(center, crossing.heading, crossing.depth + along + 0.5, crossing.span);
|
||||
const candidate = solveComplexPavementRegion(parts, [...crossingRegions, original, connector]);
|
||||
if (candidate.status === 'supported') return { region: original, connector };
|
||||
}
|
||||
}
|
||||
return { region: original, connector: null };
|
||||
}
|
||||
|
||||
module.exports = { solveComplexPavementRegion, rectangle, connectCornerCrossing };
|
||||
@@ -0,0 +1,49 @@
|
||||
'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'],
|
||||
})) {
|
||||
const geometry = compileGeometry(
|
||||
model,
|
||||
{ overrides: [] },
|
||||
{
|
||||
edgeLines: false,
|
||||
junctionTemplates: {
|
||||
enabled: true,
|
||||
clusters: [{ id: name, template: 'complex-junction-v1', coreRadiusMeters: 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(
|
||||
geometry.diagnostics.some((item) => item.rule === 'complex-junction-pavement-region-disconnected'),
|
||||
false,
|
||||
);
|
||||
for (const stripe of geometry.crosswalks.features.filter((feature) => feature.properties.cluster_id === name))
|
||||
assert.ok(
|
||||
multiArea(clipping.difference(stripe.geometry.coordinates, pavement.geometry.coordinates)) < 1e-10,
|
||||
`${name} ${stripe.properties.native_id} must lie on the unified pavement`,
|
||||
);
|
||||
}
|
||||
console.log('junction pavement region tests passed');
|
||||
@@ -412,6 +412,7 @@ function nativeSurfaceStyle(feature) {
|
||||
// Split road features meet at OSM junction nodes. Their per-feature outlines
|
||||
// are editing aids, not physical seams, so scene mode must render fills only.
|
||||
if (scenePreview) return new Style({ fill: new Fill({ color: '#3f4b50' }) });
|
||||
if (feature.get('pavement_input')) return null;
|
||||
if (feature.get('cluster_id') && feature.get('complex_part'))
|
||||
return new Style({ fill: new Fill({ color: '#6f948a' }) });
|
||||
if (feature.get('kind') === 'cluster')
|
||||
|
||||
Reference in new issue
Block a user