easeValVel function

(double, double) easeValVel(
  1. double startValue,
  2. double endValue,
  3. double startTime,
  4. double endTime,
  5. double currentTime,
  6. double initialVelocity,
)

Implementation

(double, double) easeValVel(
  double startValue,
  double endValue,
  double startTime,
  double endTime,
  double currentTime,
  double initialVelocity,
) {
  if (startTime == double.negativeInfinity || startValue == endValue) {
    return (endValue, 0.0);
  }
  double normalizedTime = (currentTime - startTime) / (endTime - startTime);
  double normalizedVelocity =
      initialVelocity / (endValue - startValue) * (endTime - startTime);

  late double normalizedPOut, normalizedVelOut;
  if (normalizedVelocity > 2) {
    normalizedPOut = linearAccelerationEaseInOutWithInitialVelocity(
        normalizedTime, normalizedVelocity);
    normalizedVelOut = velocityOfLinearAccelerationEaseInOutWithInitialVelocity(
        normalizedTime, normalizedVelocity);
  } else {
    normalizedPOut = constantAccelerationEaseInOutWithInitialVelocity(
        normalizedTime, normalizedVelocity);
    normalizedVelOut =
        velocityOfConstantAccelerationEaseInOutWithInitialVelocity(
            normalizedTime, normalizedVelocity);
  }
  return (
    startValue + normalizedPOut * (endValue - startValue),
    normalizedVelOut * (endValue - startValue) / (endTime - startTime),
  );
}