// Calculate the determinant
double det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
- if (dabs(det) < TOO_SMALL_FOR_DETERMINANT) {
+ double invdet = 1.0 / det;
+ // If det is zero, we want to return false. However, we also want to return false
+ // if 1/det overflows to infinity (i.e. det is denormalized). Both of these are
+ // handled by checking that 1/det is finite.
+ if (!sk_float_isfinite(invdet)) {
return false;
}
if (NULL == inverse) {
return true;
}
- double invdet = 1.0 / det;
b00 *= invdet;
b01 *= invdet;
inverse->fMat[3][3] = SkDoubleToMScalar(a20 * b03 - a21 * b01 + a22 * b00);
inverse->dirtyTypeMask();
- inverse->dirtyTypeMask();
return true;
}
iden2.setConcat(inverse, mat);
REPORTER_ASSERT(reporter, is_identity(iden2));
+ // test tiny-valued matrix inverse
+ mat.reset();
+ mat.setScale(1.0e-12, 1.0e-12, 1.0e-12);
+ rot.setRotateDegreesAbout(0, 0, -1, 90);
+ mat.postConcat(rot);
+ mat.postTranslate(1.0e-12, 1.0e-12, 1.0e-12);
+ REPORTER_ASSERT(reporter, mat.invert(NULL));
+ mat.invert(&inverse);
+ iden1.setConcat(mat, inverse);
+ REPORTER_ASSERT(reporter, is_identity(iden1));
+
+ // test mixed-valued matrix inverse
+ mat.reset();
+ mat.setScale(1.0e-12, 3.0, 1.0e+12);
+ rot.setRotateDegreesAbout(0, 0, -1, 90);
+ mat.postConcat(rot);
+ mat.postTranslate(1.0e+12, 3.0, 1.0e-12);
+ REPORTER_ASSERT(reporter, mat.invert(NULL));
+ mat.invert(&inverse);
+ iden1.setConcat(mat, inverse);
+ REPORTER_ASSERT(reporter, is_identity(iden1));
+
+ // test degenerate matrix
+ mat.reset();
+ mat.set3x3(1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0);
+ REPORTER_ASSERT(reporter, !mat.invert(NULL));
+
// test rol/col Major getters
{
mat.setTranslate(2, 3, 4);