diff --git a/src/compile/junction-boundary-graph.js b/src/compile/junction-boundary-graph.js index 0331147..9d12d95 100644 --- a/src/compile/junction-boundary-graph.js +++ b/src/compile/junction-boundary-graph.js @@ -220,11 +220,20 @@ function coordinateDistanceMeters(first, second) { function buildCoreClosure(topology, graph, center) { let coreSections = graph.sections; if (topology.arms.some((arm) => arm.members.length !== 1)) { - if (topology.arms.length !== 4) return { status: 'unsupported', reason: 'parallel-carriageway-closure-unresolved' }; - coreSections = topology.arms.map((arm) => - graph.sections - .filter((section) => section.armKey === arm.key && section.ringStatus === 'supported') - .sort((a, b) => a.carriagewayKey.localeCompare(b.carriagewayKey))[0], + if (topology.arms.length < 4 || topology.arms.length > 6) + return { status: 'unsupported', reason: 'parallel-carriageway-closure-unresolved' }; + coreSections = topology.arms.map( + (arm) => + graph.sections + .filter((section) => section.armKey === arm.key && section.ringStatus === 'supported') + .sort((a, b) => { + const distance = (section) => { + const x = (section.inner.left[0] + section.inner.right[0]) / 2 - center[0]; + const y = (section.inner.left[1] + section.inner.right[1]) / 2 - center[1]; + return x * x + y * y; + }; + return distance(a) - distance(b) || a.carriagewayKey.localeCompare(b.carriagewayKey); + })[0], ); if (coreSections.some((section) => !section)) return { status: 'unsupported', reason: 'parallel-carriageway-closure-unresolved' };