feat: measure junction shared seam errors
This commit is contained in:
1 parent
79f83412e6
commit
49212b3f34
4 files changed
+73
-9
No files matched your search
@@ -40,8 +40,10 @@ function offsetCoordinate(point, heading, meters) {
|
||||
}
|
||||
|
||||
function sectionAt(item, radius, center, widthMeters, helpers, explicitStation) {
|
||||
const station =
|
||||
explicitStation ?? Math.min(item.length, stationAtDistanceFrom(item.approach.line, center, radius, helpers));
|
||||
const station = Math.max(
|
||||
0,
|
||||
Math.min(item.length, explicitStation ?? 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(widthMeters) || 0) / 2;
|
||||
@@ -64,15 +66,16 @@ function buildJunctionBoundaryGraph(topology, center, radii, helpers, exclusionR
|
||||
const outerWidthMeters = Number(item.approach.sourceWidthMeters) || item.approach.widthMeters;
|
||||
const innerWidthMeters = item.approach.widthMeters;
|
||||
const outer = sectionAt(item, outerRadius, center, outerWidthMeters, helpers);
|
||||
const requestedTransition = Number.isFinite(item.approach.transitionLengthMeters)
|
||||
? Math.max(0, item.approach.transitionLengthMeters)
|
||||
: null;
|
||||
const inner = sectionAt(
|
||||
item,
|
||||
innerRadius,
|
||||
center,
|
||||
innerWidthMeters,
|
||||
helpers,
|
||||
Number.isFinite(item.approach.transitionLengthMeters)
|
||||
? outer.stationMeters - item.approach.transitionLengthMeters
|
||||
: undefined,
|
||||
requestedTransition === null ? undefined : outer.stationMeters - requestedTransition,
|
||||
);
|
||||
const key = `boundary:${item.key}`;
|
||||
const sectionRing = [outer.right, inner.right, inner.left, outer.left, outer.right];
|
||||
@@ -89,7 +92,13 @@ function buildJunctionBoundaryGraph(topology, center, radii, helpers, exclusionR
|
||||
outerWidthMeters,
|
||||
innerWidthMeters,
|
||||
transitionMeters: Math.max(0, outer.stationMeters - inner.stationMeters),
|
||||
transitionStatus: outer.stationMeters - inner.stationMeters > 1e-6 ? 'supported' : 'insufficient-source-length',
|
||||
transitionStatus:
|
||||
requestedTransition !== null &&
|
||||
Math.abs(requestedTransition - Math.max(0, outer.stationMeters - inner.stationMeters)) > 1e-6
|
||||
? 'insufficient-source-length'
|
||||
: outer.stationMeters - inner.stationMeters > 1e-6
|
||||
? 'supported'
|
||||
: 'insufficient-source-length',
|
||||
outer,
|
||||
inner,
|
||||
ring: sectionRing,
|
||||
@@ -175,6 +184,15 @@ function ringsOverlap(first, second) {
|
||||
);
|
||||
}
|
||||
|
||||
function coordinateDistanceMeters(first, second) {
|
||||
if (!first?.every(Number.isFinite) || !second?.every(Number.isFinite)) return Infinity;
|
||||
const radians = Math.PI / 180;
|
||||
const latitude = ((first[1] + second[1]) / 2) * radians;
|
||||
const east = (second[0] - first[0]) * 111320 * Math.cos(latitude);
|
||||
const north = (second[1] - first[1]) * 111320;
|
||||
return Math.hypot(east, north);
|
||||
}
|
||||
|
||||
// A central paved region is safe to infer only when every arm has exactly one
|
||||
// source carriageway. Its shared entry seams are the sections' `inner` edges;
|
||||
// every remaining edge is an explicit closure between adjacent arms.
|
||||
@@ -214,7 +232,7 @@ function buildCoreClosure(topology, graph, center) {
|
||||
return { status: 'unsupported', reason: 'core-closure-invalid' };
|
||||
if (graph.exclusionRegions.some((region) => ringsOverlap(region.ring, ring)))
|
||||
return { status: 'unsupported', reason: 'known-exclusion-region' };
|
||||
const seamErrorMeters = graph.sections.reduce((maximum, section) => {
|
||||
const seamErrors = graph.sections.map((section) => {
|
||||
const leftIndex = ring.findIndex(
|
||||
(point) => point[0] === section.inner.left[0] && point[1] === section.inner.left[1],
|
||||
);
|
||||
@@ -225,14 +243,28 @@ function buildCoreClosure(topology, graph, center) {
|
||||
leftIndex >= 0 &&
|
||||
rightIndex >= 0 &&
|
||||
(Math.abs(leftIndex - rightIndex) === 1 || Math.abs(leftIndex - rightIndex) === ring.length - 2);
|
||||
return Math.max(maximum, contiguous ? 0 : Infinity);
|
||||
}, 0);
|
||||
const edge = graph.edges.find((candidate) => candidate.key === section.edgeRefs.inner);
|
||||
if (!contiguous || !edge) return { carriagewayKey: section.carriagewayKey, errorMeters: Infinity };
|
||||
const ringLeft = ring[leftIndex];
|
||||
const ringRight = ring[rightIndex];
|
||||
const forward = Math.max(
|
||||
coordinateDistanceMeters(ringLeft, edge.from),
|
||||
coordinateDistanceMeters(ringRight, edge.to),
|
||||
);
|
||||
const reverse = Math.max(
|
||||
coordinateDistanceMeters(ringLeft, edge.to),
|
||||
coordinateDistanceMeters(ringRight, edge.from),
|
||||
);
|
||||
return { carriagewayKey: section.carriagewayKey, errorMeters: Math.min(forward, reverse) };
|
||||
});
|
||||
const seamErrorMeters = seamErrors.reduce((maximum, item) => Math.max(maximum, item.errorMeters), 0);
|
||||
return {
|
||||
status: 'supported',
|
||||
ring,
|
||||
sharedEdgeRefs: [...pairedEdges.keys()].sort(),
|
||||
closureCount: graph.sections.length,
|
||||
maxSharedSeamErrorMeters: seamErrorMeters,
|
||||
sharedSeamErrors: seamErrors,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user