From 0f1850f7407bd1359ecd5ce2b8b3c0ac238a241c Mon Sep 17 00:00:00 2001 From: que01 Date: Tue, 29 Sep 2026 10:23:13 +0800 Subject: [PATCH] fix: align separators at complex crosswalks --- src/compile/native-road.js | 24 +++++++++++++++++++++--- test/junction-corridor-markings.js | 12 +++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/compile/native-road.js b/src/compile/native-road.js index 0ea9c33..a76d75a 100644 --- a/src/compile/native-road.js +++ b/src/compile/native-road.js @@ -1185,9 +1185,27 @@ function compileComplexLaneSeparators(features, controls = [], clusterCenters = ), ) : null; - for (const { index, left, right, line } of prepared) { - const publishedLine = - center && Number.isFinite(sharedRadius) ? trimLineOutsideRadius(line, center, sharedRadius) : line; + const radiusClipped = prepared.map(({ line }) => + center && Number.isFinite(sharedRadius) ? trimLineOutsideRadius(line, center, sharedRadius) : line, + ); + // A diagonal zebra intersects adjacent lane separators at different + // longitudinal stations. Use the shortest post-control line as the + // shared inward cutoff so parallel separators terminate at one crossing + // boundary instead of leaving one visibly longer than its neighbour. + const sharedVisibleLength = Math.min( + ...radiusClipped.filter(Boolean).map((line) => lineLengthMeters(line)), + ); + for (let preparedIndex = 0; preparedIndex < prepared.length; preparedIndex += 1) { + const { index, left, right } = prepared[preparedIndex]; + const line = radiusClipped[preparedIndex]; + if (!line) continue; + const outwardFirst = distanceMeters(line[0], center) >= distanceMeters(line.at(-1), center); + const oriented = outwardFirst ? line : [...line].reverse(); + const publishedOriented = + Number.isFinite(sharedVisibleLength) && lineLengthMeters(oriented) > sharedVisibleLength + 0.01 + ? trimLineRange(oriented, 0, lineLengthMeters(oriented) - sharedVisibleLength) + : oriented; + const publishedLine = outwardFirst ? publishedOriented : [...publishedOriented].reverse(); const ring = roadRing(publishedLine, 0.12); if (!ring) continue; result.push({ diff --git a/test/junction-corridor-markings.js b/test/junction-corridor-markings.js index c406e07..195e037 100644 --- a/test/junction-corridor-markings.js +++ b/test/junction-corridor-markings.js @@ -57,12 +57,22 @@ for (const ordered of [clusters, [...clusters].reverse()]) { .filter((separator) => separator.properties.cluster_id === 'west') .map((separator) => { const ring = separator.geometry.coordinates[0]; - return Math.min(...ring.map((point) => meters(point, clusterCenter))); + const start = [(ring[0][0] + ring[1][0]) / 2, (ring[0][1] + ring[1][1]) / 2]; + const end = [(ring[2][0] + ring[3][0]) / 2, (ring[2][1] + ring[3][1]) / 2]; + return meters(start, end); }); assert.ok( Math.max(...endpointDistances) - Math.min(...endpointDistances) < 0.2, 'adjacent complex separators must share a stable core-side endpoint', ); + const separatorLengths = complexSeparators.map((separator) => { + const ring = separator.geometry.coordinates[0]; + return ring.slice(1, -1).reduce((sum, point, index) => sum + meters(ring[index], point), 0); + }); + assert.ok( + Math.max(...separatorLengths) - Math.min(...separatorLengths) < 0.2, + 'adjacent complex separators must share the same zebra-side cutoff', + ); } } for (const separator of complexSeparators) {