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
@@ -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 };
|
||||
Reference in new issue
Block a user