lerp method
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
.
Implementation
static RRect lerp(RRect a, RRect b, double t) {
assert(t != null);
if (a == null && b == null)
return null;
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,
);
}
if (b == null) {
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,
);
}
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),
);
}