From b54d3a1c50317c2322fe309432e36e8c879da394 Mon Sep 17 00:00:00 2001 From: trancen Date: Tue, 3 Feb 2026 21:20:40 +0000 Subject: [PATCH] fix(grayline): Fix splitAtDateLine to handle full-world spanning lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a line spans the full 360° from -180 to 180 with no jumps, the previous logic couldn't detect the date line crossing. Solution: Detect full-world span (>350°) and split at longitude 0, creating separate segments for western (-180 to 0) and eastern (0 to 180) hemispheres. This ensures the Enhanced DX Zone polygon wraps correctly. --- src/plugins/layers/useGrayLine.js | 48 +++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/plugins/layers/useGrayLine.js b/src/plugins/layers/useGrayLine.js index 41bf38f..fbd9ee0 100644 --- a/src/plugins/layers/useGrayLine.js +++ b/src/plugins/layers/useGrayLine.js @@ -104,6 +104,49 @@ function calculateSolarAltitude(date, latitude, longitude) { function splitAtDateLine(points) { if (points.length < 2) return [points]; + // Check if line spans the full world (-180 to 180) + const lons = points.map(p => p[1]); + const minLon = Math.min(...lons); + const maxLon = Math.max(...lons); + const span = maxLon - minLon; + + console.log('🔍 splitAtDateLine debug:', { + totalPoints: points.length, + lonRange: `${minLon.toFixed(1)} to ${maxLon.toFixed(1)}`, + span: span.toFixed(1) + }); + + // If the line spans close to 360°, it wraps around the world + // We need to split it at the ±180° boundary + if (span > 350) { + console.log('🔍 Full-world span detected, splitting at ±180°'); + + // Find where the line crosses from negative to positive (near ±180°) + // Split into: [points with lon < 0] and [points with lon >= 0] + const westSegment = []; // Points from -180 to ~0 + const eastSegment = []; // Points from ~0 to 180 + + for (let i = 0; i < points.length; i++) { + const lon = points[i][1]; + + // Split around longitude 0 or at the extremes + // Points near -180 and near +180 should be in different segments + if (lon < 0) { + westSegment.push(points[i]); + } else { + eastSegment.push(points[i]); + } + } + + const segments = []; + if (westSegment.length >= 2) segments.push(westSegment); + if (eastSegment.length >= 2) segments.push(eastSegment); + + console.log('🔍 Split into segments:', segments.map(s => s.length), 'points'); + return segments; + } + + // Otherwise, check for sudden longitude jumps (traditional date line crossing) const segments = []; let currentSegment = [points[0]]; @@ -116,20 +159,19 @@ function splitAtDateLine(points) { // If longitude jumps more than 180°, we've crossed the date line if (lonDiff > 180) { - // Finish current segment + console.log(`🔍 Date line jump detected at index ${i}: ${prevLon.toFixed(1)}° → ${currLon.toFixed(1)}°`); segments.push(currentSegment); - // Start new segment currentSegment = [curr]; } else { currentSegment.push(curr); } } - // Add final segment if (currentSegment.length > 0) { segments.push(currentSegment); } + console.log('🔍 splitAtDateLine result:', segments.length, 'segments'); return segments.filter(seg => seg.length >= 2); }