transformInternal method
- double t
override
Returns the value of the curve at point t
.
The given parametric value t
will be between 0.0 and 1.0, inclusive.
Implementation
@override
double transformInternal(double t) {
// Linearly interpolate between the two closest samples generated when the
// curve was created.
if (_precomputedSamples.isEmpty) {
// Compute the samples now if we were constructed lazily.
_precomputedSamples.addAll(_computeSamples(controlPoints, tension));
}
int start = 0;
int end = _precomputedSamples.length - 1;
int mid;
Offset value;
Offset startValue = _precomputedSamples[start].value;
Offset endValue = _precomputedSamples[end].value;
// Use a binary search to find the index of the sample point that is just
// before t.
while (end - start > 1) {
mid = (end + start) ~/ 2;
value = _precomputedSamples[mid].value;
if (t >= value.dx) {
start = mid;
startValue = value;
} else {
end = mid;
endValue = value;
}
}
// Now interpolate between the found sample and the next one.
final double t2 = (t - startValue.dx) / (endValue.dx - startValue.dx);
return lerpDouble(startValue.dy, endValue.dy, t2)!;
}