interpolateZoomRho function Zoom interpolation

ZoomInterpolator Function(View, View) interpolateZoomRho(
  1. num rho
)

Returns a new zoom interpolator using the specified curvature rho.

When rho is close to 0, the interpolator is almost linear. The default curvature is sqrt(2).

Implementation

ZoomInterpolator Function(View, View) interpolateZoomRho(num rho) {
  var rho_ = max(1e-3, rho), rho2 = rho_ * rho_, rho4 = rho2 * rho2;

  return (a, b) {
    var (ux0, uy0, w0) = a;
    var (ux1, uy1, w1) = b;

    num dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, S;

    // Special case for u0 ≅ u1.
    if (d2 < _epsilon2) {
      S = log(w1 / w0) / rho_;
      return _EspecialZoomInterpolator(rho_, S, ux0, uy0, w0, dx, dy);
    }

    // General case.
    else {
      var d1 = sqrt(d2),
          b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
          b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
          r0 = log(sqrt(b0 * b0 + 1) - b0),
          r1 = log(sqrt(b1 * b1 + 1) - b1);
      S = (r1 - r0) / rho_;
      return _GeneralZoomInterpolator(
          rho_, rho2, S, ux0, uy0, w0, dx, dy, d1, r0);
    }
  };
}