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