diff --git a/public/js/app.js b/public/js/app.js index a259e33..edf5463 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -980,22 +980,34 @@ const pts = [start, end].slice().sort((a, b) => a[0] - b[0] || a[1] - b[1]); const isForward = (start[0] === pts[0][0] && start[1] === pts[0][1]); - // Calculate a stable seed for this unique pair of coordinates - // This ensures that different paths (e.g., A-B vs C-D) always have slightly different curvatures - const pathHash = Math.abs(Math.sin(pts[0][0] * 12.9898 + pts[0][1] * 78.233 + pts[1][0] * 43.123 + pts[1][1] * 21.312)); - - // Base curvature: 0.12 - 0.25 (depends on distance and geographical coordinates) - const dist = Math.sqrt(Math.pow(end[0] - start[0], 2) + Math.pow(end[1] - start[1], 2)); - const baseCurve = 0.12 + Math.min(0.08, dist / 1000) + (pathHash * 0.05); + // Geometry metrics for crossing and overlap prevention + const dx = end[0] - start[0]; + const dy = end[1] - start[1]; + const dist = Math.sqrt(dx * dx + dy * dy); + const midLat = (start[1] + end[1]) / 2; - // Eye-pattern spreading: - // A->B and B->A will always take opposite sides of the path. - // Multiple connections between the same points will spread outward. + // 1. Layering: Group paths into "Regional" vs "Long-Haul" + // Long-distance spans (e.g. trans-oceanic) use higher arcs to "jump over" regional traffic + const isLongHaul = dist > 120; + const baseHeight = isLongHaul ? 0.38 : 0.18; + + // 2. Global Routing Bias (Pole-ward Filtering): + // This is the most effective way to reduce global intersections. + // Lines in the Northern Hemisphere curve North, lines in the Southern curve South. + const poleDir = (midLat >= 0 ? 1 : -1); + const dirFactor = poleDir * (isForward ? 1 : -1); + + // 3. Proximity Differentiator: Hash coordinates to prevent similar paths from aligning exactly + const pathHash = Math.abs(Math.sin(pts[0][0] * 12.9898 + pts[1][0] * 78.233 + pts[0][1] * 43.123 + pts[1][1] * 21.312)); + const pathJitter = (pathHash * 0.12) - 0.06; // Stable offset for each unique (source, dest) pair + + // 4. Overlap Spreading: Symmetric eye-pattern for bi-directional and multi-session traffic const spreadIndex = Math.floor(i / 2); const spreadSign = (i % 2 === 0 ? 1 : -1); - const spreadFactor = spreadSign * (1 + spreadIndex * 0.5); + const spreadFactor = spreadSign * (1 + spreadIndex * 0.45); - const finalCurve = baseCurve * spreadFactor * (isForward ? 1 : -1); + // Combine all rules: dirFactor + spreadSign ensures the "primary" line always heads toward the pole + const finalCurve = (baseHeight * dirFactor * spreadFactor) + pathJitter; finalSeries.push({ type: 'lines',