From e0eaa1c950348487dced78c56e733a503000b2fe Mon Sep 17 00:00:00 2001 From: que01 Date: Wed, 16 Sep 2026 15:35:33 +0800 Subject: [PATCH] fix: fill pavement gaps when junction islands move outward --- src/compile/complex-junction.js | 26 ++++++++++++++++ test/junction-island-offset.js | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/src/compile/complex-junction.js b/src/compile/complex-junction.js index b4c272a..8f27636 100644 --- a/src/compile/complex-junction.js +++ b/src/compile/complex-junction.js @@ -802,6 +802,32 @@ function buildComplexJunctionGeometry(model, cluster, helpers) { if (crossing.properties.arm_key === arm.key) crossing.geometry.coordinates[0] = movedRing(crossing.geometry.coordinates[0]); } + // Preserve the original full crossing footprint and pave the swept + // connection to its new position, including the gaps between white bars. + const frame = arm.crosswalkFrame; + const corners = rectangle(frame.center, frame.heading, frame.groupDepth, frame.spanMeters); + const originalRegion = []; + // Split at the same endpoint clamps used by movedRing. A four-vertex + // rectangle would interpolate across those clamps and cut off the bars. + const contactRatio = frame.contactEndpointRatio || 0; + for (let edge = 0; edge < 4; edge++) { + const ratios = edge % 2 === 0 ? [0, contactRatio, 1 - contactRatio] : [0]; + for (const ratio of ratios) { + originalRegion.push(corners[edge].map((value, axis) => value + (corners[edge + 1][axis] - value) * ratio)); + } + } + originalRegion.push(originalRegion[0]); + const movedRegion = movedRing(originalRegion); + crossingRegions.push(movedRegion); + for (let edge = 0; edge < originalRegion.length - 1; edge++) { + crossingRegions.push([ + originalRegion[edge], + originalRegion[edge + 1], + movedRegion[edge + 1], + movedRegion[edge], + originalRegion[edge], + ]); + } const averageShift = [(offsets[0][0] + offsets[1][0]) / 2, (offsets[0][1] + offsets[1][1]) / 2]; for (const stopLine of stopLines) { if (stopLine.properties.arm_key !== arm.key) continue; diff --git a/test/junction-island-offset.js b/test/junction-island-offset.js index 4b2df14..6d4e302 100644 --- a/test/junction-island-offset.js +++ b/test/junction-island-offset.js @@ -33,6 +33,60 @@ assert.ok(Math.hypot(shift[0] * 111320 * Math.cos((center[1] * Math.PI) / 180), directEdit: { clusterIslandOffsets: new Map([[cluster.id, 2]]) }, }, ); + // Check the complete crossing envelope at intermediate positions, not only + // stripe coverage at the final position. This catches the exposed road gap. + const clipping = require('polygon-clipping'); + const toMeters = ([x, y]) => [(x - 114) * 111320 * Math.cos((30 * Math.PI) / 180), (y - 30) * 111320]; + const area = (regions) => + regions.reduce( + (total, polygon) => + total + + polygon.reduce((sum, ring, index) => { + const value = + Math.abs(ring.slice(1).reduce((acc, p, i) => acc + ring[i][0] * p[1] - p[0] * ring[i][1], 0)) / 2; + return sum + (index ? -value : value); + }, 0), + 0, + ); + const groups = (geometry) => { + const result = new Map(); + for (const feature of geometry.crosswalks.features) { + if (feature.properties.kind !== 'complex-crosswalk') continue; + const key = feature.properties.arm_key; + const stripes = result.get(key) || []; + stripes.push(feature.geometry.coordinates[0]); + result.set(key, stripes); + } + return new Map( + [...result].map(([key, stripes]) => { + const first = stripes[0], + last = stripes.at(-1); + return [key, [first[0], first[1], last[2], last[3], first[0]].map(toMeters)]; + }), + ); + }; + const originalGroups = groups(base); + for (const offset of [3.3, 8]) { + const moved = compileGeometry( + model, + { overrides: [] }, + { + ...options, + directEdit: { clusterIslandOffsets: new Map([[cluster.id, offset]]) }, + }, + ); + const pavement = moved.roadSurface.features.find((f) => f.properties.kind === 'complex-pavement-region'); + assert.ok(pavement, `offset ${offset}: must publish unified pavement`); + const regions = pavement.geometry.coordinates.map((polygon) => polygon.map((ring) => ring.map(toMeters))); + for (const [key, end] of groups(moved)) { + const start = originalGroups.get(key); + for (const ratio of [0, 0.25, 0.5, 0.75, 1]) { + const envelope = start.map((point, i) => point.map((v, axis) => v + (end[i][axis] - v) * ratio)); + const missing = area(clipping.difference([envelope], regions)); + assert.ok(missing < 0.001, `offset ${offset}, arm ${key}, sweep ${ratio}: ${missing} m² unpaved`); + } + } + } const byKind = (geometry, kind) => geometry.sidewalkSurface.features.filter((feature) => feature.properties.kind === kind); const baseIslands = byKind(base, 'island');