diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-06-13 14:46:52 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-06-13 14:46:52 +0000 |
commit | da9fac0aa13d1445f8b58a75d9390638845c814d (patch) | |
tree | d5e7e189d1e5fe3caa0d074e6625a0ca09b9b4d5 /tests | |
parent | 8260a895869beaa4cab9f8b915e457728f41e561 (diff) |
add row/col major getters, plus unit-tests
git-svn-id: http://skia.googlecode.com/svn/trunk@1564 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Matrix44Test.cpp | 62 | ||||
-rw-r--r-- | tests/tests_files.mk | 1 |
2 files changed, 60 insertions, 3 deletions
diff --git a/tests/Matrix44Test.cpp b/tests/Matrix44Test.cpp index 8755bd32b2..6ee70eb40f 100644 --- a/tests/Matrix44Test.cpp +++ b/tests/Matrix44Test.cpp @@ -1,7 +1,7 @@ #include "Test.h" #include "SkMatrix44.h" -static bool nearly_equal_scalar(SkScalar a, SkScalar b) { +static bool nearly_equal_scalar(SkMScalar a, SkMScalar b) { // Note that we get more compounded error for multiple operations when // SK_SCALAR_IS_FIXED. #ifdef SK_SCALAR_IS_FLOAT @@ -13,11 +13,37 @@ static bool nearly_equal_scalar(SkScalar a, SkScalar b) { return SkScalarAbs(a - b) <= tolerance; } +template <typename T> void assert16(skiatest::Reporter* reporter, const T data[], + T m0, T m1, T m2, T m3, + T m4, T m5, T m6, T m7, + T m8, T m9, T m10, T m11, + T m12, T m13, T m14, T m15) { + REPORTER_ASSERT(reporter, data[0] == m0); + REPORTER_ASSERT(reporter, data[1] == m1); + REPORTER_ASSERT(reporter, data[2] == m2); + REPORTER_ASSERT(reporter, data[3] == m3); + + REPORTER_ASSERT(reporter, data[4] == m4); + REPORTER_ASSERT(reporter, data[5] == m5); + REPORTER_ASSERT(reporter, data[6] == m6); + REPORTER_ASSERT(reporter, data[7] == m7); + + REPORTER_ASSERT(reporter, data[8] == m8); + REPORTER_ASSERT(reporter, data[9] == m9); + REPORTER_ASSERT(reporter, data[10] == m10); + REPORTER_ASSERT(reporter, data[11] == m11); + + REPORTER_ASSERT(reporter, data[12] == m12); + REPORTER_ASSERT(reporter, data[13] == m13); + REPORTER_ASSERT(reporter, data[14] == m14); + REPORTER_ASSERT(reporter, data[15] == m15); +} + static bool nearly_equal(const SkMatrix44& a, const SkMatrix44& b) { for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { if (!nearly_equal_scalar(a.get(i, j), b.get(i, j))) { - printf("not equal %g %g\n", (float)a.get(i, j), (float)b.get(i, j)); + printf("not equal %g %g\n", a.get(i, j), b.get(i, j)); return false; } } @@ -31,8 +57,8 @@ static bool is_identity(const SkMatrix44& m) { return nearly_equal(m, identity); } - void TestMatrix44(skiatest::Reporter* reporter) { +#ifdef SK_SCALAR_IS_FLOAT SkMatrix44 mat, inverse, iden1, iden2, rot; mat.reset(); @@ -64,6 +90,36 @@ void TestMatrix44(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, is_identity(iden1)); iden2.setConcat(inverse, mat); REPORTER_ASSERT(reporter, is_identity(iden2)); + + // test rol/col Major getters + { + mat.setTranslate(2, 3, 4); + float dataf[16]; + double datad[16]; + + mat.asColMajorf(dataf); + assert16<float>(reporter, dataf, + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 2, 3, 4, 1); + mat.asColMajord(datad); + assert16<double>(reporter, datad, 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 2, 3, 4, 1); + mat.asRowMajorf(dataf); + assert16<float>(reporter, dataf, 1, 0, 0, 2, + 0, 1, 0, 3, + 0, 0, 1, 4, + 0, 0, 0, 1); + mat.asRowMajord(datad); + assert16<double>(reporter, datad, 1, 0, 0, 2, + 0, 1, 0, 3, + 0, 0, 1, 4, + 0, 0, 0, 1); + } +#endif } #include "TestClassDef.h" diff --git a/tests/tests_files.mk b/tests/tests_files.mk index 667c9b5b84..595d000bfd 100644 --- a/tests/tests_files.mk +++ b/tests/tests_files.mk @@ -15,6 +15,7 @@ SOURCE := \ GeometryTest.cpp \ InfRectTest.cpp \ MathTest.cpp \ + Matrix44Test.cpp \ MatrixTest.cpp \ MetaDataTest.cpp \ PackBitsTest.cpp \ |