constantAccelerationEaseInOutWithInitialVelocity function

double constantAccelerationEaseInOutWithInitialVelocity(
  1. double t,
  2. double initialVelocity
)

Implementation

double constantAccelerationEaseInOutWithInitialVelocity(
    double t, double initialVelocity) {
  if (t >= 1) {
    return 1;
  }
  double sqrtPart = sqrt(2 * sq(initialVelocity) - 4 * initialVelocity + 4);
  double m =
      (2 - initialVelocity + (initialVelocity < 2 ? sqrtPart : -sqrtPart)) / 2;
  double ax = -initialVelocity / (2 * m);
  double ay = initialVelocity * ax / 2;
  double h = (ax + 1) / 2;
  if (t < h) {
    return m * sq(t - ax) + ay;
  } else {
    return -m * sq(t - 1) + 1;
  }
}