/**
 * Performs matrix multiplication of 3x3 matrices
 * r = a * b
 * @param {number[]|Float32Array} r result matrix
 * @param {number[]|Float32Array} a first matrix
 * @param {number[]|Float32Array} b second matrix
 */
export function m3_multiply(r, a, b) {
    //read out values of input matrices to support the case where result is written back into one of the inputs
    const a0 = a[0];
    const a1 = a[1];
    const a2 = a[2];

    const a3 = a[3];
    const a4 = a[4];
    const a5 = a[5];

    const a6 = a[6];
    const a7 = a[7];
    const a8 = a[8];


    const b0 = b[0];
    const b1 = b[1];
    const b2 = b[2];

    const b3 = b[3];
    const b4 = b[4];
    const b5 = b[5];

    const b6 = b[6];
    const b7 = b[7];
    const b8 = b[8];

    //produce first row
    r[0] = a0 * b0 + a1 * b3 + a2 * b6;
    r[1] = a0 * b1 + a1 * b4 + a2 * b7;
    r[2] = a0 * b2 + a1 * b5 + a2 * b8;

    //produce second row
    r[3] = a3 * b0 + a4 * b3 + a5 * b6;
    r[4] = a3 * b1 + a4 * b4 + a5 * b7;
    r[5] = a3 * b2 + a4 * b5 + a5 * b8;

    //produce third row
    r[6] = a6 * b0 + a7 * b3 + a8 * b6;
    r[7] = a6 * b1 + a7 * b4 + a8 * b7;
    r[8] = a6 * b2 + a7 * b5 + a8 * b8;
}
