diff options
author | vollick@chromium.org <vollick@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-11-13 15:08:22 +0000 |
---|---|---|
committer | vollick@chromium.org <vollick@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-11-13 15:08:22 +0000 |
commit | 3959a76ab086a4adbdb9d48977fa276ce0213cb1 (patch) | |
tree | 807dae9f99efbb9ed854151df1823e961bf1e22c | |
parent | 30c174b9ce6b9777ee50ae0d0565a01b2a060f01 (diff) |
Changing the visibility of SkMatrix44::determinant().
Review URL: https://codereview.appspot.com/6819080
git-svn-id: http://skia.googlecode.com/svn/trunk@6395 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/utils/SkMatrix44.h | 4 | ||||
-rw-r--r-- | tests/Matrix44Test.cpp | 35 |
2 files changed, 37 insertions, 2 deletions
diff --git a/include/utils/SkMatrix44.h b/include/utils/SkMatrix44.h index cff0d04a3d..8c6d0350dd 100644 --- a/include/utils/SkMatrix44.h +++ b/include/utils/SkMatrix44.h @@ -219,6 +219,8 @@ public: void dump() const; + double determinant() const; + private: /* Stored in the same order as opengl: [3][0] = tx @@ -226,8 +228,6 @@ private: [3][2] = tz */ SkMScalar fMat[4][4]; - - double determinant() const; }; #endif diff --git a/tests/Matrix44Test.cpp b/tests/Matrix44Test.cpp index 086321c1cf..af10e00d71 100644 --- a/tests/Matrix44Test.cpp +++ b/tests/Matrix44Test.cpp @@ -8,6 +8,14 @@ #include "Test.h" #include "SkMatrix44.h" +static bool nearly_equal_double(double a, double b) { + const double tolerance = 1e-7; + double diff = a - b; + if (diff < 0) + diff = -diff; + return diff <= tolerance; +} + static bool nearly_equal_scalar(SkMScalar a, SkMScalar b) { // Note that we get more compounded error for multiple operations when // SK_SCALAR_IS_FIXED. @@ -114,6 +122,31 @@ static void test_concat(skiatest::Reporter* reporter) { } } +static void test_determinant(skiatest::Reporter* reporter) { + SkMatrix44 a; + REPORTER_ASSERT(reporter, nearly_equal_double(1, a.determinant())); + a.set(1, 1, SkFloatToMScalar(2)); + REPORTER_ASSERT(reporter, nearly_equal_double(2, a.determinant())); + SkMatrix44 b; + REPORTER_ASSERT(reporter, a.invert(&b)); + REPORTER_ASSERT(reporter, nearly_equal_double(0.5, b.determinant())); + SkMatrix44 c = b = a; + c.set(0, 1, SkFloatToMScalar(4)); + b.set(1, 0, SkFloatToMScalar(4)); + REPORTER_ASSERT(reporter, + nearly_equal_double(a.determinant(), + b.determinant())); + SkMatrix44 d = a; + d.set(0, 0, SkFloatToMScalar(8)); + REPORTER_ASSERT(reporter, nearly_equal_double(16, d.determinant())); + + SkMatrix44 e = a; + e.postConcat(d); + REPORTER_ASSERT(reporter, nearly_equal_double(32, e.determinant())); + e.set(0, 0, SkFloatToMScalar(0)); + REPORTER_ASSERT(reporter, nearly_equal_double(0, e.determinant())); +} + static void TestMatrix44(skiatest::Reporter* reporter) { #ifdef SK_SCALAR_IS_FLOAT SkMatrix44 mat, inverse, iden1, iden2, rot; @@ -182,6 +215,8 @@ static void TestMatrix44(skiatest::Reporter* reporter) { if (false) { // avoid bit rot, suppress warning (working on making this pass) test_common_angles(reporter); } + + test_determinant(reporter); #endif } |