function invert(out, a) {
  let aa = a[0],
    ab = a[1],
    ac = a[2],
    ad = a[3];
  let atx = a[4],
    aty = a[5];

  let det = aa * ad - ab * ac;
  if (!det) {
    return null;
  }
  det = 1.0 / det;

  out[0] = ad * det;
  out[1] = -ab * det;
  out[2] = -ac * det;
  out[3] = aa * det;
  out[4] = (ac * aty - ad * atx) * det;
  out[5] = (ab * atx - aa * aty) * det;
  return out;
}
Inverts a mat2d

@param {mat2d} out the receiving matrix
@param {ReadonlyMat2d} a the source matrix
@returns {mat2d | null} out, or null if source matrix is not invertible