fix(junction): align complex boundary trims
This commit is contained in:
1 parent
a12e2ac823
commit
4de971ce68
5 files changed
+125
-24
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
const fs = require('fs');
|
||||
const { structureFromTopology } = require('./junction-topology');
|
||||
const { resolveJunctionBuildPlan } = require('./junction-build-plan');
|
||||
const { resolveJunctionBuildPlan, stationAtDistanceFrom } = require('./junction-build-plan');
|
||||
const { convertGeoJson, boundsOf } = require('../reference/gaode');
|
||||
const metricsCache = new WeakMap();
|
||||
const CORNER_FILLET_SEGMENTS = 12;
|
||||
@@ -784,9 +784,8 @@ function positiveHeadingDelta(first, second) {
|
||||
return (((second - first) % 360) + 360) % 360;
|
||||
}
|
||||
function pointOnCarriagewayRadius(item, center, radius, helpers) {
|
||||
const start = item.approach.line[0];
|
||||
const startRadius = directionalProjectionMeters(center, start, item.heading);
|
||||
return helpers.pointAlongLine(item.approach.line, Math.max(0, Math.min(item.length, radius - startRadius)));
|
||||
const station = stationAtDistanceFrom(item.approach.line, center, radius, helpers);
|
||||
return helpers.pointAlongLine(item.approach.line, Math.max(0, Math.min(item.length, station)));
|
||||
}
|
||||
function armEnvelopeAtRadius(arm, radius, center, helpers) {
|
||||
if (!arm.members.length) return null;
|
||||
|
||||
@@ -49,6 +49,40 @@ function boundaryAt(point, tangent, widthMeters) {
|
||||
};
|
||||
}
|
||||
|
||||
function interpolate(first, second, ratio) {
|
||||
return [first[0] + (second[0] - first[0]) * ratio, first[1] + (second[1] - first[1]) * ratio];
|
||||
}
|
||||
|
||||
// Return the first source-polyline station whose actual distance to `center`
|
||||
// reaches the requested boundary. This intentionally does not project a fixed
|
||||
// initial heading: curved approaches must terminate where their own geometry
|
||||
// meets the boundary.
|
||||
function stationAtDistanceFrom(line, center, radius, helpers) {
|
||||
if (!center || !Array.isArray(line) || line.length < 2 || !Number.isFinite(radius)) return 0;
|
||||
let station = 0;
|
||||
let previousDistance = helpers.distanceMeters(line[0], center);
|
||||
if (previousDistance >= radius) return 0;
|
||||
for (let index = 1; index < line.length; index += 1) {
|
||||
const start = line[index - 1];
|
||||
const end = line[index];
|
||||
const segmentLength = helpers.distanceMeters(start, end);
|
||||
const endDistance = helpers.distanceMeters(end, center);
|
||||
if (previousDistance < radius && endDistance >= radius) {
|
||||
let low = 0;
|
||||
let high = 1;
|
||||
for (let iteration = 0; iteration < 32; iteration += 1) {
|
||||
const middle = (low + high) / 2;
|
||||
if (helpers.distanceMeters(interpolate(start, end, middle), center) < radius) low = middle;
|
||||
else high = middle;
|
||||
}
|
||||
return station + segmentLength * ((low + high) / 2);
|
||||
}
|
||||
station += segmentLength;
|
||||
previousDistance = endDistance;
|
||||
}
|
||||
return station;
|
||||
}
|
||||
|
||||
function entrySectionFor(item, helpers) {
|
||||
const length = item.length;
|
||||
const line = item.approach.line;
|
||||
@@ -148,4 +182,4 @@ function resolveJunctionBuildPlan(model, cluster, helpers) {
|
||||
return { schema: 'junction-build-plan/v1', cluster, nodeIds: [...nodeIds].sort(), carriageways, arms };
|
||||
}
|
||||
|
||||
module.exports = { MIN_ENTRY_SECTION_METERS, resolveJunctionBuildPlan };
|
||||
module.exports = { MIN_ENTRY_SECTION_METERS, resolveJunctionBuildPlan, stationAtDistanceFrom };
|
||||
+63
-18
@@ -8,6 +8,7 @@ const {
|
||||
complexJunctionMetrics,
|
||||
resolveComplexJunctionTopology,
|
||||
} = require('./complex-junction');
|
||||
const { stationAtDistanceFrom } = require('./junction-build-plan');
|
||||
const { diagnostic } = require('./diagnostics');
|
||||
// Default marking placement lives with the constraint bounds in the solver, which
|
||||
// is the IO-free module; importing the other way would drag fs into it.
|
||||
@@ -783,12 +784,21 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
|
||||
if (generated.islands) generatedComplexSidewalks.push(...generated.islands);
|
||||
diagnostics.push(...generated.diagnostics);
|
||||
}
|
||||
const lanes = compileLaneCenterlines(model, diagnostics, junctionPlans, options, {
|
||||
crosswalks: generatedComplexCrosswalks,
|
||||
stopLines: generatedComplexStopLines,
|
||||
});
|
||||
const lanes = compileLaneCenterlines(
|
||||
model,
|
||||
diagnostics,
|
||||
junctionPlans,
|
||||
options,
|
||||
{
|
||||
crosswalks: generatedComplexCrosswalks,
|
||||
stopLines: generatedComplexStopLines,
|
||||
},
|
||||
complexApproachBoundaries,
|
||||
);
|
||||
const edgeLines =
|
||||
options.edgeLines === false ? [] : compileEdgeLines(model, overrides, junctionPlans, options, features);
|
||||
options.edgeLines === false
|
||||
? []
|
||||
: compileEdgeLines(model, overrides, junctionPlans, options, features, complexApproachBoundaries);
|
||||
const controls = compileControlMarkings(
|
||||
model,
|
||||
lanes,
|
||||
@@ -800,13 +810,21 @@ function compileGeometry(model, overrides = { overrides: [] }, options = {}) {
|
||||
crosswalks: [...controls.crosswalks, ...generatedComplexCrosswalks],
|
||||
stopLines: [...controls.stopLines, ...generatedComplexStopLines],
|
||||
};
|
||||
const centerLines = compileCenterLines(model, overrides, junctionPlans, allControls, diagnostics, options);
|
||||
const centerLines = compileCenterLines(
|
||||
model,
|
||||
overrides,
|
||||
junctionPlans,
|
||||
allControls,
|
||||
diagnostics,
|
||||
options,
|
||||
complexApproachBoundaries,
|
||||
);
|
||||
const markings = compileLaneMarkings(model, overrides, lanes, diagnostics, junctionPlans, allControls, options);
|
||||
markings.separators.push(
|
||||
...compileComplexLaneSeparators(lanes.features, [...allControls.crosswalks, ...allControls.stopLines]),
|
||||
);
|
||||
markings.directionArrows.push(...compileComplexPreviewArrows(lanes.features, generatedComplexStopLines));
|
||||
const sidewalks = compileSidewalkSurfaces(model, diagnostics, junctionPlans, options);
|
||||
const sidewalks = compileSidewalkSurfaces(model, diagnostics, junctionPlans, options, complexApproachBoundaries);
|
||||
// Complex crosswalks are generated from native approach tangents; do not
|
||||
// synthesize side strips that can be mistaken for crosswalks.
|
||||
sidewalks.push(...generatedComplexSidewalks);
|
||||
@@ -1068,7 +1086,14 @@ function laneWasClipped(original, visible) {
|
||||
return Boolean(visible) && lineLengthMeters(visible) < lineLengthMeters(original) - 0.01;
|
||||
}
|
||||
|
||||
function compileEdgeLines(model, overrides, junctionPlans, options = {}, roadSurfaces = []) {
|
||||
function compileEdgeLines(
|
||||
model,
|
||||
overrides,
|
||||
junctionPlans,
|
||||
options = {},
|
||||
roadSurfaces = [],
|
||||
complexBoundaries = new Map(),
|
||||
) {
|
||||
const features = [];
|
||||
const clusters = options.junctionTemplates?.enabled ? options.junctionTemplates.clusters || [] : [];
|
||||
const clusterByNode = new Map(
|
||||
@@ -1104,6 +1129,7 @@ function compileEdgeLines(model, overrides, junctionPlans, options = {}, roadSur
|
||||
junctionPlans,
|
||||
cluster,
|
||||
clusterCenters.get(cluster.id),
|
||||
complexBoundaries.get(cluster.id)?.get(road.id),
|
||||
)
|
||||
: trimLineAtJunctions(road.centerline, road.sourceNodeIds, junctionPlans);
|
||||
// On a two-way segment, the inner edge is the road centre boundary and is
|
||||
@@ -1155,7 +1181,15 @@ function edgeLineFeature(road, side, style, ring, part = null) {
|
||||
};
|
||||
}
|
||||
|
||||
function compileCenterLines(model, overrides, junctionPlans, controls, diagnostics, options = {}) {
|
||||
function compileCenterLines(
|
||||
model,
|
||||
overrides,
|
||||
junctionPlans,
|
||||
controls,
|
||||
diagnostics,
|
||||
options = {},
|
||||
complexBoundaries = new Map(),
|
||||
) {
|
||||
const features = [];
|
||||
const controlFeatures = [...controls.crosswalks, ...controls.stopLines];
|
||||
const segments = new Map();
|
||||
@@ -1177,6 +1211,7 @@ function compileCenterLines(model, overrides, junctionPlans, controls, diagnosti
|
||||
junctionPlans,
|
||||
cluster,
|
||||
clusterCenter(cluster, junctionPlans),
|
||||
complexBoundaries.get(cluster.id)?.get(forward.id),
|
||||
)
|
||||
: trimLineAtJunctions(forward.centerline, forward.sourceNodeIds, junctionPlans);
|
||||
const length = lineLengthMeters(line);
|
||||
@@ -1827,7 +1862,7 @@ function ringsOverlap(first, second) {
|
||||
);
|
||||
}
|
||||
|
||||
function compileSidewalkSurfaces(model, diagnostics, junctionPlans, options = {}) {
|
||||
function compileSidewalkSurfaces(model, diagnostics, junctionPlans, options = {}, complexBoundaries = new Map()) {
|
||||
const features = [];
|
||||
const byWay = new Map();
|
||||
for (const road of model.roads) {
|
||||
@@ -1850,7 +1885,14 @@ function compileSidewalkSurfaces(model, diagnostics, junctionPlans, options = {}
|
||||
const sidewalkWidth = profile?.sidewalkWidths?.[side] ?? DEFAULT_SIDEWALK_WIDTH_METERS;
|
||||
if (!enabled || sidewalkWidth <= 0) continue;
|
||||
const centerline = cluster
|
||||
? trimLineAtComplexCluster(forward.centerline, forward.sourceNodeIds, junctionPlans, cluster, center)
|
||||
? trimLineAtComplexCluster(
|
||||
forward.centerline,
|
||||
forward.sourceNodeIds,
|
||||
junctionPlans,
|
||||
cluster,
|
||||
center,
|
||||
complexBoundaries.get(cluster.id)?.get(forward.id),
|
||||
)
|
||||
: trimLineAtJunctions(forward.centerline, forward.sourceNodeIds, junctionPlans);
|
||||
const ring = sidewalkRing(centerline, totalWidth / 2, totalWidth / 2 + sidewalkWidth, side === 'left' ? 1 : -1);
|
||||
if (!ring) {
|
||||
@@ -2088,7 +2130,14 @@ function pointOnSegment(point, a, b) {
|
||||
// templates already emitted. Ordinary controls cannot be passed here: they are
|
||||
// placed *from* these lane centerlines, so only the template-generated ones
|
||||
// exist this early.
|
||||
function compileLaneCenterlines(model, diagnostics, junctionPlans, options = {}, complexControls = {}) {
|
||||
function compileLaneCenterlines(
|
||||
model,
|
||||
diagnostics,
|
||||
junctionPlans,
|
||||
options = {},
|
||||
complexControls = {},
|
||||
complexBoundaries = new Map(),
|
||||
) {
|
||||
const features = [];
|
||||
const controlFeatures = [...(complexControls.crosswalks || []), ...(complexControls.stopLines || [])];
|
||||
const byRoadId = new Map();
|
||||
@@ -2115,6 +2164,7 @@ function compileLaneCenterlines(model, diagnostics, junctionPlans, options = {},
|
||||
junctionPlans,
|
||||
boundaryCluster,
|
||||
clusterCenters.get(boundaryCluster.id),
|
||||
complexBoundaries.get(boundaryCluster.id)?.get(road.id),
|
||||
)
|
||||
: trimLineAtJunctions(road.centerline, road.sourceNodeIds, junctionPlans);
|
||||
// OSM centerline is the shared carriageway center. On a two-way road,
|
||||
@@ -3237,12 +3287,7 @@ function complexApproachBoundaryRadii(model, clusters, junctionPlans) {
|
||||
}
|
||||
|
||||
function distanceAlongLineToRadius(line, center, radius) {
|
||||
if (!center || line.length < 2) return 0;
|
||||
const heading = headingAtEndpoint(line);
|
||||
const vector = project(line[0], center);
|
||||
const radians = (heading * Math.PI) / 180;
|
||||
const startRadius = vector[0] * Math.sin(radians) + vector[1] * Math.cos(radians);
|
||||
return Math.max(0, radius - startRadius);
|
||||
return stationAtDistanceFrom(line, center, radius, { distanceMeters });
|
||||
}
|
||||
|
||||
function trimLineRange(line, startCutback, endCutback) {
|
||||
|
||||
Reference in new issue
Block a user