Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(801)

Unified Diff: tests/Matrix44Test.cpp

Issue 22886010: Add perf benchmarks and more unit tests for matrix inversion (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bench/Matrix44Bench.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/Matrix44Test.cpp
===================================================================
--- tests/Matrix44Test.cpp (revision 10801)
+++ tests/Matrix44Test.cpp (working copy)
@@ -319,6 +319,103 @@
REPORTER_ASSERT(reporter, nearly_equal_double(0, e.determinant()));
}
+static void test_invert(skiatest::Reporter* reporter) {
+ SkMatrix44 inverse;
+ double inverseData[16];
+
+ SkMatrix44 identity;
+ identity.setIdentity();
+ identity.invert(&inverse);
+ inverse.asRowMajord(inverseData);
+ assert16<double>(reporter, inverseData,
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1);
+
+ SkMatrix44 translation;
+ translation.setTranslate(2, 3, 4);
+ translation.invert(&inverse);
+ inverse.asRowMajord(inverseData);
+ assert16<double>(reporter, inverseData,
+ 1, 0, 0, -2,
+ 0, 1, 0, -3,
+ 0, 0, 1, -4,
+ 0, 0, 0, 1);
+
+ SkMatrix44 scale;
+ scale.setScale(2, 4, 8);
+ scale.invert(&inverse);
+ inverse.asRowMajord(inverseData);
+ assert16<double>(reporter, inverseData,
+ 0.5, 0, 0, 0,
+ 0, 0.25, 0, 0,
+ 0, 0, 0.125, 0,
+ 0, 0, 0, 1);
+
+ SkMatrix44 scaleTranslation;
+ scaleTranslation.setScale(10, 100, 1000);
+ scaleTranslation.preTranslate(2, 3, 4);
+ scaleTranslation.invert(&inverse);
+ inverse.asRowMajord(inverseData);
+ assert16<double>(reporter, inverseData,
+ 0.1, 0, 0, -2,
+ 0, 0.01, 0, -3,
+ 0, 0, 0.001, -4,
+ 0, 0, 0, 1);
+
+ SkMatrix44 rotation;
+ rotation.setRotateDegreesAbout(0, 0, 1, 90);
+ rotation.invert(&inverse);
+ SkMatrix44 expected;
+ double expectedInverseRotation[16] =
+ {0, 1, 0, 0,
+ -1, 0, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1};
+ expected.setRowMajord(expectedInverseRotation);
+ REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));
+
+ SkMatrix44 affine;
+ affine.setRotateDegreesAbout(0, 0, 1, 90);
+ affine.preScale(10, 20, 100);
+ affine.preTranslate(2, 3, 4);
+ affine.invert(&inverse);
+ double expectedInverseAffine[16] =
+ {0, 0.1, 0, -2,
+ -0.05, 0, 0, -3,
+ 0, 0, 0.01, -4,
+ 0, 0, 0, 1};
+ expected.setRowMajord(expectedInverseAffine);
+ REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));
+
+ SkMatrix44 perspective;
+ perspective.setIdentity();
+ perspective.setDouble(3, 2, 1.0);
+ perspective.invert(&inverse);
+ double expectedInversePerspective[16] =
+ {1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, -1, 1};
+ expected.setRowMajord(expectedInversePerspective);
+ REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));
+
+ SkMatrix44 affineAndPerspective;
+ affineAndPerspective.setIdentity();
+ affineAndPerspective.setDouble(3, 2, 1.0);
+ affineAndPerspective.preScale(10, 20, 100);
+ affineAndPerspective.preTranslate(2, 3, 4);
+ affineAndPerspective.invert(&inverse);
+ double expectedInverseAffineAndPerspective[16] =
+ {0.1, 0, 2, -2,
+ 0, 0.05, 3, -3,
+ 0, 0, 4.01, -4,
+ 0, 0, -1, 1};
+ expected.setRowMajord(expectedInverseAffineAndPerspective);
+ REPORTER_ASSERT(reporter, nearly_equal(expected, inverse));
+}
+
static void test_transpose(skiatest::Reporter* reporter) {
SkMatrix44 a;
SkMatrix44 b;
@@ -441,6 +538,7 @@
test_constructor(reporter);
test_gettype(reporter);
test_determinant(reporter);
+ test_invert(reporter);
test_transpose(reporter);
test_get_set_double(reporter);
test_set_row_col_major(reporter);
« no previous file with comments | « bench/Matrix44Bench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698