diff --git a/src/compile/junction-facility-composition.js b/src/compile/junction-facility-composition.js index 68236b0..ca0719c 100644 --- a/src/compile/junction-facility-composition.js +++ b/src/compile/junction-facility-composition.js @@ -1,5 +1,7 @@ '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 || [])]; @@ -173,9 +175,12 @@ function solveIslandContacts(firstSegment, secondSegment, thirdWidth, options = // 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 hypotenuseControl = hypotenuseMidpoint.map((value, axis) => value * 1.45 - 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); + // 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) => { @@ -191,11 +196,14 @@ function solveIslandContacts(firstSegment, secondSegment, thirdWidth, options = } }); ring.push(ring[0]); + 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, ring, - greenRing: [...vertices, vertices[0]], + greenRing, contacts, thirdContact, thirdCenter, diff --git a/test/junction-facility-composition.js b/test/junction-facility-composition.js index 061efa9..c820ab0 100644 --- a/test/junction-facility-composition.js +++ b/test/junction-facility-composition.js @@ -40,6 +40,24 @@ 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'); +const islandContains = (point) => { + let inside = false; + for (let i = 0, j = sketchIsland.length - 1; i < sketchIsland.length; j = i++) { + const a = sketchIsland[i], + b = sketchIsland[j]; + if (a[1] > point[1] !== b[1] > point[1] && point[0] < ((b[0] - a[0]) * (point[1] - a[1])) / (b[1] - a[1]) + a[0]) + inside = !inside; + } + return inside; +}; +assert.ok( + sketchIsland + .slice(0, -1) + .every( + (point) => islandContains(point) || sketchIsland.some((item) => item[0] === point[0] && item[1] === point[1]), + ), + 'green contact points must stay inside island', +); for (const crossing of [ [ [0, 0],