lerp method
Returns a lerped value based on theta.
Implementation
@override
T lerp(double t) {
if (t <= 0.0) {
return _values.first.value;
}
if (t >= 1.0) {
return _values.last.value;
}
if (_pair == null ||
_pair!.b.percent < t * 100.0 ||
_pair!.a.percent > t * 100.0) {
_pair = fetchFromTo(t);
}
if (t * 100.0 <= _pair!.a.percent) {
return _pair!.a.value;
}
if (t * 100.0 >= _pair!.b.percent) {
return _pair!.b.value;
}
final n = _pair!.a.curve.transform(
(t * 100.0 - _pair!.a.percent) / (_pair!.b.percent - _pair!.a.percent));
if (T == Matrix4) {
final Vector3 beginTranslation = Vector3.zero();
final Vector3 endTranslation = Vector3.zero();
final Quaternion beginRotation = Quaternion.identity();
final Quaternion endRotation = Quaternion.identity();
final Vector3 beginScale = Vector3.zero();
final Vector3 endScale = Vector3.zero();
_pair!.a.value.decompose(beginTranslation, beginRotation, beginScale);
_pair!.b.value.decompose(endTranslation, endRotation, endScale);
final Vector3 lerpTranslation =
beginTranslation * (1.0 - n) + endTranslation * n;
final Quaternion lerpRotation =
qlerp(beginRotation, endRotation, n).normalized();
final Vector3 lerpScale = beginScale * (1.0 - n) + endScale * n;
return Matrix4.compose(lerpTranslation, lerpRotation, lerpScale) as T;
}
if (T == int) {
return (_pair!.a.value + n * (_pair!.b.value - _pair!.a.value)).round();
}
if (T == Color) {
return Color.lerp(_pair!.a.value as Color, _pair!.b.value as Color, n)
as T;
}
if (T == Offset) {
return Offset.lerp(_pair!.a.value as Offset, _pair!.b.value as Offset, n)
as T;
}
if (T == Size) {
return Size.lerp(_pair!.a.value as Size, _pair!.b.value as Size, n) as T;
}
if (T == Rect) {
return Rect.lerp(_pair!.a.value as Rect, _pair!.b.value as Rect, n) as T;
}
return _pair!.a.value + n * (_pair!.b.value - _pair!.a.value) as T;
}