epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkMatrix44.h" |
| 9 | #include "include/core/SkPoint3.h" |
| 10 | #include "tests/Test.h" |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 11 | |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 12 | static bool nearly_equal_double(double a, double b) { |
| 13 | const double tolerance = 1e-7; |
| 14 | double diff = a - b; |
| 15 | if (diff < 0) |
| 16 | diff = -diff; |
| 17 | return diff <= tolerance; |
| 18 | } |
| 19 | |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 20 | static bool nearly_equal_scalar(SkScalar a, SkScalar b) { |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 21 | const SkScalar tolerance = SK_Scalar1 / 200000; |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 22 | return SkScalarAbs(a - b) <= tolerance; |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 23 | } |
| 24 | |
reed@google.com | da9fac0 | 2011-06-13 14:46:52 +0000 | [diff] [blame] | 25 | template <typename T> void assert16(skiatest::Reporter* reporter, const T data[], |
| 26 | T m0, T m1, T m2, T m3, |
| 27 | T m4, T m5, T m6, T m7, |
| 28 | T m8, T m9, T m10, T m11, |
| 29 | T m12, T m13, T m14, T m15) { |
| 30 | REPORTER_ASSERT(reporter, data[0] == m0); |
| 31 | REPORTER_ASSERT(reporter, data[1] == m1); |
| 32 | REPORTER_ASSERT(reporter, data[2] == m2); |
| 33 | REPORTER_ASSERT(reporter, data[3] == m3); |
| 34 | |
| 35 | REPORTER_ASSERT(reporter, data[4] == m4); |
| 36 | REPORTER_ASSERT(reporter, data[5] == m5); |
| 37 | REPORTER_ASSERT(reporter, data[6] == m6); |
| 38 | REPORTER_ASSERT(reporter, data[7] == m7); |
| 39 | |
| 40 | REPORTER_ASSERT(reporter, data[8] == m8); |
| 41 | REPORTER_ASSERT(reporter, data[9] == m9); |
| 42 | REPORTER_ASSERT(reporter, data[10] == m10); |
| 43 | REPORTER_ASSERT(reporter, data[11] == m11); |
| 44 | |
| 45 | REPORTER_ASSERT(reporter, data[12] == m12); |
| 46 | REPORTER_ASSERT(reporter, data[13] == m13); |
| 47 | REPORTER_ASSERT(reporter, data[14] == m14); |
| 48 | REPORTER_ASSERT(reporter, data[15] == m15); |
| 49 | } |
| 50 | |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 51 | static bool nearly_equal(const SkMatrix44& a, const SkMatrix44& b) { |
| 52 | for (int i = 0; i < 4; ++i) { |
| 53 | for (int j = 0; j < 4; ++j) { |
Mike Reed | 38380df | 2020-01-21 15:31:02 -0500 | [diff] [blame] | 54 | if (!SkScalarNearlyEqual(a.get(i, j), b.get(i, j))) { |
bungeman@google.com | fab44db | 2013-10-11 18:50:45 +0000 | [diff] [blame] | 55 | SkDebugf("not equal %g %g\n", a.get(i, j), b.get(i, j)); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 56 | return false; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | static bool is_identity(const SkMatrix44& m) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 64 | SkMatrix44 identity(SkMatrix44::kIdentity_Constructor); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 65 | return nearly_equal(m, identity); |
| 66 | } |
| 67 | |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 68 | /////////////////////////////////////////////////////////////////////////////// |
| 69 | static bool bits_isonly(int value, int mask) { |
| 70 | return 0 == (value & ~mask); |
| 71 | } |
| 72 | |
vollick@chromium.org | 57a54e3 | 2012-12-10 20:16:10 +0000 | [diff] [blame] | 73 | static void test_constructor(skiatest::Reporter* reporter) { |
| 74 | // Allocate a matrix on the heap |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 75 | SkMatrix44* placeholderMatrix = new SkMatrix44; |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 76 | std::unique_ptr<SkMatrix44> deleteMe(placeholderMatrix); |
robertphillips@google.com | 35300c4 | 2013-03-21 17:38:49 +0000 | [diff] [blame] | 77 | |
vollick@chromium.org | 57a54e3 | 2012-12-10 20:16:10 +0000 | [diff] [blame] | 78 | for (int row = 0; row < 4; ++row) { |
| 79 | for (int col = 0; col < 4; ++col) { |
| 80 | placeholderMatrix->setDouble(row, col, row * col); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Use placement-new syntax to trigger the constructor on top of the heap |
| 85 | // address we already initialized. This allows us to check that the |
| 86 | // constructor did avoid initializing the matrix contents. |
| 87 | SkMatrix44* testMatrix = new(placeholderMatrix) SkMatrix44(SkMatrix44::kUninitialized_Constructor); |
| 88 | REPORTER_ASSERT(reporter, testMatrix == placeholderMatrix); |
| 89 | REPORTER_ASSERT(reporter, !testMatrix->isIdentity()); |
| 90 | for (int row = 0; row < 4; ++row) { |
| 91 | for (int col = 0; col < 4; ++col) { |
| 92 | REPORTER_ASSERT(reporter, nearly_equal_double(row * col, testMatrix->getDouble(row, col))); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // Verify that kIdentity_Constructor really does initialize to an identity matrix. |
| 97 | testMatrix = 0; |
skia.committer@gmail.com | c7b4be7 | 2012-12-11 02:01:20 +0000 | [diff] [blame] | 98 | testMatrix = new(placeholderMatrix) SkMatrix44(SkMatrix44::kIdentity_Constructor); |
vollick@chromium.org | 57a54e3 | 2012-12-10 20:16:10 +0000 | [diff] [blame] | 99 | REPORTER_ASSERT(reporter, testMatrix == placeholderMatrix); |
| 100 | REPORTER_ASSERT(reporter, testMatrix->isIdentity()); |
| 101 | REPORTER_ASSERT(reporter, *testMatrix == SkMatrix44::I()); |
fs | 88640cf | 2014-12-16 08:36:11 -0800 | [diff] [blame] | 102 | |
| 103 | // Verify that that constructing from an SkMatrix initializes everything. |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 104 | SkMatrix44 scaleMatrix; |
fs | 88640cf | 2014-12-16 08:36:11 -0800 | [diff] [blame] | 105 | scaleMatrix.setScale(3, 4, 5); |
| 106 | REPORTER_ASSERT(reporter, scaleMatrix.isScale()); |
| 107 | testMatrix = new(&scaleMatrix) SkMatrix44(SkMatrix::I()); |
| 108 | REPORTER_ASSERT(reporter, testMatrix->isIdentity()); |
| 109 | REPORTER_ASSERT(reporter, *testMatrix == SkMatrix44::I()); |
vollick@chromium.org | 57a54e3 | 2012-12-10 20:16:10 +0000 | [diff] [blame] | 110 | } |
| 111 | |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 112 | static void test_translate(skiatest::Reporter* reporter) { |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 113 | SkMatrix44 mat; |
| 114 | SkMatrix44 inverse; |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 115 | |
| 116 | mat.setTranslate(0, 0, 0); |
| 117 | REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kIdentity_Mask)); |
| 118 | mat.setTranslate(1, 2, 3); |
| 119 | REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kTranslate_Mask)); |
| 120 | REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
| 121 | REPORTER_ASSERT(reporter, bits_isonly(inverse.getType(), SkMatrix44::kTranslate_Mask)); |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 122 | |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 123 | SkMatrix44 a,b,c; |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 124 | a.set3x3(1, 2, 3, 4, 5, 6, 7, 8, 9); |
| 125 | b.setTranslate(10, 11, 12); |
| 126 | |
| 127 | c.setConcat(a, b); |
| 128 | mat = a; |
| 129 | mat.preTranslate(10, 11, 12); |
| 130 | REPORTER_ASSERT(reporter, mat == c); |
| 131 | |
| 132 | c.setConcat(b, a); |
| 133 | mat = a; |
| 134 | mat.postTranslate(10, 11, 12); |
| 135 | REPORTER_ASSERT(reporter, mat == c); |
| 136 | } |
| 137 | |
| 138 | static void test_scale(skiatest::Reporter* reporter) { |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 139 | SkMatrix44 mat; |
| 140 | SkMatrix44 inverse; |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 141 | |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 142 | mat.setScale(1, 1, 1); |
| 143 | REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kIdentity_Mask)); |
| 144 | mat.setScale(1, 2, 3); |
| 145 | REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kScale_Mask)); |
| 146 | REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
| 147 | REPORTER_ASSERT(reporter, bits_isonly(inverse.getType(), SkMatrix44::kScale_Mask)); |
| 148 | |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 149 | SkMatrix44 a,b,c; |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 150 | a.set3x3(1, 2, 3, 4, 5, 6, 7, 8, 9); |
| 151 | b.setScale(10, 11, 12); |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 152 | |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 153 | c.setConcat(a, b); |
| 154 | mat = a; |
| 155 | mat.preScale(10, 11, 12); |
| 156 | REPORTER_ASSERT(reporter, mat == c); |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 157 | |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 158 | c.setConcat(b, a); |
| 159 | mat = a; |
| 160 | mat.postScale(10, 11, 12); |
| 161 | REPORTER_ASSERT(reporter, mat == c); |
| 162 | } |
| 163 | |
| 164 | static void make_i(SkMatrix44* mat) { mat->setIdentity(); } |
| 165 | static void make_t(SkMatrix44* mat) { mat->setTranslate(1, 2, 3); } |
| 166 | static void make_s(SkMatrix44* mat) { mat->setScale(1, 2, 3); } |
| 167 | static void make_st(SkMatrix44* mat) { |
| 168 | mat->setScale(1, 2, 3); |
| 169 | mat->postTranslate(1, 2, 3); |
| 170 | } |
| 171 | static void make_a(SkMatrix44* mat) { |
| 172 | mat->setRotateDegreesAbout(1, 2, 3, 45); |
| 173 | } |
| 174 | static void make_p(SkMatrix44* mat) { |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 175 | SkScalar data[] = { |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 176 | 1, 2, 3, 4, 5, 6, 7, 8, |
| 177 | 1, 2, 3, 4, 5, 6, 7, 8, |
| 178 | }; |
| 179 | mat->setRowMajor(data); |
| 180 | } |
| 181 | |
| 182 | typedef void (*Make44Proc)(SkMatrix44*); |
| 183 | |
| 184 | static const Make44Proc gMakeProcs[] = { |
| 185 | make_i, make_t, make_s, make_st, make_a, make_p |
| 186 | }; |
| 187 | |
| 188 | static void test_map2(skiatest::Reporter* reporter, const SkMatrix44& mat) { |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 189 | SkScalar src2[] = { 1, 2 }; |
| 190 | SkScalar src4[] = { src2[0], src2[1], 0, 1 }; |
| 191 | SkScalar dstA[4], dstB[4]; |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 192 | |
| 193 | for (int i = 0; i < 4; ++i) { |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 194 | dstA[i] = SkScalar(123456789); |
| 195 | dstB[i] = SkScalar(987654321); |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | mat.map2(src2, 1, dstA); |
Mike Reed | 38380df | 2020-01-21 15:31:02 -0500 | [diff] [blame] | 199 | mat.mapScalars(src4, dstB); |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 200 | |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 201 | for (int i = 0; i < 4; ++i) { |
| 202 | REPORTER_ASSERT(reporter, dstA[i] == dstB[i]); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | static void test_map2(skiatest::Reporter* reporter) { |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 207 | SkMatrix44 mat; |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 208 | |
| 209 | for (size_t i = 0; i < SK_ARRAY_COUNT(gMakeProcs); ++i) { |
| 210 | gMakeProcs[i](&mat); |
| 211 | test_map2(reporter, mat); |
| 212 | } |
| 213 | } |
| 214 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 215 | static void test_gettype(skiatest::Reporter* reporter) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 216 | SkMatrix44 matrix(SkMatrix44::kIdentity_Constructor); |
skia.committer@gmail.com | e659c2e | 2012-12-04 02:01:25 +0000 | [diff] [blame] | 217 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 218 | REPORTER_ASSERT(reporter, matrix.isIdentity()); |
| 219 | REPORTER_ASSERT(reporter, SkMatrix44::kIdentity_Mask == matrix.getType()); |
skia.committer@gmail.com | e659c2e | 2012-12-04 02:01:25 +0000 | [diff] [blame] | 220 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 221 | int expectedMask; |
| 222 | |
| 223 | matrix.set(1, 1, 0); |
| 224 | expectedMask = SkMatrix44::kScale_Mask; |
| 225 | REPORTER_ASSERT(reporter, matrix.getType() == expectedMask); |
| 226 | |
| 227 | matrix.set(0, 3, 1); // translate-x |
| 228 | expectedMask |= SkMatrix44::kTranslate_Mask; |
| 229 | REPORTER_ASSERT(reporter, matrix.getType() == expectedMask); |
| 230 | |
| 231 | matrix.set(2, 0, 1); |
| 232 | expectedMask |= SkMatrix44::kAffine_Mask; |
| 233 | REPORTER_ASSERT(reporter, matrix.getType() == expectedMask); |
skia.committer@gmail.com | e659c2e | 2012-12-04 02:01:25 +0000 | [diff] [blame] | 234 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 235 | matrix.set(3, 2, 1); |
| 236 | REPORTER_ASSERT(reporter, matrix.getType() & SkMatrix44::kPerspective_Mask); |
reed@google.com | 87f99cb | 2013-04-19 12:25:00 +0000 | [diff] [blame] | 237 | |
| 238 | // ensure that negative zero is treated as zero |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 239 | SkScalar dx = 0; |
| 240 | SkScalar dy = 0; |
| 241 | SkScalar dz = 0; |
reed@google.com | 87f99cb | 2013-04-19 12:25:00 +0000 | [diff] [blame] | 242 | matrix.setTranslate(-dx, -dy, -dz); |
| 243 | REPORTER_ASSERT(reporter, matrix.isIdentity()); |
| 244 | matrix.preTranslate(-dx, -dy, -dz); |
| 245 | REPORTER_ASSERT(reporter, matrix.isIdentity()); |
| 246 | matrix.postTranslate(-dx, -dy, -dz); |
| 247 | REPORTER_ASSERT(reporter, matrix.isIdentity()); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 248 | } |
| 249 | |
reed@google.com | 6f2b44d | 2011-06-24 18:13:39 +0000 | [diff] [blame] | 250 | static void test_common_angles(skiatest::Reporter* reporter) { |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 251 | SkMatrix44 rot; |
reed@google.com | 6f2b44d | 2011-06-24 18:13:39 +0000 | [diff] [blame] | 252 | // Test precision of rotation in common cases |
| 253 | int common_angles[] = { 0, 90, -90, 180, -180, 270, -270, 360, -360 }; |
| 254 | for (int i = 0; i < 9; ++i) { |
robertphillips@google.com | 09042b8 | 2012-04-06 20:01:46 +0000 | [diff] [blame] | 255 | rot.setRotateDegreesAbout(0, 0, -1, SkIntToScalar(common_angles[i])); |
reed@google.com | 6f2b44d | 2011-06-24 18:13:39 +0000 | [diff] [blame] | 256 | |
Mike Reed | d4d3b33 | 2020-01-16 16:34:34 -0500 | [diff] [blame] | 257 | SkMatrix rot3x3 = SkMatrix(rot); |
reed@google.com | 6f2b44d | 2011-06-24 18:13:39 +0000 | [diff] [blame] | 258 | REPORTER_ASSERT(reporter, rot3x3.rectStaysRect()); |
| 259 | } |
| 260 | } |
| 261 | |
reed@google.com | 80b577e | 2012-11-09 21:25:06 +0000 | [diff] [blame] | 262 | static void test_concat(skiatest::Reporter* reporter) { |
| 263 | int i; |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 264 | SkMatrix44 a,b,c,d; |
reed@google.com | 80b577e | 2012-11-09 21:25:06 +0000 | [diff] [blame] | 265 | |
| 266 | a.setTranslate(10, 10, 10); |
| 267 | b.setScale(2, 2, 2); |
| 268 | |
| 269 | SkScalar src[8] = { |
| 270 | 0, 0, 0, 1, |
| 271 | 1, 1, 1, 1 |
| 272 | }; |
| 273 | SkScalar dst[8]; |
| 274 | |
| 275 | c.setConcat(a, b); |
| 276 | |
| 277 | d = a; |
| 278 | d.preConcat(b); |
| 279 | REPORTER_ASSERT(reporter, d == c); |
skia.committer@gmail.com | 453995e | 2012-11-10 02:01:26 +0000 | [diff] [blame] | 280 | |
reed@google.com | 1ea95be | 2012-11-09 21:39:48 +0000 | [diff] [blame] | 281 | c.mapScalars(src, dst); c.mapScalars(src + 4, dst + 4); |
reed@google.com | 80b577e | 2012-11-09 21:25:06 +0000 | [diff] [blame] | 282 | for (i = 0; i < 3; ++i) { |
| 283 | REPORTER_ASSERT(reporter, 10 == dst[i]); |
| 284 | REPORTER_ASSERT(reporter, 12 == dst[i + 4]); |
| 285 | } |
skia.committer@gmail.com | 453995e | 2012-11-10 02:01:26 +0000 | [diff] [blame] | 286 | |
reed@google.com | 80b577e | 2012-11-09 21:25:06 +0000 | [diff] [blame] | 287 | c.setConcat(b, a); |
| 288 | |
| 289 | d = a; |
| 290 | d.postConcat(b); |
| 291 | REPORTER_ASSERT(reporter, d == c); |
| 292 | |
reed@google.com | 1ea95be | 2012-11-09 21:39:48 +0000 | [diff] [blame] | 293 | c.mapScalars(src, dst); c.mapScalars(src + 4, dst + 4); |
reed@google.com | 80b577e | 2012-11-09 21:25:06 +0000 | [diff] [blame] | 294 | for (i = 0; i < 3; ++i) { |
| 295 | REPORTER_ASSERT(reporter, 20 == dst[i]); |
| 296 | REPORTER_ASSERT(reporter, 22 == dst[i + 4]); |
| 297 | } |
| 298 | } |
| 299 | |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 300 | static void test_determinant(skiatest::Reporter* reporter) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 301 | SkMatrix44 a(SkMatrix44::kIdentity_Constructor); |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 302 | REPORTER_ASSERT(reporter, nearly_equal_double(1, a.determinant())); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 303 | a.set(1, 1, 2); |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 304 | REPORTER_ASSERT(reporter, nearly_equal_double(2, a.determinant())); |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 305 | SkMatrix44 b; |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 306 | REPORTER_ASSERT(reporter, a.invert(&b)); |
| 307 | REPORTER_ASSERT(reporter, nearly_equal_double(0.5, b.determinant())); |
| 308 | SkMatrix44 c = b = a; |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 309 | c.set(0, 1, 4); |
| 310 | b.set(1, 0, 4); |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 311 | REPORTER_ASSERT(reporter, |
| 312 | nearly_equal_double(a.determinant(), |
| 313 | b.determinant())); |
| 314 | SkMatrix44 d = a; |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 315 | d.set(0, 0, 8); |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 316 | REPORTER_ASSERT(reporter, nearly_equal_double(16, d.determinant())); |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 317 | |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 318 | SkMatrix44 e = a; |
| 319 | e.postConcat(d); |
| 320 | REPORTER_ASSERT(reporter, nearly_equal_double(32, e.determinant())); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 321 | e.set(0, 0, 0); |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 322 | REPORTER_ASSERT(reporter, nearly_equal_double(0, e.determinant())); |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 323 | } |
| 324 | |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 325 | static void test_invert(skiatest::Reporter* reporter) { |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 326 | SkMatrix44 inverse; |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 327 | double inverseData[16]; |
| 328 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 329 | SkMatrix44 identity(SkMatrix44::kIdentity_Constructor); |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 330 | identity.invert(&inverse); |
| 331 | inverse.asRowMajord(inverseData); |
| 332 | assert16<double>(reporter, inverseData, |
| 333 | 1, 0, 0, 0, |
| 334 | 0, 1, 0, 0, |
| 335 | 0, 0, 1, 0, |
| 336 | 0, 0, 0, 1); |
| 337 | |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 338 | SkMatrix44 translation; |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 339 | translation.setTranslate(2, 3, 4); |
| 340 | translation.invert(&inverse); |
| 341 | inverse.asRowMajord(inverseData); |
| 342 | assert16<double>(reporter, inverseData, |
| 343 | 1, 0, 0, -2, |
| 344 | 0, 1, 0, -3, |
| 345 | 0, 0, 1, -4, |
| 346 | 0, 0, 0, 1); |
| 347 | |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 348 | SkMatrix44 scale; |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 349 | scale.setScale(2, 4, 8); |
| 350 | scale.invert(&inverse); |
| 351 | inverse.asRowMajord(inverseData); |
| 352 | assert16<double>(reporter, inverseData, |
| 353 | 0.5, 0, 0, 0, |
| 354 | 0, 0.25, 0, 0, |
| 355 | 0, 0, 0.125, 0, |
| 356 | 0, 0, 0, 1); |
| 357 | |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 358 | SkMatrix44 scaleTranslation; |
mtklein | 5195805 | 2015-06-09 15:06:22 -0700 | [diff] [blame] | 359 | scaleTranslation.setScale(32, 128, 1024); |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 360 | scaleTranslation.preTranslate(2, 3, 4); |
| 361 | scaleTranslation.invert(&inverse); |
| 362 | inverse.asRowMajord(inverseData); |
| 363 | assert16<double>(reporter, inverseData, |
mtklein | 5195805 | 2015-06-09 15:06:22 -0700 | [diff] [blame] | 364 | 0.03125, 0, 0, -2, |
| 365 | 0, 0.0078125, 0, -3, |
| 366 | 0, 0, 0.0009765625, -4, |
| 367 | 0, 0, 0, 1); |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 368 | |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 369 | SkMatrix44 rotation; |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 370 | rotation.setRotateDegreesAbout(0, 0, 1, 90); |
| 371 | rotation.invert(&inverse); |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 372 | SkMatrix44 expected; |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 373 | double expectedInverseRotation[16] = |
| 374 | {0, 1, 0, 0, |
| 375 | -1, 0, 0, 0, |
| 376 | 0, 0, 1, 0, |
| 377 | 0, 0, 0, 1}; |
| 378 | expected.setRowMajord(expectedInverseRotation); |
| 379 | REPORTER_ASSERT(reporter, nearly_equal(expected, inverse)); |
skia.committer@gmail.com | b74bdf0 | 2013-08-21 07:01:29 +0000 | [diff] [blame] | 380 | |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 381 | SkMatrix44 affine; |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 382 | affine.setRotateDegreesAbout(0, 0, 1, 90); |
| 383 | affine.preScale(10, 20, 100); |
| 384 | affine.preTranslate(2, 3, 4); |
| 385 | affine.invert(&inverse); |
| 386 | double expectedInverseAffine[16] = |
| 387 | {0, 0.1, 0, -2, |
| 388 | -0.05, 0, 0, -3, |
| 389 | 0, 0, 0.01, -4, |
| 390 | 0, 0, 0, 1}; |
| 391 | expected.setRowMajord(expectedInverseAffine); |
| 392 | REPORTER_ASSERT(reporter, nearly_equal(expected, inverse)); |
| 393 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 394 | SkMatrix44 perspective(SkMatrix44::kIdentity_Constructor); |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 395 | perspective.setDouble(3, 2, 1.0); |
| 396 | perspective.invert(&inverse); |
| 397 | double expectedInversePerspective[16] = |
| 398 | {1, 0, 0, 0, |
| 399 | 0, 1, 0, 0, |
| 400 | 0, 0, 1, 0, |
| 401 | 0, 0, -1, 1}; |
| 402 | expected.setRowMajord(expectedInversePerspective); |
| 403 | REPORTER_ASSERT(reporter, nearly_equal(expected, inverse)); |
| 404 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 405 | SkMatrix44 affineAndPerspective(SkMatrix44::kIdentity_Constructor); |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 406 | affineAndPerspective.setDouble(3, 2, 1.0); |
| 407 | affineAndPerspective.preScale(10, 20, 100); |
| 408 | affineAndPerspective.preTranslate(2, 3, 4); |
| 409 | affineAndPerspective.invert(&inverse); |
| 410 | double expectedInverseAffineAndPerspective[16] = |
| 411 | {0.1, 0, 2, -2, |
| 412 | 0, 0.05, 3, -3, |
| 413 | 0, 0, 4.01, -4, |
| 414 | 0, 0, -1, 1}; |
| 415 | expected.setRowMajord(expectedInverseAffineAndPerspective); |
| 416 | REPORTER_ASSERT(reporter, nearly_equal(expected, inverse)); |
vmpstr | a8d4559 | 2015-06-30 13:36:04 -0700 | [diff] [blame] | 417 | |
| 418 | SkMatrix44 tinyScale(SkMatrix44::kIdentity_Constructor); |
| 419 | tinyScale.setDouble(0, 0, 1e-39); |
| 420 | REPORTER_ASSERT(reporter, tinyScale.getType() == SkMatrix44::kScale_Mask); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 421 | REPORTER_ASSERT(reporter, !tinyScale.invert(nullptr)); |
vmpstr | a8d4559 | 2015-06-30 13:36:04 -0700 | [diff] [blame] | 422 | REPORTER_ASSERT(reporter, !tinyScale.invert(&inverse)); |
| 423 | |
| 424 | SkMatrix44 tinyScaleTranslate(SkMatrix44::kIdentity_Constructor); |
| 425 | tinyScaleTranslate.setDouble(0, 0, 1e-38); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 426 | REPORTER_ASSERT(reporter, tinyScaleTranslate.invert(nullptr)); |
vmpstr | a8d4559 | 2015-06-30 13:36:04 -0700 | [diff] [blame] | 427 | tinyScaleTranslate.setDouble(0, 3, 10); |
| 428 | REPORTER_ASSERT( |
| 429 | reporter, tinyScaleTranslate.getType() == |
| 430 | (SkMatrix44::kScale_Mask | SkMatrix44::kTranslate_Mask)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 431 | REPORTER_ASSERT(reporter, !tinyScaleTranslate.invert(nullptr)); |
vmpstr | a8d4559 | 2015-06-30 13:36:04 -0700 | [diff] [blame] | 432 | REPORTER_ASSERT(reporter, !tinyScaleTranslate.invert(&inverse)); |
| 433 | |
| 434 | SkMatrix44 tinyScalePerspective(SkMatrix44::kIdentity_Constructor); |
| 435 | tinyScalePerspective.setDouble(0, 0, 1e-39); |
| 436 | tinyScalePerspective.setDouble(3, 2, -1); |
| 437 | REPORTER_ASSERT(reporter, (tinyScalePerspective.getType() & |
| 438 | SkMatrix44::kPerspective_Mask) == |
| 439 | SkMatrix44::kPerspective_Mask); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 440 | REPORTER_ASSERT(reporter, !tinyScalePerspective.invert(nullptr)); |
vmpstr | a8d4559 | 2015-06-30 13:36:04 -0700 | [diff] [blame] | 441 | REPORTER_ASSERT(reporter, !tinyScalePerspective.invert(&inverse)); |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 442 | } |
| 443 | |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 444 | static void test_transpose(skiatest::Reporter* reporter) { |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 445 | SkMatrix44 a,b; |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 446 | |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 447 | int i = 0; |
| 448 | for (int row = 0; row < 4; ++row) { |
| 449 | for (int col = 0; col < 4; ++col) { |
| 450 | a.setDouble(row, col, i); |
| 451 | b.setDouble(col, row, i++); |
| 452 | } |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 453 | } |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 454 | |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 455 | a.transpose(); |
| 456 | REPORTER_ASSERT(reporter, nearly_equal(a, b)); |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static void test_get_set_double(skiatest::Reporter* reporter) { |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 460 | SkMatrix44 a; |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 461 | for (int row = 0; row < 4; ++row) { |
| 462 | for (int col = 0; col < 4; ++col) { |
| 463 | a.setDouble(row, col, 3.141592653589793); |
| 464 | REPORTER_ASSERT(reporter, |
| 465 | nearly_equal_double(3.141592653589793, |
| 466 | a.getDouble(row, col))); |
| 467 | a.setDouble(row, col, 0); |
| 468 | REPORTER_ASSERT(reporter, |
| 469 | nearly_equal_double(0, a.getDouble(row, col))); |
| 470 | } |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 471 | } |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 472 | } |
| 473 | |
msarett | c1a3e24 | 2016-06-23 12:42:29 -0700 | [diff] [blame] | 474 | static void test_set_3x3(skiatest::Reporter* r) { |
| 475 | static float vals[9] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, }; |
| 476 | |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 477 | SkMatrix44 mat; |
msarett | c1a3e24 | 2016-06-23 12:42:29 -0700 | [diff] [blame] | 478 | mat.set3x3RowMajorf(vals); |
| 479 | |
| 480 | REPORTER_ASSERT(r, 1.0f == mat.getFloat(0, 0)); |
| 481 | REPORTER_ASSERT(r, 2.0f == mat.getFloat(0, 1)); |
| 482 | REPORTER_ASSERT(r, 3.0f == mat.getFloat(0, 2)); |
| 483 | REPORTER_ASSERT(r, 4.0f == mat.getFloat(1, 0)); |
| 484 | REPORTER_ASSERT(r, 5.0f == mat.getFloat(1, 1)); |
| 485 | REPORTER_ASSERT(r, 6.0f == mat.getFloat(1, 2)); |
| 486 | REPORTER_ASSERT(r, 7.0f == mat.getFloat(2, 0)); |
| 487 | REPORTER_ASSERT(r, 8.0f == mat.getFloat(2, 1)); |
| 488 | REPORTER_ASSERT(r, 9.0f == mat.getFloat(2, 2)); |
| 489 | } |
| 490 | |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 491 | static void test_set_row_col_major(skiatest::Reporter* reporter) { |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 492 | SkMatrix44 a,b; |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 493 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 494 | for (int row = 0; row < 4; ++row) { |
| 495 | for (int col = 0; col < 4; ++col) { |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 496 | a.setDouble(row, col, row * 4 + col); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 497 | } |
| 498 | } |
skia.committer@gmail.com | e659c2e | 2012-12-04 02:01:25 +0000 | [diff] [blame] | 499 | |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 500 | double bufferd[16]; |
| 501 | float bufferf[16]; |
| 502 | a.asColMajord(bufferd); |
| 503 | b.setColMajord(bufferd); |
| 504 | REPORTER_ASSERT(reporter, nearly_equal(a, b)); |
| 505 | b.setRowMajord(bufferd); |
| 506 | b.transpose(); |
| 507 | REPORTER_ASSERT(reporter, nearly_equal(a, b)); |
| 508 | a.asColMajorf(bufferf); |
| 509 | b.setColMajorf(bufferf); |
| 510 | REPORTER_ASSERT(reporter, nearly_equal(a, b)); |
| 511 | b.setRowMajorf(bufferf); |
| 512 | b.transpose(); |
| 513 | REPORTER_ASSERT(reporter, nearly_equal(a, b)); |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 514 | } |
| 515 | |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 516 | static void test_3x3_conversion(skiatest::Reporter* reporter) { |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 517 | SkScalar values4x4[16] = { 1, 2, 3, 4, |
| 518 | 5, 6, 7, 8, |
| 519 | 9, 10, 11, 12, |
| 520 | 13, 14, 15, 16 }; |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 521 | SkScalar values3x3[9] = { 1, 2, 4, |
| 522 | 5, 6, 8, |
| 523 | 13, 14, 16 }; |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 524 | SkScalar values4x4flattened[16] = { 1, 2, 0, 4, |
| 525 | 5, 6, 0, 8, |
| 526 | 0, 0, 1, 0, |
| 527 | 13, 14, 0, 16 }; |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 528 | SkMatrix44 a44; |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 529 | a44.setRowMajor(values4x4); |
| 530 | |
Mike Reed | d4d3b33 | 2020-01-16 16:34:34 -0500 | [diff] [blame] | 531 | SkMatrix a33 = SkMatrix(a44); |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 532 | SkMatrix expected33; |
| 533 | for (int i = 0; i < 9; i++) expected33[i] = values3x3[i]; |
| 534 | REPORTER_ASSERT(reporter, expected33 == a33); |
| 535 | |
| 536 | SkMatrix44 a44flattened = a33; |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 537 | SkMatrix44 expected44flattened; |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 538 | expected44flattened.setRowMajor(values4x4flattened); |
| 539 | REPORTER_ASSERT(reporter, nearly_equal(a44flattened, expected44flattened)); |
| 540 | |
| 541 | // Test that a point with a Z value of 0 is transformed the same way. |
| 542 | SkScalar vec4[4] = { 2, 4, 0, 8 }; |
Cary Clark | e4442cb | 2017-10-18 11:46:18 -0400 | [diff] [blame] | 543 | SkPoint3 vec3 = { 2, 4, 8 }; |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 544 | |
| 545 | SkScalar vec4transformed[4]; |
Cary Clark | e4442cb | 2017-10-18 11:46:18 -0400 | [diff] [blame] | 546 | SkPoint3 vec3transformed; |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 547 | SkScalar vec4transformed2[4]; |
| 548 | a44.mapScalars(vec4, vec4transformed); |
Cary Clark | e4442cb | 2017-10-18 11:46:18 -0400 | [diff] [blame] | 549 | a33.mapHomogeneousPoints(&vec3transformed, &vec3, 1); |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 550 | a44flattened.mapScalars(vec4, vec4transformed2); |
Cary Clark | e4442cb | 2017-10-18 11:46:18 -0400 | [diff] [blame] | 551 | REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[0], vec3transformed.fX)); |
| 552 | REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[1], vec3transformed.fY)); |
| 553 | REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[3], vec3transformed.fZ)); |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 554 | REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[0], vec4transformed2[0])); |
| 555 | REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[1], vec4transformed2[1])); |
| 556 | REPORTER_ASSERT(reporter, !nearly_equal_scalar(vec4transformed[2], vec4transformed2[2])); |
| 557 | REPORTER_ASSERT(reporter, nearly_equal_scalar(vec4transformed[3], vec4transformed2[3])); |
| 558 | } |
| 559 | |
tomhudson | a32f175 | 2014-09-16 08:29:29 -0700 | [diff] [blame] | 560 | static void test_has_perspective(skiatest::Reporter* reporter) { |
| 561 | SkMatrix44 transform(SkMatrix44::kIdentity_Constructor); |
| 562 | |
mtklein | 1831f99 | 2015-06-09 11:47:01 -0700 | [diff] [blame] | 563 | transform.setDouble(3, 2, -0.1); |
tomhudson | a32f175 | 2014-09-16 08:29:29 -0700 | [diff] [blame] | 564 | REPORTER_ASSERT(reporter, transform.hasPerspective()); |
| 565 | |
| 566 | transform.reset(); |
| 567 | REPORTER_ASSERT(reporter, !transform.hasPerspective()); |
| 568 | |
mtklein | 1831f99 | 2015-06-09 11:47:01 -0700 | [diff] [blame] | 569 | transform.setDouble(3, 0, -1.0); |
tomhudson | a32f175 | 2014-09-16 08:29:29 -0700 | [diff] [blame] | 570 | REPORTER_ASSERT(reporter, transform.hasPerspective()); |
| 571 | |
| 572 | transform.reset(); |
mtklein | 1831f99 | 2015-06-09 11:47:01 -0700 | [diff] [blame] | 573 | transform.setDouble(3, 1, -1.0); |
tomhudson | a32f175 | 2014-09-16 08:29:29 -0700 | [diff] [blame] | 574 | REPORTER_ASSERT(reporter, transform.hasPerspective()); |
| 575 | |
| 576 | transform.reset(); |
mtklein | 1831f99 | 2015-06-09 11:47:01 -0700 | [diff] [blame] | 577 | transform.setDouble(3, 2, -0.3); |
tomhudson | a32f175 | 2014-09-16 08:29:29 -0700 | [diff] [blame] | 578 | REPORTER_ASSERT(reporter, transform.hasPerspective()); |
| 579 | |
| 580 | transform.reset(); |
mtklein | 1831f99 | 2015-06-09 11:47:01 -0700 | [diff] [blame] | 581 | transform.setDouble(3, 3, 0.5); |
tomhudson | a32f175 | 2014-09-16 08:29:29 -0700 | [diff] [blame] | 582 | REPORTER_ASSERT(reporter, transform.hasPerspective()); |
mtklein | 1831f99 | 2015-06-09 11:47:01 -0700 | [diff] [blame] | 583 | |
tomhudson | a32f175 | 2014-09-16 08:29:29 -0700 | [diff] [blame] | 584 | transform.reset(); |
mtklein | 1831f99 | 2015-06-09 11:47:01 -0700 | [diff] [blame] | 585 | transform.setDouble(3, 3, 0.0); |
tomhudson | a32f175 | 2014-09-16 08:29:29 -0700 | [diff] [blame] | 586 | REPORTER_ASSERT(reporter, transform.hasPerspective()); |
| 587 | } |
| 588 | |
tomhudson | faccb8e | 2014-09-26 11:45:48 -0700 | [diff] [blame] | 589 | static bool is_rectilinear (SkVector4& p1, SkVector4& p2, SkVector4& p3, SkVector4& p4) { |
| 590 | return (SkScalarNearlyEqual(p1.fData[0], p2.fData[0]) && |
| 591 | SkScalarNearlyEqual(p2.fData[1], p3.fData[1]) && |
| 592 | SkScalarNearlyEqual(p3.fData[0], p4.fData[0]) && |
| 593 | SkScalarNearlyEqual(p4.fData[1], p1.fData[1])) || |
| 594 | (SkScalarNearlyEqual(p1.fData[1], p2.fData[1]) && |
| 595 | SkScalarNearlyEqual(p2.fData[0], p3.fData[0]) && |
| 596 | SkScalarNearlyEqual(p3.fData[1], p4.fData[1]) && |
| 597 | SkScalarNearlyEqual(p4.fData[0], p1.fData[0])); |
| 598 | } |
| 599 | |
| 600 | static SkVector4 mul_with_persp_divide(const SkMatrix44& transform, const SkVector4& target) { |
| 601 | SkVector4 result = transform * target; |
| 602 | if (result.fData[3] != 0.0f && result.fData[3] != SK_Scalar1) { |
| 603 | float wInverse = SK_Scalar1 / result.fData[3]; |
| 604 | result.set(result.fData[0] * wInverse, |
| 605 | result.fData[1] * wInverse, |
| 606 | result.fData[2] * wInverse, |
| 607 | SK_Scalar1); |
| 608 | } |
| 609 | return result; |
| 610 | } |
| 611 | |
| 612 | static bool empirically_preserves_2d_axis_alignment(skiatest::Reporter* reporter, |
| 613 | const SkMatrix44& transform) { |
| 614 | SkVector4 p1(5.0f, 5.0f, 0.0f); |
| 615 | SkVector4 p2(10.0f, 5.0f, 0.0f); |
| 616 | SkVector4 p3(10.0f, 20.0f, 0.0f); |
| 617 | SkVector4 p4(5.0f, 20.0f, 0.0f); |
| 618 | |
| 619 | REPORTER_ASSERT(reporter, is_rectilinear(p1, p2, p3, p4)); |
| 620 | |
| 621 | p1 = mul_with_persp_divide(transform, p1); |
| 622 | p2 = mul_with_persp_divide(transform, p2); |
| 623 | p3 = mul_with_persp_divide(transform, p3); |
| 624 | p4 = mul_with_persp_divide(transform, p4); |
| 625 | |
| 626 | return is_rectilinear(p1, p2, p3, p4); |
| 627 | } |
| 628 | |
| 629 | static void test(bool expected, skiatest::Reporter* reporter, const SkMatrix44& transform) { |
| 630 | if (expected) { |
| 631 | REPORTER_ASSERT(reporter, empirically_preserves_2d_axis_alignment(reporter, transform)); |
| 632 | REPORTER_ASSERT(reporter, transform.preserves2dAxisAlignment()); |
| 633 | } else { |
| 634 | REPORTER_ASSERT(reporter, !empirically_preserves_2d_axis_alignment(reporter, transform)); |
| 635 | REPORTER_ASSERT(reporter, !transform.preserves2dAxisAlignment()); |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | static void test_preserves_2d_axis_alignment(skiatest::Reporter* reporter) { |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 640 | SkMatrix44 transform; |
| 641 | SkMatrix44 transform2; |
tomhudson | faccb8e | 2014-09-26 11:45:48 -0700 | [diff] [blame] | 642 | |
| 643 | static const struct TestCase { |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 644 | SkScalar a; // row 1, column 1 |
| 645 | SkScalar b; // row 1, column 2 |
| 646 | SkScalar c; // row 2, column 1 |
| 647 | SkScalar d; // row 2, column 2 |
tomhudson | faccb8e | 2014-09-26 11:45:48 -0700 | [diff] [blame] | 648 | bool expected; |
| 649 | } test_cases[] = { |
| 650 | { 3.f, 0.f, |
| 651 | 0.f, 4.f, true }, // basic case |
| 652 | { 0.f, 4.f, |
| 653 | 3.f, 0.f, true }, // rotate by 90 |
| 654 | { 0.f, 0.f, |
| 655 | 0.f, 4.f, true }, // degenerate x |
| 656 | { 3.f, 0.f, |
| 657 | 0.f, 0.f, true }, // degenerate y |
| 658 | { 0.f, 0.f, |
| 659 | 3.f, 0.f, true }, // degenerate x + rotate by 90 |
| 660 | { 0.f, 4.f, |
| 661 | 0.f, 0.f, true }, // degenerate y + rotate by 90 |
| 662 | { 3.f, 4.f, |
| 663 | 0.f, 0.f, false }, |
| 664 | { 0.f, 0.f, |
| 665 | 3.f, 4.f, false }, |
| 666 | { 0.f, 3.f, |
| 667 | 0.f, 4.f, false }, |
| 668 | { 3.f, 0.f, |
| 669 | 4.f, 0.f, false }, |
| 670 | { 3.f, 4.f, |
| 671 | 5.f, 0.f, false }, |
| 672 | { 3.f, 4.f, |
| 673 | 0.f, 5.f, false }, |
| 674 | { 3.f, 0.f, |
| 675 | 4.f, 5.f, false }, |
| 676 | { 0.f, 3.f, |
| 677 | 4.f, 5.f, false }, |
| 678 | { 2.f, 3.f, |
| 679 | 4.f, 5.f, false }, |
| 680 | }; |
| 681 | |
| 682 | for (size_t i = 0; i < sizeof(test_cases)/sizeof(TestCase); ++i) { |
| 683 | const TestCase& value = test_cases[i]; |
| 684 | transform.setIdentity(); |
| 685 | transform.set(0, 0, value.a); |
| 686 | transform.set(0, 1, value.b); |
| 687 | transform.set(1, 0, value.c); |
| 688 | transform.set(1, 1, value.d); |
| 689 | |
| 690 | test(value.expected, reporter, transform); |
| 691 | } |
| 692 | |
| 693 | // Try the same test cases again, but this time make sure that other matrix |
| 694 | // elements (except perspective) have entries, to test that they are ignored. |
| 695 | for (size_t i = 0; i < sizeof(test_cases)/sizeof(TestCase); ++i) { |
| 696 | const TestCase& value = test_cases[i]; |
| 697 | transform.setIdentity(); |
| 698 | transform.set(0, 0, value.a); |
| 699 | transform.set(0, 1, value.b); |
| 700 | transform.set(1, 0, value.c); |
| 701 | transform.set(1, 1, value.d); |
| 702 | |
| 703 | transform.set(0, 2, 1.f); |
| 704 | transform.set(0, 3, 2.f); |
| 705 | transform.set(1, 2, 3.f); |
| 706 | transform.set(1, 3, 4.f); |
| 707 | transform.set(2, 0, 5.f); |
| 708 | transform.set(2, 1, 6.f); |
| 709 | transform.set(2, 2, 7.f); |
| 710 | transform.set(2, 3, 8.f); |
| 711 | |
| 712 | test(value.expected, reporter, transform); |
| 713 | } |
| 714 | |
| 715 | // Try the same test cases again, but this time add perspective which is |
| 716 | // always assumed to not-preserve axis alignment. |
| 717 | for (size_t i = 0; i < sizeof(test_cases)/sizeof(TestCase); ++i) { |
| 718 | const TestCase& value = test_cases[i]; |
| 719 | transform.setIdentity(); |
| 720 | transform.set(0, 0, value.a); |
| 721 | transform.set(0, 1, value.b); |
| 722 | transform.set(1, 0, value.c); |
| 723 | transform.set(1, 1, value.d); |
| 724 | |
| 725 | transform.set(0, 2, 1.f); |
| 726 | transform.set(0, 3, 2.f); |
| 727 | transform.set(1, 2, 3.f); |
| 728 | transform.set(1, 3, 4.f); |
| 729 | transform.set(2, 0, 5.f); |
| 730 | transform.set(2, 1, 6.f); |
| 731 | transform.set(2, 2, 7.f); |
| 732 | transform.set(2, 3, 8.f); |
| 733 | transform.set(3, 0, 9.f); |
| 734 | transform.set(3, 1, 10.f); |
| 735 | transform.set(3, 2, 11.f); |
| 736 | transform.set(3, 3, 12.f); |
| 737 | |
| 738 | test(false, reporter, transform); |
| 739 | } |
| 740 | |
| 741 | // Try a few more practical situations to check precision |
| 742 | // Reuse TestCase (a, b, c, d) as (x, y, z, degrees) axis to rotate about. |
| 743 | TestCase rotation_tests[] = { |
| 744 | { 0.0, 0.0, 1.0, 90.0, true }, |
| 745 | { 0.0, 0.0, 1.0, 180.0, true }, |
| 746 | { 0.0, 0.0, 1.0, 270.0, true }, |
| 747 | { 0.0, 1.0, 0.0, 90.0, true }, |
| 748 | { 1.0, 0.0, 0.0, 90.0, true }, |
| 749 | { 0.0, 0.0, 1.0, 45.0, false }, |
| 750 | // In 3d these next two are non-preserving, but we're testing in 2d after |
| 751 | // orthographic projection, where they are. |
| 752 | { 0.0, 1.0, 0.0, 45.0, true }, |
| 753 | { 1.0, 0.0, 0.0, 45.0, true }, |
| 754 | }; |
| 755 | |
| 756 | for (size_t i = 0; i < sizeof(rotation_tests)/sizeof(TestCase); ++i) { |
| 757 | const TestCase& value = rotation_tests[i]; |
| 758 | transform.setRotateDegreesAbout(value.a, value.b, value.c, value.d); |
| 759 | test(value.expected, reporter, transform); |
| 760 | } |
| 761 | |
| 762 | static const struct DoubleRotationCase { |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 763 | SkScalar x1; |
| 764 | SkScalar y1; |
| 765 | SkScalar z1; |
| 766 | SkScalar degrees1; |
| 767 | SkScalar x2; |
| 768 | SkScalar y2; |
| 769 | SkScalar z2; |
| 770 | SkScalar degrees2; |
tomhudson | faccb8e | 2014-09-26 11:45:48 -0700 | [diff] [blame] | 771 | bool expected; |
| 772 | } double_rotation_tests[] = { |
| 773 | { 0.0, 0.0, 1.0, 90.0, 0.0, 1.0, 0.0, 90.0, true }, |
| 774 | { 0.0, 0.0, 1.0, 90.0, 1.0, 0.0, 0.0, 90.0, true }, |
| 775 | { 0.0, 1.0, 0.0, 90.0, 0.0, 0.0, 1.0, 90.0, true }, |
| 776 | }; |
| 777 | |
| 778 | for (size_t i = 0; i < sizeof(double_rotation_tests)/sizeof(DoubleRotationCase); ++i) { |
| 779 | const DoubleRotationCase& value = double_rotation_tests[i]; |
| 780 | transform.setRotateDegreesAbout(value.x1, value.y1, value.z1, value.degrees1); |
| 781 | transform2.setRotateDegreesAbout(value.x2, value.y2, value.z2, value.degrees2); |
| 782 | transform.postConcat(transform2); |
| 783 | test(value.expected, reporter, transform); |
| 784 | } |
| 785 | |
| 786 | // Perspective cases. |
| 787 | transform.setIdentity(); |
mtklein | 1831f99 | 2015-06-09 11:47:01 -0700 | [diff] [blame] | 788 | transform.setDouble(3, 2, -0.1); // Perspective depth 10 |
tomhudson | faccb8e | 2014-09-26 11:45:48 -0700 | [diff] [blame] | 789 | transform2.setRotateDegreesAbout(0.0, 1.0, 0.0, 45.0); |
| 790 | transform.preConcat(transform2); |
| 791 | test(false, reporter, transform); |
| 792 | |
| 793 | transform.setIdentity(); |
mtklein | 1831f99 | 2015-06-09 11:47:01 -0700 | [diff] [blame] | 794 | transform.setDouble(3, 2, -0.1); // Perspective depth 10 |
tomhudson | faccb8e | 2014-09-26 11:45:48 -0700 | [diff] [blame] | 795 | transform2.setRotateDegreesAbout(0.0, 0.0, 1.0, 90.0); |
| 796 | transform.preConcat(transform2); |
| 797 | test(true, reporter, transform); |
| 798 | } |
| 799 | |
Mike Reed | 38380df | 2020-01-21 15:31:02 -0500 | [diff] [blame] | 800 | // just want to exercise the various converters for Scalar |
reed | 39393e3 | 2014-10-21 12:33:21 -0700 | [diff] [blame] | 801 | static void test_toint(skiatest::Reporter* reporter) { |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 802 | SkMatrix44 mat; |
reed | 39393e3 | 2014-10-21 12:33:21 -0700 | [diff] [blame] | 803 | mat.setScale(3, 3, 3); |
| 804 | |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 805 | SkScalar sum = SkScalarFloorToScalar(mat.get(0, 0)) + |
| 806 | SkScalarRoundToScalar(mat.get(1, 0)) + |
| 807 | SkScalarCeilToScalar(mat.get(2, 0)); |
| 808 | int isum = SkScalarFloorToInt(mat.get(0, 1)) + |
| 809 | SkScalarRoundToInt(mat.get(1, 2)) + |
| 810 | SkScalarCeilToInt(mat.get(2, 3)); |
reed | 39393e3 | 2014-10-21 12:33:21 -0700 | [diff] [blame] | 811 | REPORTER_ASSERT(reporter, sum >= 0); |
| 812 | REPORTER_ASSERT(reporter, isum >= 0); |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 813 | REPORTER_ASSERT(reporter, static_cast<SkScalar>(isum) == SkIntToScalar(isum)); |
reed | 39393e3 | 2014-10-21 12:33:21 -0700 | [diff] [blame] | 814 | } |
tomhudson | faccb8e | 2014-09-26 11:45:48 -0700 | [diff] [blame] | 815 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 816 | DEF_TEST(Matrix44, reporter) { |
Mike Klein | 4429a4f | 2018-10-04 09:06:00 -0400 | [diff] [blame] | 817 | SkMatrix44 mat; |
| 818 | SkMatrix44 inverse; |
| 819 | SkMatrix44 iden1; |
| 820 | SkMatrix44 iden2; |
| 821 | SkMatrix44 rot; |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 822 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 823 | mat.setTranslate(1, 1, 1); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 824 | mat.invert(&inverse); |
| 825 | iden1.setConcat(mat, inverse); |
| 826 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 827 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 828 | mat.setScale(2, 2, 2); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 829 | mat.invert(&inverse); |
| 830 | iden1.setConcat(mat, inverse); |
| 831 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 832 | |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 833 | mat.setScale(SK_Scalar1/2, SK_Scalar1/2, SK_Scalar1/2); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 834 | mat.invert(&inverse); |
| 835 | iden1.setConcat(mat, inverse); |
| 836 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 837 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 838 | mat.setScale(3, 3, 3); |
| 839 | rot.setRotateDegreesAbout(0, 0, -1, 90); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 840 | mat.postConcat(rot); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 841 | REPORTER_ASSERT(reporter, mat.invert(nullptr)); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 842 | mat.invert(&inverse); |
| 843 | iden1.setConcat(mat, inverse); |
| 844 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 845 | iden2.setConcat(inverse, mat); |
| 846 | REPORTER_ASSERT(reporter, is_identity(iden2)); |
reed@google.com | da9fac0 | 2011-06-13 14:46:52 +0000 | [diff] [blame] | 847 | |
commit-bot@chromium.org | f02f078 | 2013-08-20 15:25:04 +0000 | [diff] [blame] | 848 | // test tiny-valued matrix inverse |
| 849 | mat.reset(); |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 850 | auto v = 1.0e-12f; |
mtklein | 1831f99 | 2015-06-09 11:47:01 -0700 | [diff] [blame] | 851 | mat.setScale(v,v,v); |
commit-bot@chromium.org | f02f078 | 2013-08-20 15:25:04 +0000 | [diff] [blame] | 852 | rot.setRotateDegreesAbout(0, 0, -1, 90); |
| 853 | mat.postConcat(rot); |
mtklein | 1831f99 | 2015-06-09 11:47:01 -0700 | [diff] [blame] | 854 | mat.postTranslate(v,v,v); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 855 | REPORTER_ASSERT(reporter, mat.invert(nullptr)); |
commit-bot@chromium.org | f02f078 | 2013-08-20 15:25:04 +0000 | [diff] [blame] | 856 | mat.invert(&inverse); |
| 857 | iden1.setConcat(mat, inverse); |
| 858 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
skia.committer@gmail.com | b74bdf0 | 2013-08-21 07:01:29 +0000 | [diff] [blame] | 859 | |
commit-bot@chromium.org | f02f078 | 2013-08-20 15:25:04 +0000 | [diff] [blame] | 860 | // test mixed-valued matrix inverse |
| 861 | mat.reset(); |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 862 | mat.setScale(1.0e-2f, 3.0f, 1.0e+2f); |
commit-bot@chromium.org | f02f078 | 2013-08-20 15:25:04 +0000 | [diff] [blame] | 863 | rot.setRotateDegreesAbout(0, 0, -1, 90); |
| 864 | mat.postConcat(rot); |
Mike Reed | 215c34b | 2020-01-21 06:47:03 -0500 | [diff] [blame] | 865 | mat.postTranslate(1.0e+2f, 3.0f, 1.0e-2f); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 866 | REPORTER_ASSERT(reporter, mat.invert(nullptr)); |
commit-bot@chromium.org | f02f078 | 2013-08-20 15:25:04 +0000 | [diff] [blame] | 867 | mat.invert(&inverse); |
| 868 | iden1.setConcat(mat, inverse); |
| 869 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
skia.committer@gmail.com | b74bdf0 | 2013-08-21 07:01:29 +0000 | [diff] [blame] | 870 | |
commit-bot@chromium.org | f02f078 | 2013-08-20 15:25:04 +0000 | [diff] [blame] | 871 | // test degenerate matrix |
| 872 | mat.reset(); |
| 873 | mat.set3x3(1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 874 | REPORTER_ASSERT(reporter, !mat.invert(nullptr)); |
skia.committer@gmail.com | b74bdf0 | 2013-08-21 07:01:29 +0000 | [diff] [blame] | 875 | |
reed@google.com | da9fac0 | 2011-06-13 14:46:52 +0000 | [diff] [blame] | 876 | // test rol/col Major getters |
| 877 | { |
| 878 | mat.setTranslate(2, 3, 4); |
| 879 | float dataf[16]; |
| 880 | double datad[16]; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 881 | |
reed@google.com | da9fac0 | 2011-06-13 14:46:52 +0000 | [diff] [blame] | 882 | mat.asColMajorf(dataf); |
| 883 | assert16<float>(reporter, dataf, |
| 884 | 1, 0, 0, 0, |
| 885 | 0, 1, 0, 0, |
| 886 | 0, 0, 1, 0, |
| 887 | 2, 3, 4, 1); |
| 888 | mat.asColMajord(datad); |
| 889 | assert16<double>(reporter, datad, 1, 0, 0, 0, |
| 890 | 0, 1, 0, 0, |
| 891 | 0, 0, 1, 0, |
| 892 | 2, 3, 4, 1); |
| 893 | mat.asRowMajorf(dataf); |
| 894 | assert16<float>(reporter, dataf, 1, 0, 0, 2, |
| 895 | 0, 1, 0, 3, |
| 896 | 0, 0, 1, 4, |
| 897 | 0, 0, 0, 1); |
| 898 | mat.asRowMajord(datad); |
| 899 | assert16<double>(reporter, datad, 1, 0, 0, 2, |
| 900 | 0, 1, 0, 3, |
| 901 | 0, 0, 1, 4, |
| 902 | 0, 0, 0, 1); |
| 903 | } |
reed@google.com | 6f2b44d | 2011-06-24 18:13:39 +0000 | [diff] [blame] | 904 | |
reed@google.com | 80b577e | 2012-11-09 21:25:06 +0000 | [diff] [blame] | 905 | test_concat(reporter); |
| 906 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 907 | if (false) { // avoid bit rot, suppress warning (working on making this pass) |
| 908 | test_common_angles(reporter); |
| 909 | } |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 910 | |
vollick@chromium.org | 57a54e3 | 2012-12-10 20:16:10 +0000 | [diff] [blame] | 911 | test_constructor(reporter); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 912 | test_gettype(reporter); |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 913 | test_determinant(reporter); |
commit-bot@chromium.org | 9504575 | 2013-08-20 20:15:24 +0000 | [diff] [blame] | 914 | test_invert(reporter); |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 915 | test_transpose(reporter); |
| 916 | test_get_set_double(reporter); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 917 | test_set_row_col_major(reporter); |
msarett | c1a3e24 | 2016-06-23 12:42:29 -0700 | [diff] [blame] | 918 | test_set_3x3(reporter); |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame] | 919 | test_translate(reporter); |
| 920 | test_scale(reporter); |
| 921 | test_map2(reporter); |
commit-bot@chromium.org | 722555b | 2013-10-05 01:16:30 +0000 | [diff] [blame] | 922 | test_3x3_conversion(reporter); |
tomhudson | a32f175 | 2014-09-16 08:29:29 -0700 | [diff] [blame] | 923 | test_has_perspective(reporter); |
tomhudson | faccb8e | 2014-09-26 11:45:48 -0700 | [diff] [blame] | 924 | test_preserves_2d_axis_alignment(reporter); |
reed | 39393e3 | 2014-10-21 12:33:21 -0700 | [diff] [blame] | 925 | test_toint(reporter); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 926 | } |