From 7a3eeacd87443bd5ace370edc458ffa628303010 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Thu, 15 Aug 2013 21:56:38 +0000 Subject: Make SkMatrix44::invert() check for finite 1/det instead of magic value Previously we were checking to see if the magnitude of determinant of the matrix to be inverted was less than 1.0e-8, which is a magic number possibly plucked from Graphics Gems. After some discussion, it's been determined (ha) that we can simply check to see if 1/det is finite and if so proceed. BUG=222926 R=reed@google.com, shawnsingh@chromium.org Author: jvanverth@google.com Review URL: https://chromiumcodereview.appspot.com/22904003 git-svn-id: http://skia.googlecode.com/svn/trunk@10758 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/Matrix44Test.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/Matrix44Test.cpp') diff --git a/tests/Matrix44Test.cpp b/tests/Matrix44Test.cpp index b2c7071b79..6783ba0275 100644 --- a/tests/Matrix44Test.cpp +++ b/tests/Matrix44Test.cpp @@ -403,6 +403,33 @@ static void TestMatrix44(skiatest::Reporter* reporter) { 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); -- cgit v1.2.3