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
This commit is contained in:
vollick@chromium.org 2012-11-13 15:08:22 +00:00
parent 30c174b9ce
commit 3959a76ab0
2 changed files with 37 additions and 2 deletions

View File

@ -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

View File

@ -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
}