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-19 21:02:06 +0000
committerGravatar vollick@chromium.org <vollick@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-19 21:02:06 +0000
commitf11cf9ff885c81e29f55283174ca34ce2fc5fd23 (patch)
treeabc3cbbe3f4ed4e97b40e0fb2836d92c229b5345 /tests/Matrix44Test.cpp
parent8a1cdaece7e1d009befb84f21bb82370025bf4d6 (diff)
Add SkMatrix44::setColMajord, etc.
We have accessors for efficiently getting the matirx data, and it would be nice if we had similar methods for setting the matrix entries. Review URL: https://codereview.appspot.com/6851063 git-svn-id: http://skia.googlecode.com/svn/trunk@6494 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/Matrix44Test.cpp')
-rw-r--r--tests/Matrix44Test.cpp107
1 files changed, 65 insertions, 42 deletions
diff --git a/tests/Matrix44Test.cpp b/tests/Matrix44Test.cpp
index 782b51e0bf..ea6a56f436 100644
--- a/tests/Matrix44Test.cpp
+++ b/tests/Matrix44Test.cpp
@@ -123,57 +123,80 @@ 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()));
+ 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 test_transpose(skiatest::Reporter* reporter) {
- SkMatrix44 a;
- SkMatrix44 b;
-
- int i = 0;
- for (int row = 0; row < 4; ++row) {
- for (int col = 0; col < 4; ++col) {
- a.setDouble(row, col, i);
- b.setDouble(col, row, i++);
+ SkMatrix44 a;
+ SkMatrix44 b;
+
+ int i = 0;
+ for (int row = 0; row < 4; ++row) {
+ for (int col = 0; col < 4; ++col) {
+ a.setDouble(row, col, i);
+ b.setDouble(col, row, i++);
+ }
}
- }
- a.transpose();
- REPORTER_ASSERT(reporter, nearly_equal(a, b));
+ a.transpose();
+ REPORTER_ASSERT(reporter, nearly_equal(a, b));
}
static void test_get_set_double(skiatest::Reporter* reporter) {
- SkMatrix44 a;
- for (int row = 0; row < 4; ++row) {
- for (int col = 0; col < 4; ++col) {
- a.setDouble(row, col, 3.141592653589793);
- REPORTER_ASSERT(reporter, nearly_equal_double(3.141592653589793,
- a.getDouble(row, col)));
- a.setDouble(row, col, 0);
- REPORTER_ASSERT(reporter, nearly_equal_double(0, a.getDouble(row, col)));
+ SkMatrix44 a;
+ for (int row = 0; row < 4; ++row) {
+ for (int col = 0; col < 4; ++col) {
+ a.setDouble(row, col, 3.141592653589793);
+ REPORTER_ASSERT(reporter,
+ nearly_equal_double(3.141592653589793,
+ a.getDouble(row, col)));
+ a.setDouble(row, col, 0);
+ REPORTER_ASSERT(reporter,
+ nearly_equal_double(0, a.getDouble(row, col)));
+ }
}
- }
+}
+
+static void test_set_row_col_major(skiatest::Reporter* reporter) {
+ SkMatrix44 a, b, c, d;
+ for (int row = 0; row < 4; ++row)
+ for (int col = 0; col < 4; ++col)
+ a.setDouble(row, col, row * 4 + col);
+ double bufferd[16];
+ float bufferf[16];
+ a.asColMajord(bufferd);
+ b.setColMajord(bufferd);
+ REPORTER_ASSERT(reporter, nearly_equal(a, b));
+ b.setRowMajord(bufferd);
+ b.transpose();
+ REPORTER_ASSERT(reporter, nearly_equal(a, b));
+ a.asColMajorf(bufferf);
+ b.setColMajorf(bufferf);
+ REPORTER_ASSERT(reporter, nearly_equal(a, b));
+ b.setRowMajorf(bufferf);
+ b.transpose();
+ REPORTER_ASSERT(reporter, nearly_equal(a, b));
}
static void TestMatrix44(skiatest::Reporter* reporter) {