watmough / glmatrix

Automatically exported from code.google.com/p/glmatrix
0 stars 1 forks source link

Return null early in inverse 3x3 #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
replace it by something like this:

    var a00 = mat[0], a01 = mat[1], a02 = mat[2];

    var b01 = a22*a11-a12*a21;
        var b11 = -a22*a10+a12*a20;
    var b21 = a21*a10-a11*a20;

    var d = a00 * b01 + a01 * b11 + a02 * b21;
    if (!d) { return null; }

    var a10 = mat[4], a11 = mat[5], a12 = mat[6];
    var a20 = mat[8], a21 = mat[9], a22 = mat[10];

    var b02 = -a22*a01+a02*a21;
    var b03 = a12*a01-a02*a11;
    var b12 = a22*a00-a02*a20;
    var b13 = -a12*a00+a02*a10;
    var b22 = -a21*a00+a01*a20;
    var b23 = a11*a00-a01*a10;

Original issue reported on code.google.com by danielhe...@gmail.com on 4 Jun 2010 at 8:11

GoogleCodeExporter commented 8 years ago
Interestingly enough when I benchmark this code in respect to the original 
version, the 
original is faster. I think that Javascript is taking advantage of memory 
locality, and 
therefore grouping code that references variables near one another (memory 
wise) may be 
faster. (just a theory)

Original comment by Tojiro@gmail.com on 5 Jun 2010 at 5:01

GoogleCodeExporter commented 8 years ago
This function has been reorganized, taking this issue into account.

Original comment by Tojiro@gmail.com on 5 Jun 2010 at 8:30