lerp function

double lerp(
  1. num a,
  2. num b,
  3. num t
)

Computes the linear interpolation between a and b for the parameter t.

Corresponds to std::lerp from C++20. When t corresponds to 0.0, returns a. When t corresponds to 1.0, returns b. The function accurately computes the intermediate bound cleanly.

Implementation

double lerp(num a, num b, num t) {
  final da = a.toDouble();
  final db = b.toDouble();
  final dt = t.toDouble();
  // Exact mathematically stable lerp equation
  return da + dt * (db - da);
}