lerp2DMatrix static method

List lerp2DMatrix(
  1. List matrixA,
  2. List matrixB,
  3. double t
)

Implementation

static List lerp2DMatrix(List matrixA, List matrixB, double t) {
  // If x-axis of one is flipped, and y-axis of the other,
  // convert to an unflipped rotation.

  List<double> scaleA = matrixA[1];
  double angleA = matrixA[2];

  List<double> scaleB = matrixB[1];
  double angleB = matrixB[2];

  if ((scaleA[0] < 0 && scaleB[1] < 0) || (scaleA[1] < 0 && scaleB[0] < 0)) {
    scaleA[0] = -scaleA[0];
    scaleA[1] = -scaleA[1];
    angleA += angleA < 0 ? 180 : -180;
  }

  // Don’t rotate the long way around.
  if (angleA == 0)
    angleA = 360;
  if (angleB == 0)
    angleB = 360;

  if ((angleA - angleB).abs() > 180) {
    if (angleA > angleB)
      angleA -= 360;
    else
      angleB -= 360;
  }

  List<double> translate = _lerpFloat64List(matrixA[0], matrixB[0], t);
  List<double> scale = _lerpFloat64List(matrixA[1], matrixB[1], t);
  double angle = _lerpDouble(angleA, angleB, t);
  double m11 = _lerpDouble(matrixA[3], matrixB[3], t);
  double m12 = _lerpDouble(matrixA[4], matrixB[4], t);
  double m21 = _lerpDouble(matrixA[5], matrixB[5], t);
  double m22 = _lerpDouble(matrixA[6], matrixB[6], t);

  return [translate, scale, angle, m11, m12, m21, m22];
}