diff --git a/src/compile/junction-facility-composition.js b/src/compile/junction-facility-composition.js index 2fcd567..68236b0 100644 --- a/src/compile/junction-facility-composition.js +++ b/src/compile/junction-facility-composition.js @@ -168,7 +168,15 @@ function solveIslandContacts(firstSegment, secondSegment, thirdWidth, options = ) / 2; if (hexArea <= 1e-8) return fail('degenerate-contact-hexagon'); const ring = []; - const controls = [firstTip, secondTip, corner]; + 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 * 0.55 + corner[axis] * 0.45); + const innerMidpoint = midpoint(contacts[2][1], contacts[0][0]); + const innerControl = innerMidpoint.map((value, axis) => value * 1.35 - corner[axis] * 0.35); + const controls = [firstTip, hypotenuseControl, innerControl]; const steps = 16; contacts.forEach((contact, index) => { ring.push(...contact); diff --git a/test/junction-facility-composition.js b/test/junction-facility-composition.js index ef8a459..061efa9 100644 --- a/test/junction-facility-composition.js +++ b/test/junction-facility-composition.js @@ -30,6 +30,16 @@ assert.deepEqual(sketchIsland[0], sketchIsland.at(-1)); assert.ok(sketchIsland.every(([x, y]) => x <= 0 && y >= 0)); const arcMiddle = sketchIsland[7]; assert.ok(arcMiddle[1] - arcMiddle[0] < 6.8, 'hypotenuse bends toward the right-angle vertex'); +const longEdgeStart = sketchIsland[18]; +const longEdgeEnd = sketchIsland[34]; +const longEdgeMid = sketchIsland[26]; +const longEdgeCross = + (longEdgeEnd[0] - longEdgeStart[0]) * (longEdgeMid[1] - longEdgeStart[1]) - + (longEdgeEnd[1] - longEdgeStart[1]) * (longEdgeMid[0] - longEdgeStart[0]); +const cornerSideCross = + (longEdgeEnd[0] - longEdgeStart[0]) * (0 - longEdgeStart[1]) - + (longEdgeEnd[1] - longEdgeStart[1]) * (0 - longEdgeStart[0]); +assert.ok(longEdgeCross * cornerSideCross > 0, 'long edge must bow toward the right-angle vertex'); for (const crossing of [ [ [0, 0],