From 914adcc4e602eec0f722feb8ef16e84f07b724bd Mon Sep 17 00:00:00 2001 From: que01 Date: Mon, 14 Sep 2026 15:54:39 +0800 Subject: [PATCH] fix: pave complex junction crossings --- src/compile/complex-junction.js | 69 +++++++++++++++++++++++++++ test/junction-facility-composition.js | 26 ++++++++++ 2 files changed, 95 insertions(+) diff --git a/src/compile/complex-junction.js b/src/compile/complex-junction.js index 1ca67d9..c47c890 100644 --- a/src/compile/complex-junction.js +++ b/src/compile/complex-junction.js @@ -84,6 +84,10 @@ function buildComplexJunctionGeometry(model, cluster, helpers) { const boundaryParts = []; const transitionDiagnostics = []; const crosswalks = []; + // A crossing is a connection across a paved carriageway, never decoration + // over empty ground. Keep its complete rectangle as an explicit road-surface + // component so core closure gaps cannot show through the white stripes. + const crosswalkPavements = []; const stopLines = []; const islands = []; const crossingControls = helpers.clusterCrossingControls || new Map(); @@ -340,6 +344,28 @@ function buildComplexJunctionGeometry(model, cluster, helpers) { arm.crosswalkFrame.endpoints = endpoints; arm.crosswalkFrame.spanMeters = usableSpan; arm.crosswalkFrame.roadEdgeInsetMeters = roadEdgeInset; + const pavementRing = [ + helpers.offsetCoordinate(endpoints[0], crossingHeading, -groupDepth / 2), + helpers.offsetCoordinate(endpoints[1], crossingHeading, -groupDepth / 2), + helpers.offsetCoordinate(endpoints[1], crossingHeading, groupDepth / 2), + helpers.offsetCoordinate(endpoints[0], crossingHeading, groupDepth / 2), + helpers.offsetCoordinate(endpoints[0], crossingHeading, -groupDepth / 2), + ]; + crosswalkPavements.push({ + type: 'Feature', + properties: { + native_id: `complex-crosswalk-pavement:${cluster.id}:${item.approach.segmentId}`, + object_key: `crossing:${arm.key}`, + crossing_key: `crossing:${arm.key}`, + arm_key: arm.key, + cluster_id: cluster.id, + kind: 'complex-crosswalk-pavement', + complex_part: 'crosswalk-pavement', + road_id: item.approach.roadIds[0], + provenance: 'native-road-complex-junction-crosswalk-pavement/v1', + }, + geometry: { type: 'Polygon', coordinates: [pavementRing] }, + }); for (let stripe = 0; stripe < stripeCount; stripe += 1) { const along = layout.centers[stripe]; const centerPoint = helpers.offsetCoordinate(endpoints[0], bearing(...endpoints), along); @@ -606,6 +632,48 @@ function buildComplexJunctionGeometry(model, cluster, helpers) { const diagonalHeading = outwardHeading; const diagonalCenter = helpers.offsetCoordinate(outerMidpoint, outwardHeading, diagonalDepth / 2); const diagonalSpan = COMPLEX_CROSSWALK_DEPTH_METERS; + const diagonalPavementRing = [ + helpers.offsetCoordinate( + helpers.offsetCoordinate(diagonalCenter, diagonalHeading + 90, -diagonalSpan / 2), + diagonalHeading, + -diagonalDepth / 2, + ), + helpers.offsetCoordinate( + helpers.offsetCoordinate(diagonalCenter, diagonalHeading + 90, diagonalSpan / 2), + diagonalHeading, + -diagonalDepth / 2, + ), + helpers.offsetCoordinate( + helpers.offsetCoordinate(diagonalCenter, diagonalHeading + 90, diagonalSpan / 2), + diagonalHeading, + diagonalDepth / 2, + ), + helpers.offsetCoordinate( + helpers.offsetCoordinate(diagonalCenter, diagonalHeading + 90, -diagonalSpan / 2), + diagonalHeading, + diagonalDepth / 2, + ), + helpers.offsetCoordinate( + helpers.offsetCoordinate(diagonalCenter, diagonalHeading + 90, -diagonalSpan / 2), + diagonalHeading, + -diagonalDepth / 2, + ), + ]; + crosswalkPavements.push({ + type: 'Feature', + properties: { + native_id: `complex-corner-crosswalk-pavement:${cluster.id}:${index + 1}`, + object_key: `crossing:corner:${first.cornerKey}`, + crossing_key: `crossing:corner:${first.cornerKey}`, + island_key: `island:inferred/${first.cornerKey}`, + cluster_id: cluster.id, + kind: 'complex-crosswalk-pavement', + complex_part: 'crosswalk-pavement', + corner_key: first.cornerKey, + provenance: 'native-road-complex-junction-crosswalk-pavement/v1', + }, + geometry: { type: 'Polygon', coordinates: [diagonalPavementRing] }, + }); const layout = stripeLayout(diagonalDepth); const stripeCount = layout.centers.length; const stripeSpacing = layout.pitch; @@ -810,6 +878,7 @@ function buildComplexJunctionGeometry(model, cluster, helpers) { // Corner fills come last so they overlay the rectangular carriageway ends // they are smoothing; they never replace an OSM-derived road surface. features.push(...cornerFills); + features.push(...crosswalkPavements); if (coreFeature) features.push(coreFeature); // `coreRadiusMeters` is only consulted when there is no reference geometry. // Under calibration the radius comes from the reference span, so a configured diff --git a/test/junction-facility-composition.js b/test/junction-facility-composition.js index ef8a459..ae4962f 100644 --- a/test/junction-facility-composition.js +++ b/test/junction-facility-composition.js @@ -171,4 +171,30 @@ assert.equal(new Set(solvedContacts.greenRing.slice(0, -1).map((p) => p.join(',' assert.deepEqual(points, island.properties.contact_points); } assert.equal(geometry.diagnostics.filter((d) => d.rule === 'complex-junction-island-infeasible').length, 0); + + const pavementByCrossing = new Map( + geometry.roadSurface.features + .filter((feature) => feature.properties.kind === 'complex-crosswalk-pavement') + .map((feature) => [feature.properties.crossing_key, feature]), + ); + const ringArea = (ring) => + Math.abs( + ring.slice(1).reduce((sum, point, index) => sum + ring[index][0] * point[1] - point[0] * ring[index][1], 0) / 2, + ); + const residualArea = (multiPolygon) => + multiPolygon.reduce( + (sum, polygon) => + sum + ringArea(polygon[0]) - polygon.slice(1).reduce((holes, hole) => holes + ringArea(hole), 0), + 0, + ); + for (const stripe of geometry.crosswalks.features.filter( + (feature) => feature.properties.cluster_id === 'four-node-contact-regression', + )) { + const pavement = pavementByCrossing.get(stripe.properties.crossing_key); + assert.ok(pavement, `${stripe.properties.crossing_key} must publish crossing pavement`); + assert.ok( + residualArea(clipping.difference(stripe.geometry.coordinates, pavement.geometry.coordinates)) < 1e-10, + `${stripe.properties.native_id} must remain fully on its matching pavement`, + ); + } }