feat: serpentine map layout function

This commit is contained in:
2026-06-11 23:12:29 +09:00
parent ee364cc2e2
commit 96304cc8a7
2 changed files with 61 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import 'dart:math' as math;
import 'dart:ui';
/// Deterministic serpentine layout for the journey map. Stage 0 is at the
/// bottom; the path snakes upward. Works for any stage count.
class MapLayout {
const MapLayout({
required this.width,
this.nodeSpacing = 108,
this.topPadding = 140,
this.bottomPadding = 150,
});
final double width;
final double nodeSpacing;
final double topPadding;
final double bottomPadding;
double get amplitude => width * 0.26;
double heightFor(int count) =>
topPadding + bottomPadding + (count - 1) * nodeSpacing;
Offset nodeCenter(int index, int count) {
final y = heightFor(count) - bottomPadding - index * nodeSpacing;
final x = width / 2 + amplitude * math.sin(index * 1.05);
return Offset(x, y);
}
}