fix: coordinate crosswalk landings across all four islands
This commit is contained in:
1 parent
1b91e280bc
commit
695bf21a84
6 files changed
+121
-25
No files matched your search
@@ -274,13 +274,57 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
arm.crosswalkFrame.supportHeading = normalizeHeading(crossingHeadings[index] + 90);
|
||||
}
|
||||
});
|
||||
// Coordinate all four landing pairs before publishing stripes. Trim whole
|
||||
// stripe pitches symmetrically so stripe size and spacing stay unchanged.
|
||||
let crossingSpanTrim = 0;
|
||||
if (arms.length === 4 && arms.every((arm) => arm.crosswalkFrame)) {
|
||||
for (let attempt = 0; attempt < 12; attempt++) {
|
||||
const trialTrim = attempt * 1.64;
|
||||
const candidates = arms.map((arm) => {
|
||||
const f = arm.crosswalkFrame;
|
||||
const span = f.envelopeWidthMeters - 0.7 - trialTrim;
|
||||
if (span < f.groupDepth) return null;
|
||||
const shifted = helpers.offsetCoordinate(f.center, f.heading, f.groupDepth);
|
||||
const layout = stripeLayout(span);
|
||||
const half = span / 2 - (layout.centers[0] - layout.width / 2);
|
||||
return [-1, 1].map((sign) => helpers.offsetCoordinate(shifted, f.heading + 90, sign * half));
|
||||
});
|
||||
if (candidates.some((candidate) => !candidate)) break;
|
||||
const valid = arms.every((arm, i) => {
|
||||
const j = (i + 1) % arms.length;
|
||||
const pair = candidates[i]
|
||||
.flatMap((a) => candidates[j].map((b) => ({ a, b, distance: helpers.distanceMeters(a, b) })))
|
||||
.sort((a, b) => a.distance - b.distance)[0];
|
||||
const origin = rayIntersection(
|
||||
{ point: pair.a, heading: arm.crosswalkFrame.heading },
|
||||
{ point: pair.b, heading: arms[j].crosswalkFrame.heading },
|
||||
center,
|
||||
);
|
||||
return (
|
||||
origin &&
|
||||
[
|
||||
[arm, pair.a],
|
||||
[arms[j], pair.b],
|
||||
].every(
|
||||
([side, point]) =>
|
||||
directionalProjectionMeters(origin, point, side.crosswalkFrame.heading) >
|
||||
side.crosswalkFrame.groupDepth / 2 + 0.2,
|
||||
)
|
||||
);
|
||||
});
|
||||
if (valid) {
|
||||
crossingSpanTrim = trialTrim;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let index = 0; index < arms.length; index += 1) {
|
||||
const arm = arms[index];
|
||||
if (!arm.crosswalkFrame) continue;
|
||||
const item = arm.representative;
|
||||
const crossingHeading = arm.crosswalkFrame.heading;
|
||||
const roadEdgeInset = 0.35;
|
||||
const usableSpan = Math.max(0.42, arm.crosswalkFrame.envelopeWidthMeters - roadEdgeInset * 2);
|
||||
const usableSpan = Math.max(0.42, arm.crosswalkFrame.envelopeWidthMeters - roadEdgeInset * 2 - crossingSpanTrim);
|
||||
const groupDepth = arm.crosswalkFrame.groupDepth;
|
||||
arm.crosswalkFrame.center = helpers.offsetCoordinate(arm.crosswalkFrame.center, crossingHeading, groupDepth);
|
||||
arm.crosswalkRadius += groupDepth;
|
||||
@@ -477,21 +521,30 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
const outerFirst = helpers.offsetCoordinate(
|
||||
crossingCorner,
|
||||
first.crosswalkFrame.heading,
|
||||
first.crosswalkFrame.groupDepth * 2,
|
||||
first.crosswalkFrame.groupDepth,
|
||||
);
|
||||
const outerSecond = helpers.offsetCoordinate(
|
||||
crossingCorner,
|
||||
second.crosswalkFrame.heading,
|
||||
second.crosswalkFrame.groupDepth * 2,
|
||||
second.crosswalkFrame.groupDepth,
|
||||
);
|
||||
const lonScale = 111320 * Math.cos((crossingCorner[1] * Math.PI) / 180);
|
||||
const toLocal = (point) => [(point[0] - crossingCorner[0]) * lonScale, (point[1] - crossingCorner[1]) * 111320];
|
||||
const fromLocal = (point) => [crossingCorner[0] + point[0] / lonScale, crossingCorner[1] + point[1] / 111320];
|
||||
const landing = (arm, endpoint) => {
|
||||
const frame = arm.crosswalkFrame;
|
||||
const layout = stripeLayout(frame.spanMeters);
|
||||
const margin = layout.centers[0] - layout.width / 2;
|
||||
const edgeCenter = helpers.offsetCoordinate(endpoint, bearing(endpoint, frame.center), margin);
|
||||
return [-1, 1].map((sign) =>
|
||||
toLocal(helpers.offsetCoordinate(edgeCenter, frame.heading, (sign * frame.groupDepth) / 2)),
|
||||
);
|
||||
};
|
||||
const contactSolution = solveIslandContacts(
|
||||
[[0, 0], toLocal(outerFirst)],
|
||||
[[0, 0], toLocal(outerSecond)],
|
||||
landing(first, pair.a),
|
||||
landing(second, pair.b),
|
||||
COMPLEX_CROSSWALK_DEPTH_METERS,
|
||||
{ maxLegLength: Math.max(outerRadius * 2, COMPLEX_CROSSWALK_DEPTH_METERS * 4) },
|
||||
{ maxLegLength: outerRadius },
|
||||
);
|
||||
if (contactSolution.status !== 'solved') {
|
||||
cornerDiagnostics.push(
|
||||
@@ -549,18 +602,9 @@ function buildComplexJunctionGeometry(model, cluster, helpers) {
|
||||
// not required for the default visual treatment.
|
||||
const outerMidpoint = fromLocal(contactSolution.thirdCenter);
|
||||
const diagonalDepth = COMPLEX_CROSSWALK_DEPTH_METERS;
|
||||
const diagonalHeading = bearing(outerFirst, outerSecond) - 90;
|
||||
const outwardHeading = bearing(crossingCorner, outerMidpoint);
|
||||
const theta = (outwardHeading * Math.PI) / 180;
|
||||
const diagonalLonScale = 111320 * Math.cos((outerMidpoint[1] * Math.PI) / 180);
|
||||
const projectedIsland = publishedIslandRing.map((p) => {
|
||||
const east = (p[0] - outerMidpoint[0]) * diagonalLonScale;
|
||||
const north = (p[1] - outerMidpoint[1]) * 111320;
|
||||
return [east * Math.cos(theta) - north * Math.sin(theta), east * Math.sin(theta) + north * Math.cos(theta)];
|
||||
});
|
||||
const support = crossingArcSupport(projectedIsland, COMPLEX_CROSSWALK_DEPTH_METERS / 2);
|
||||
if (support === null) continue;
|
||||
const diagonalCenter = helpers.offsetCoordinate(outerMidpoint, outwardHeading, support + diagonalDepth / 2);
|
||||
const outwardHeading = (Math.atan2(contactSolution.outward[0], contactSolution.outward[1]) * 180) / Math.PI;
|
||||
const diagonalHeading = outwardHeading;
|
||||
const diagonalCenter = helpers.offsetCoordinate(outerMidpoint, outwardHeading, diagonalDepth / 2);
|
||||
const diagonalSpan = COMPLEX_CROSSWALK_DEPTH_METERS;
|
||||
const layout = stripeLayout(diagonalDepth);
|
||||
const stripeCount = layout.centers.length;
|
||||
|
||||
Reference in new issue
Block a user