fix complex junction island geometry

This commit is contained in:
que01 committed 2026-09-16 13:24:34 +08:00
1 parent c3579074fd
commit 0c42eb46cd
19 files changed
+424 -44

No files matched your search

+34 -32
View File
@@ -1,7 +1,5 @@
'use strict';
const { union } = require('./junction-polygon-ops');
function buildPedestrianIsland({ key, ring, crossingKeys, provenance = 'inferred' }) {
if (!key || !Array.isArray(ring) || ring.length < 4) return null;
const adjacentCrossings = [...new Set(crossingKeys || [])];
@@ -108,7 +106,7 @@ function crossingArcSupport(ring, halfWidth) {
module.exports.crossingArcSupport = crossingArcSupport;
// Solve three complete landings together. All coordinates are local metres.
// Quadratic connectors round the supporting triangle outside the green hexagon;
// Rounded supporting-triangle tips remain outside the green contact hexagon;
// the three contact segments themselves are never shortened by rounding.
function solveIslandContacts(firstSegment, secondSegment, thirdWidth, options = {}) {
const fail = (reason) => ({ status: 'infeasible', reason });
@@ -156,7 +154,11 @@ function solveIslandContacts(firstSegment, secondSegment, thirdWidth, options =
return fail('leg-length-exceeds-space');
const firstTip = add(corner, u, legLengths[0]),
secondTip = add(corner, v, legLengths[1]);
const thirdCenter = firstTip.map((value, i) => (value + secondTip[i]) / 2);
const tipCenter = firstTip.map((value, i) => (value + secondTip[i]) / 2);
// Move the landing toward the corner, leaving the tips on the supporting
// triangle. Bound the inset by the spare leg length so contacts remain inside.
const inset = Math.min(0.12, 0.35 * Math.min(1 - a / legLengths[0], 1 - b / legLengths[1]));
const thirdCenter = add(tipCenter, sub(corner, tipCenter), inset);
const thirdContact = [add(thirdCenter, tangent, -thirdWidth / 2), add(thirdCenter, tangent, thirdWidth / 2)];
let outward = [tangent[1], -tangent[0]];
if (dot(outward, sub(thirdCenter, corner)) < 0) outward = outward.map((value) => -value);
@@ -172,36 +174,36 @@ function solveIslandContacts(firstSegment, secondSegment, thirdWidth, options =
}, 0),
) / 2;
if (hexArea <= 1e-8) return fail('degenerate-contact-hexagon');
const ring = [];
const midpoint = (a, b) => a.map((value, axis) => (value + b[axis]) / 2);
// The hypotenuse must bow toward the right-angle vertex. The final inner
// roundover is pushed away from that vertex so the island does not intrude
// into the vehicle swept area behind the two perpendicular crossings.
const hypotenuseMidpoint = midpoint(contacts[1][1], contacts[2][0]);
const hypotenuseControl = hypotenuseMidpoint.map((value, axis) => value * 1.45 - corner[axis] * 0.45);
const innerMidpoint = midpoint(contacts[2][1], contacts[0][0]);
// Keep the right-angle roundover outside the crossing intersection. Its
// control point is deliberately beyond the contact chord, leaving the
// vehicle-side edge at least one crossing half-depth from the corner.
const innerControl = innerMidpoint.map((value, axis) => value * 4 - corner[axis] * 3);
const controls = [firstTip, hypotenuseControl, innerControl];
const steps = 16;
contacts.forEach((contact, index) => {
ring.push(...contact);
const start = contact[1],
end = contacts[(index + 1) % 3][0],
control = controls[index];
for (let step = 1; step < steps; step++) {
const t = step / steps;
ring.push(
start.map((value, axis) => (1 - t) ** 2 * value + 2 * t * (1 - t) * control[axis] + t ** 2 * end[axis]),
);
// Keep the two complete straight legs. Only their unused ends are rounded;
// the former six-endpoint outline discarded all three triangle vertices.
const radius = Math.min(0.45, length(sub(first[0], corner)) / 3, length(sub(second[0], corner)) / 3);
const firstTrim = Math.min(radius, (legLengths[0] - a) / 3);
const secondTrim = Math.min(radius, (legLengths[1] - b) / 3);
const nearFirst = add(corner, u, radius);
const nearSecond = add(corner, v, radius);
const tipFirst = add(firstTip, u, -firstTrim);
const tipSecond = add(secondTip, v, -secondTrim);
const ring = [nearFirst, ...first, tipFirst];
const cubic = (start, control1, control2, end) => {
for (let step = 1; step <= 16; step++) {
const t = step / 16, q = 1 - t;
ring.push(start.map((value, axis) =>
q ** 3 * value + 3 * q * q * t * control1[axis] +
3 * q * t * t * control2[axis] + t ** 3 * end[axis]));
}
});
ring.push(ring[0]);
};
// Tangents follow the leg at each tip and the full straight landing at the
// middle. Thus the long side bows inward without a kink at the third crossing.
const firstRun = length(sub(thirdContact[0], firstTip)) / 3;
const secondRun = length(sub(secondTip, thirdContact[1])) / 3;
cubic(tipFirst, firstTip, add(thirdContact[0], tangent, -firstRun), thirdContact[0]);
ring.push(thirdContact[1]);
cubic(thirdContact[1], add(thirdContact[1], tangent, secondRun), secondTip, tipSecond);
ring.push(second[1], second[0], nearSecond);
// A small right-angle roundover, independent of the contact-to-corner distance.
cubic(nearSecond, add(nearSecond, v, -radius * 0.55228475),
add(nearFirst, u, -radius * 0.55228475), nearFirst);
const greenRing = [...vertices, vertices[0]];
const merged = union(ring, greenRing);
if (merged.length === 1 && merged[0].length === 1) ring.splice(0, ring.length, ...merged[0][0]);
return {
status: 'solved',
reason: null,