invert function
Inverts a mat2
@param {mat2} out the receiving matrix @param {ReadonlyMat2} a the source matrix @returns {mat2} out
Implementation
List<double>? invert(List<double> out, List<double> a) {
double a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
// Calculate the determinant
double det = a0 * a3 - a2 * a1;
if (det == 0) {
return null;
}
det = 1.0 / det;
out[0] = a3 * det;
out[1] = -a1 * det;
out[2] = -a2 * det;
out[3] = a0 * det;
return out;
}