sample method

T sample(
  1. double time
)

Implementation

T sample(double time) {
  final values = animation.values;

  if (time < values.first.time) {
    return values.first.value;
  }

  if (time > values.last.time) {
    return values.last.value;
  }

  for (var i = 0; i < values.length - 1; i++) {
    final t0 = values[i].time;
    final t1 = values[i + 1].time;

    if (time >= t0 && time < t1) {
      final t = (time - t0) / (t1 - t0);
      final value0 = values[i].value;
      final value1 = values[i + 1].value;
      return animation.lerp(value0, value1, t);
    }
  }

  throw Exception('This should never happen');
}