feat: serpentine map layout function
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user