decomposeRelativeTransform function
Implementation
RelativeTransform decomposeRelativeTransform(List<num>? t1) {
t1 ??= defaultGradientTransform();
// __ __
// |a c tx|
// |b d ty|
// -- --
final double a = t1[0].toDouble();
final double b = t1.length > 1 ? t1[1].toDouble() : 0;
final double c = t1.length > 2 ? t1[2].toDouble() : 0;
final double d = t1.length > 3 ? t1[3].toDouble() : 0;
final double tx = t1.length > 4 ? t1[4].toDouble() : 0;
final double ty = t1.length > 5 ? t1[5].toDouble() : 0;
final double delta = a * d - b * c;
List<double> translation = [tx, ty];
double rotation = 0;
List<double> scale = [0, 0];
List<double> skew = [0, 0];
// Apply the QR-like decomposition.
if (a != 0 || b != 0) {
final double r = sqrt(a * a + b * b);
rotation = b > 0 ? acos(a / r) : -acos(a / r);
scale = [r, delta / r];
skew = [atan((a * c + b * d) / (r * r)), 0];
} else if (c != 0 || d != 0) {
// these are not currently being used.
final double s = sqrt(c * c + d * d);
rotation = pi / 2 - (d > 0 ? acos(-c / s) : -acos(c / s));
scale = [delta / s, s];
skew = [0, atan((a * c + b * d) / (s * s))];
} else {
// a = b = c = d = 0
}
return RelativeTransform(
translation: translation,
rotation: rotation / pi * 180,
scale: scale,
skew: skew,
);
}