Logo Search packages:      
Sourcecode: inkscape version File versions

Matrix NR::Matrix::inverse (  )  const

Return the inverse of this matrix. If an inverse is not defined, then return the identity matrix.

Definition at line 267 of file nr-matrix.cpp.

References _c, det(), and set_identity().

Referenced by sp_item_adjust_paint_recursive(), sp_item_write_transform(), and sp_nodepath_new().

{
    Matrix d(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);

    NR::Coord const det = _c[0] * _c[3] - _c[1] * _c[2];
    if (!NR_DF_TEST_CLOSE(det, 0.0, NR_EPSILON)) {

        NR::Coord const idet = 1.0 / det;
        NR::Coord *dest = d._c;

        /*0*/ *dest++ =  _c[3] * idet;
        /*1*/ *dest++ = -_c[1] * idet;
        /*2*/ *dest++ = -_c[2] * idet;
        /*3*/ *dest++ =  _c[0] * idet;
        /*4*/ *dest++ = -_c[4] * d._c[0] - _c[5] * d._c[2];
        /*5*/ *dest   = -_c[4] * d._c[1] - _c[5] * d._c[3];

    } else {
        d.set_identity();
    }

    return d;
}


Generated by  Doxygen 1.6.0   Back to index