优化算法

This commit is contained in:
CN-JS-HuiBai
2026-04-06 19:35:30 +08:00
parent 3bdde47c60
commit 92f97b7e51

View File

@@ -976,23 +976,19 @@
const pts = [start, end].slice().sort((a, b) => a[0] - b[0] || a[1] - b[1]);
const isForward = (start === pts[0]);
// Calculate curveness: ensure all lines are slightly curved
// Use a canonical hash of the route endpoints to deterministically decide the curve direction
// This helps spread lines across the map even for single routes
const names = [route.source, route.dest].sort();
const routeHash = (names[0] + names[1]).split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
const baseSign = (routeHash % 2 === 0 ? 1 : -1);
// Simplified calculation to reduce crossings
// Maintaining a consistent direction for single lines ensures that parallel paths stay parallel
let finalCurve = 0;
if (count === 1) {
// Single lines get a decent curve, alternating direction based on hash
finalCurve = 0.2 * baseSign;
// Subtle consistent curve for single routes
finalCurve = 0.12;
} else {
// Multiple lines between same points fan out with increasing magnitude
const magnitude = 0.2 + Math.floor(i / 2) * 0.15;
// Symmetrical fan-out for multiple lines between the same points
// This spreads them cleanly into "eye" shapes without biased clustering
const magnitude = 0.12 + Math.floor(i / 2) * 0.12;
const spread = (i % 2 === 0) ? magnitude : -magnitude;
// Apply baseSign to ensure the whole group isn't biased to one side
finalCurve = isForward ? (spread * baseSign) : (-spread * baseSign);
// Ensure visual consistency regardless of the data direction (A->B or B->A)
finalCurve = isForward ? spread : -spread;
}
finalSeries.push({