lerp method

RRect lerp (
  1. RRect a,
  2. RRect b,
  3. double t

Linearly interpolate between two rounded rectangles.

If either is null, this function substitutes RRect.zero instead.

The t argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning a (or something equivalent to a), 1.0 meaning that the interpolation has finished, returning b (or something equivalent to b), and values in between meaning that the interpolation is at the relevant point on the timeline between a and b. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid (and can easily be generated by curves such as Curves.elasticInOut).

Values for t are usually obtained from an Animation<double>, such as an AnimationController.


static RRect? lerp(RRect? a, RRect? b, double t) {
  assert(t != null); // ignore: unnecessary_null_comparison
  if (b == null) {
    if (a == null) {
      return null;
    } else {
      final double k = 1.0 - t;
      return RRect._raw(
        left: a.left * k,
        top: a.top * k,
        right: a.right * k,
        bottom: a.bottom * k,
        tlRadiusX: a.tlRadiusX * k,
        tlRadiusY: a.tlRadiusY * k,
        trRadiusX: a.trRadiusX * k,
        trRadiusY: a.trRadiusY * k,
        brRadiusX: a.brRadiusX * k,
        brRadiusY: a.brRadiusY * k,
        blRadiusX: a.blRadiusX * k,
        blRadiusY: a.blRadiusY * k,
  } else {
    if (a == null) {
      return RRect._raw(
        left: b.left * t,
        top: b.top * t,
        right: b.right * t,
        bottom: b.bottom * t,
        tlRadiusX: b.tlRadiusX * t,
        tlRadiusY: b.tlRadiusY * t,
        trRadiusX: b.trRadiusX * t,
        trRadiusY: b.trRadiusY * t,
        brRadiusX: b.brRadiusX * t,
        brRadiusY: b.brRadiusY * t,
        blRadiusX: b.blRadiusX * t,
        blRadiusY: b.blRadiusY * t,
    } else {
      return RRect._raw(
        left: _lerpDouble(a.left, b.left, t),
        top: _lerpDouble(a.top, b.top, t),
        right: _lerpDouble(a.right, b.right, t),
        bottom: _lerpDouble(a.bottom, b.bottom, t),
        tlRadiusX: _lerpDouble(a.tlRadiusX, b.tlRadiusX, t),
        tlRadiusY: _lerpDouble(a.tlRadiusY, b.tlRadiusY, t),
        trRadiusX: _lerpDouble(a.trRadiusX, b.trRadiusX, t),
        trRadiusY: _lerpDouble(a.trRadiusY, b.trRadiusY, t),
        brRadiusX: _lerpDouble(a.brRadiusX, b.brRadiusX, t),
        brRadiusY: _lerpDouble(a.brRadiusY, b.brRadiusY, t),
        blRadiusX: _lerpDouble(a.blRadiusX, b.blRadiusX, t),
        blRadiusY: _lerpDouble(a.blRadiusY, b.blRadiusY, t),