levelPathNodeCenter function

Offset levelPathNodeCenter(
  1. int index,
  2. double width, {
  3. double rowHeight = 96,
  4. double amplitude = 0.62,
})

Pure math helper: computes center position of node index along an S-curve saga path (FEAT-133).

Implementation

Offset levelPathNodeCenter(
  int index,
  double width, {
  double rowHeight = 96,
  double amplitude = 0.62,
}) {
  if (width <= 0) {
    throw ArgumentError.value(width, 'width', 'must be positive');
  }
  if (rowHeight <= 0) {
    throw ArgumentError.value(rowHeight, 'rowHeight', 'must be positive');
  }
  final xCenter = width / 2;
  final xOffset = math.sin(index * math.pi / 2) * (width * amplitude / 2);
  final y = (index + 0.5) * rowHeight;
  return Offset(xCenter + xOffset, y);
}