feat(junction): derive complex approach boundary sections
This commit is contained in:
1 parent
4de971ce68
commit
b4abfdb870
4 files changed
+138
-12
No files matched your search
@@ -3,6 +3,7 @@
|
||||
const fs = require('fs');
|
||||
const { structureFromTopology } = require('./junction-topology');
|
||||
const { resolveJunctionBuildPlan, stationAtDistanceFrom } = require('./junction-build-plan');
|
||||
const { buildJunctionBoundaryGraph } = require('./junction-boundary-graph');
|
||||
const { convertGeoJson, boundsOf } = require('../reference/gaode');
|
||||
const metricsCache = new WeakMap();
|
||||
const CORNER_FILLET_SEGMENTS = 12;
|
||||
@@ -83,15 +84,22 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
const crossingControls = helpers.clusterCrossingControls || new Map();
|
||||
const armCrosswalkRadiusFor = (arm) =>
|
||||
Math.max(1, coreRadius * 0.68 + (crossingControls.get(`crossing:${arm.key}`)?.crosswalkInsetMeters || 0));
|
||||
for (const item of carriageways) {
|
||||
const boundaryGraph = buildJunctionBoundaryGraph(
|
||||
topology,
|
||||
center,
|
||||
{
|
||||
outerRadiusFor: (item) => Math.max(coreRadius + 4, outerRadius - Math.max(0, Number(item.approach.cutback) || 0)),
|
||||
innerRadiusFor: () => coreRadius * 0.7,
|
||||
},
|
||||
helpers,
|
||||
);
|
||||
for (const section of boundaryGraph.sections) {
|
||||
const item = carriageways.find((candidate) => candidate.key === section.carriagewayKey);
|
||||
if (!item) continue;
|
||||
// The approach plan owns the editable handoff distance. It shifts only this
|
||||
// carriageway's outer transition, leaving neighboring arms untouched.
|
||||
const itemOuterRadius = Math.max(coreRadius + 4, outerRadius - Math.max(0, Number(item.approach.cutback) || 0));
|
||||
const outer = pointOnCarriagewayRadius(item, center, itemOuterRadius, helpers);
|
||||
const inner = pointOnCarriagewayRadius(item, center, coreRadius * 0.7, helpers);
|
||||
boundaryParts.push({ item, section });
|
||||
const outerHalf = item.approach.widthMeters / 2;
|
||||
const innerHalf = outerHalf;
|
||||
boundaryParts.push({ item, outer, inner, outerHalf, innerHalf });
|
||||
const incomingRoad = item.approach.roadIds
|
||||
.map((roadId) => model.roads.find((road) => road.id === roadId))
|
||||
.find((road) => String(road?.sourceNodeIds.at(-1)) === String(item.nodeId));
|
||||
@@ -529,13 +537,13 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
),
|
||||
);
|
||||
}
|
||||
for (const { item, outer, inner, outerHalf, innerHalf } of boundaryParts) {
|
||||
for (const { item, section } of boundaryParts) {
|
||||
const ring = [
|
||||
helpers.offsetCoordinate(outer, item.heading + 90, outerHalf),
|
||||
helpers.offsetCoordinate(inner, item.heading + 90, innerHalf),
|
||||
helpers.offsetCoordinate(inner, item.heading - 90, innerHalf),
|
||||
helpers.offsetCoordinate(outer, item.heading - 90, outerHalf),
|
||||
helpers.offsetCoordinate(outer, item.heading + 90, outerHalf),
|
||||
section.outer.right,
|
||||
section.inner.right,
|
||||
section.inner.left,
|
||||
section.outer.left,
|
||||
section.outer.right,
|
||||
];
|
||||
features.push({
|
||||
type: 'Feature',
|
||||
@@ -553,6 +561,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
0,
|
||||
),
|
||||
width_m: item.approach.widthMeters,
|
||||
boundary_refs: section.edgeRefs,
|
||||
provenance: 'native-road-complex-junction/v5',
|
||||
},
|
||||
geometry: { type: 'Polygon', coordinates: [ring] },
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
|
||||
const { stationAtDistanceFrom } = require('./junction-build-plan');
|
||||
|
||||
function pointAtStation(line, station, helpers) {
|
||||
let remaining = Math.max(0, station);
|
||||
for (let index = 1; index < line.length; index += 1) {
|
||||
const length = helpers.distanceMeters(line[index - 1], line[index]);
|
||||
if (remaining <= length) {
|
||||
const ratio = length ? remaining / length : 0;
|
||||
return [
|
||||
line[index - 1][0] + (line[index][0] - line[index - 1][0]) * ratio,
|
||||
line[index - 1][1] + (line[index][1] - line[index - 1][1]) * ratio,
|
||||
];
|
||||
}
|
||||
remaining -= length;
|
||||
}
|
||||
return line.at(-1) || null;
|
||||
}
|
||||
|
||||
function tangentAtStation(line, station, helpers) {
|
||||
let walked = 0;
|
||||
for (let index = 1; index < line.length; index += 1) {
|
||||
const length = helpers.distanceMeters(line[index - 1], line[index]);
|
||||
if (station <= walked + length || index === line.length - 1)
|
||||
return helpers.headingAtEndpoint([line[index - 1], line[index]]);
|
||||
walked += length;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function offsetCoordinate(point, heading, meters) {
|
||||
if (!point || !Number.isFinite(heading)) return null;
|
||||
const radians = (heading * Math.PI) / 180;
|
||||
const lonMeters = 111320 * Math.cos((point[1] * Math.PI) / 180);
|
||||
return [
|
||||
point[0] + (Math.sin(radians) * meters) / Math.max(lonMeters, 1e-9),
|
||||
point[1] + (Math.cos(radians) * meters) / 111320,
|
||||
];
|
||||
}
|
||||
|
||||
function sectionAt(item, radius, center, helpers) {
|
||||
const station = Math.min(item.length, stationAtDistanceFrom(item.approach.line, center, radius, helpers));
|
||||
const point = pointAtStation(item.approach.line, station, helpers);
|
||||
const tangent = tangentAtStation(item.approach.line, station, helpers);
|
||||
const halfWidth = Math.max(0, Number(item.approach.widthMeters) || 0) / 2;
|
||||
return {
|
||||
stationMeters: station,
|
||||
point,
|
||||
tangent,
|
||||
left: offsetCoordinate(point, tangent - 90, halfWidth),
|
||||
right: offsetCoordinate(point, tangent + 90, halfWidth),
|
||||
};
|
||||
}
|
||||
|
||||
// The graph currently owns only source-derived entry edges. Core closure is
|
||||
// deliberately unresolved until a later stage can distinguish paved links,
|
||||
// medians, and exclusion regions from topology alone.
|
||||
function buildJunctionBoundaryGraph(topology, center, radii, helpers) {
|
||||
const sections = topology.carriageways.map((item) => {
|
||||
const outerRadius = radii.outerRadiusFor(item);
|
||||
const innerRadius = radii.innerRadiusFor(item);
|
||||
const outer = sectionAt(item, outerRadius, center, helpers);
|
||||
const inner = sectionAt(item, innerRadius, center, helpers);
|
||||
const key = `boundary:${item.key}`;
|
||||
return {
|
||||
key,
|
||||
carriagewayKey: item.key,
|
||||
armKey: item.armKey,
|
||||
outer,
|
||||
inner,
|
||||
edgeRefs: {
|
||||
left: `${key}:left`,
|
||||
right: `${key}:right`,
|
||||
outer: `${key}:outer`,
|
||||
inner: `${key}:inner`,
|
||||
},
|
||||
};
|
||||
});
|
||||
const edges = sections.flatMap((section) => [
|
||||
{ key: section.edgeRefs.left, from: section.outer.left, to: section.inner.left, owner: section.carriagewayKey },
|
||||
{ key: section.edgeRefs.right, from: section.inner.right, to: section.outer.right, owner: section.carriagewayKey },
|
||||
{ key: section.edgeRefs.outer, from: section.outer.right, to: section.outer.left, owner: section.carriagewayKey },
|
||||
{ key: section.edgeRefs.inner, from: section.inner.left, to: section.inner.right, owner: section.carriagewayKey },
|
||||
]);
|
||||
return {
|
||||
schema: 'junction-boundary-graph/v1',
|
||||
status: 'entry-sections-only',
|
||||
sections,
|
||||
edges,
|
||||
unresolvedClosures: topology.arms.map((arm) => arm.cornerKey),
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { buildJunctionBoundaryGraph };
|
||||
Reference in new issue
Block a user