asCubics method

List<Cubic> asCubics(
  1. double progress
)

Returns a representation of the morph object at a given progress value as a list of Cubics. Note that this function causes a new list to be created and populated, so there is some overhead.

progress is a value from 0 to 1 that determines the morph's current shape, between the start and end shapes provided at construction time. A value of 0 results in the start shape, a value of 1 results in the end shape, and any value in between results in a shape which is a linear interpolation between those two shapes.

The range is generally 0..1 and values outside could result in undefined shapes, but values close to (but outside) the range can be used to get an exaggerated effect (e.g., for a bounce or overshoot animation).

Implementation

List<Cubic> asCubics(double progress) {
  final result = <Cubic>[];

  // The first/last mechanism here ensures 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.
  Cubic? firstCubic;
  Cubic? lastCubic;

  for (var i = 0; i < _morphMatch.length; i++) {
    final cubic = Cubic._raw(
      List<double>.generate(8, (j) {
        return lerp(
          _morphMatch[i].$1.points[j],
          _morphMatch[i].$2.points[j],
          progress,
        );
      }),
    );

    firstCubic ??= cubic;
    if (lastCubic != null) {
      result.add(lastCubic);
    }
    lastCubic = cubic;
  }

  if (lastCubic != null && firstCubic != null) {
    result.add(
      Cubic(
        lastCubic.anchor0X,
        lastCubic.anchor0Y,
        lastCubic.control0X,
        lastCubic.control0Y,
        lastCubic.control1X,
        lastCubic.control1Y,
        firstCubic.anchor0X,
        firstCubic.anchor0Y,
      ),
    );
  }

  return result;
}