aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Matrix44Test.cpp
diff options
context:
space:
mode:
authorGravatar vollick@chromium.org <vollick@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-13 15:08:22 +0000
committerGravatar vollick@chromium.org <vollick@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-13 15:08:22 +0000
commit3959a76ab086a4adbdb9d48977fa276ce0213cb1 (patch)
tree807dae9f99efbb9ed854151df1823e961bf1e22c /tests/Matrix44Test.cpp
parent30c174b9ce6b9777ee50ae0d0565a01b2a060f01 (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
Diffstat (limited to 'tests/Matrix44Test.cpp')
-rw-r--r--tests/Matrix44Test.cpp35
1 files changed, 35 insertions, 0 deletions
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
}