toCubics method

List<CubicBezier> toCubics(
  1. double progress
)

Returns this morph's shape at progress as a list of CubicBeziers.

progress runs from 0 at start to 1 at end, and a value in between gives a linear interpolation of the two. Values a little outside that range give an exaggerated effect, useful for a bounce or an overshoot, but values far outside it produce undefined shapes.

This creates and populates a new list on every call.

Implementation

List<CubicBezier> toCubics(double progress) {
  final matchCount = _morphMatch.length;

  if (matchCount == 0) return [];

  // The result has exactly one cubic per matched pair. The last cubic's end
  // anchor is replaced with the first cubic's start anchor, ensuring that
  // the final anchor point in the shape exactly matches the first anchor
  // point. There can be rendering artifacts introduced by those points being
  // slightly off, even by much less than a pixel.
  final (firstFrom, firstTo) = _morphMatch[0];
  final firstAnchor0X = lerp(firstFrom.anchor0X, firstTo.anchor0X, progress);
  final firstAnchor0Y = lerp(firstFrom.anchor0Y, firstTo.anchor0Y, progress);

  return .generate(matchCount, (i) {
    final (from, to) = _morphMatch[i];
    final isLast = i == matchCount - 1;

    return .raw(
      lerp(from.anchor0X, to.anchor0X, progress),
      lerp(from.anchor0Y, to.anchor0Y, progress),
      lerp(from.control0X, to.control0X, progress),
      lerp(from.control0Y, to.control0Y, progress),
      lerp(from.control1X, to.control1X, progress),
      lerp(from.control1Y, to.control1Y, progress),
      isLast ? firstAnchor0X : lerp(from.anchor1X, to.anchor1X, progress),
      isLast ? firstAnchor0Y : lerp(from.anchor1Y, to.anchor1Y, progress),
    );
  }, growable: false);
}