diff --git a/src/compile/native-road.js b/src/compile/native-road.js index 67ccf8d..0ea9c33 100644 --- a/src/compile/native-road.js +++ b/src/compile/native-road.js @@ -1149,6 +1149,10 @@ function compileComplexLaneSeparators(features, controls = [], clusterCenters = for (const lanes of groups.values()) { const roadId = lanes[0].properties.road_id; lanes.sort((first, second) => first.properties.lane_index - second.properties.lane_index); + const clusterId = lanes[0].properties.cluster_id; + const center = clusterCenters.get(clusterId); + const coreRadius = clusterCoreRadii.get(clusterId); + const prepared = []; for (let index = 1; index < lanes.length; index += 1) { const left = lanes[index - 1].geometry.coordinates; const right = lanes[index].geometry.coordinates; @@ -1162,14 +1166,29 @@ function compileComplexLaneSeparators(features, controls = [], clusterCenters = // near the core and make the separator disappear entirely. const roadControls = controls.filter((control) => String(control.properties?.road_id || '') === String(roadId)); const visibleLine = trimLineBeforeFirstControl(line, roadControls, 0.12); - const clusterId = lanes[0].properties.cluster_id; - const center = clusterCenters.get(clusterId); - const coreRadius = clusterCoreRadii.get(clusterId); const coreClippedLine = visibleLine && center && Number.isFinite(coreRadius) ? trimLineOutsideRadius(visibleLine, center, coreRadius) : visibleLine; - const ring = coreClippedLine ? roadRing(coreClippedLine, 0.12) : null; + if (!coreClippedLine) continue; + prepared.push({ index, left, right, line: coreClippedLine }); + } + // Adjacent separators share the same zebra/stop-line cutoff. Their lane + // offsets can otherwise make the polygon-overlap probe stop a few + // centimetres apart, leaving visibly uneven endpoints. Use the shortest + // outward-to-inward station as the shared, geometry-derived cutoff. + if (!prepared.length) continue; + const sharedRadius = center + ? Math.min( + ...prepared.map(({ line }) => + Math.min(...line.map((point) => distanceMeters(point, center))), + ), + ) + : null; + for (const { index, left, right, line } of prepared) { + const publishedLine = + center && Number.isFinite(sharedRadius) ? trimLineOutsideRadius(line, center, sharedRadius) : line; + const ring = roadRing(publishedLine, 0.12); if (!ring) continue; result.push({ type: 'Feature', diff --git a/test/junction-corridor-markings.js b/test/junction-corridor-markings.js index d0b4956..c406e07 100644 --- a/test/junction-corridor-markings.js +++ b/test/junction-corridor-markings.js @@ -36,7 +36,10 @@ for (const ordered of [clusters, [...clusters].reverse()]) { const road = model.roads.find((r) => r.id === roadId); const midpoint = road.centerline[0].map((v, i) => (v + road.centerline.at(-1)[i]) / 2); const complexSeparators = geometry.laneSeparators.features.filter( - (f) => f.properties.road_id === roadId && f.properties.provenance === 'native-road-complex-lane-separator/v1', + (f) => + f.properties.road_id === roadId && + f.properties.cluster_id === 'west' && + f.properties.provenance === 'native-road-complex-lane-separator/v1', ); if (roadId === 'road:way/858770823:segment/2:forward') { const core = geometry.roadSurface.features.find( @@ -50,6 +53,16 @@ for (const ordered of [clusters, [...clusters].reverse()]) { separator.geometry.coordinates[0].every((point) => meters(point, clusterCenter) >= coreRadius - 0.05), 'complex separator must stop outside the calibrated west-cluster core', ); + const endpointDistances = complexSeparators + .filter((separator) => separator.properties.cluster_id === 'west') + .map((separator) => { + const ring = separator.geometry.coordinates[0]; + return Math.min(...ring.map((point) => meters(point, clusterCenter))); + }); + assert.ok( + Math.max(...endpointDistances) - Math.min(...endpointDistances) < 0.2, + 'adjacent complex separators must share a stable core-side endpoint', + ); } } for (const separator of complexSeparators) {