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 | |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | #include "SkMatrix44.h" |
| 10 | |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 11 | static bool nearly_equal_double(double a, double b) { |
| 12 | const double tolerance = 1e-7; |
| 13 | double diff = a - b; |
| 14 | if (diff < 0) |
| 15 | diff = -diff; |
| 16 | return diff <= tolerance; |
| 17 | } |
| 18 | |
reed@google.com | da9fac0 | 2011-06-13 14:46:52 +0000 | [diff] [blame] | 19 | static bool nearly_equal_scalar(SkMScalar a, SkMScalar b) { |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 20 | // Note that we get more compounded error for multiple operations when |
| 21 | // SK_SCALAR_IS_FIXED. |
| 22 | #ifdef SK_SCALAR_IS_FLOAT |
| 23 | const SkScalar tolerance = SK_Scalar1 / 200000; |
| 24 | #else |
| 25 | const SkScalar tolerance = SK_Scalar1 / 1024; |
| 26 | #endif |
| 27 | |
| 28 | return SkScalarAbs(a - b) <= tolerance; |
| 29 | } |
| 30 | |
reed@google.com | da9fac0 | 2011-06-13 14:46:52 +0000 | [diff] [blame] | 31 | template <typename T> void assert16(skiatest::Reporter* reporter, const T data[], |
| 32 | T m0, T m1, T m2, T m3, |
| 33 | T m4, T m5, T m6, T m7, |
| 34 | T m8, T m9, T m10, T m11, |
| 35 | T m12, T m13, T m14, T m15) { |
| 36 | REPORTER_ASSERT(reporter, data[0] == m0); |
| 37 | REPORTER_ASSERT(reporter, data[1] == m1); |
| 38 | REPORTER_ASSERT(reporter, data[2] == m2); |
| 39 | REPORTER_ASSERT(reporter, data[3] == m3); |
| 40 | |
| 41 | REPORTER_ASSERT(reporter, data[4] == m4); |
| 42 | REPORTER_ASSERT(reporter, data[5] == m5); |
| 43 | REPORTER_ASSERT(reporter, data[6] == m6); |
| 44 | REPORTER_ASSERT(reporter, data[7] == m7); |
| 45 | |
| 46 | REPORTER_ASSERT(reporter, data[8] == m8); |
| 47 | REPORTER_ASSERT(reporter, data[9] == m9); |
| 48 | REPORTER_ASSERT(reporter, data[10] == m10); |
| 49 | REPORTER_ASSERT(reporter, data[11] == m11); |
| 50 | |
| 51 | REPORTER_ASSERT(reporter, data[12] == m12); |
| 52 | REPORTER_ASSERT(reporter, data[13] == m13); |
| 53 | REPORTER_ASSERT(reporter, data[14] == m14); |
| 54 | REPORTER_ASSERT(reporter, data[15] == m15); |
| 55 | } |
| 56 | |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 57 | static bool nearly_equal(const SkMatrix44& a, const SkMatrix44& b) { |
| 58 | for (int i = 0; i < 4; ++i) { |
| 59 | for (int j = 0; j < 4; ++j) { |
| 60 | if (!nearly_equal_scalar(a.get(i, j), b.get(i, j))) { |
reed@google.com | da9fac0 | 2011-06-13 14:46:52 +0000 | [diff] [blame] | 61 | printf("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] | 62 | return false; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | static bool is_identity(const SkMatrix44& m) { |
| 70 | SkMatrix44 identity; |
| 71 | identity.reset(); |
| 72 | return nearly_equal(m, identity); |
| 73 | } |
| 74 | |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame^] | 75 | /////////////////////////////////////////////////////////////////////////////// |
| 76 | static bool bits_isonly(int value, int mask) { |
| 77 | return 0 == (value & ~mask); |
| 78 | } |
| 79 | |
| 80 | static void test_translate(skiatest::Reporter* reporter) { |
| 81 | SkMatrix44 mat, inverse; |
| 82 | |
| 83 | mat.setTranslate(0, 0, 0); |
| 84 | REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kIdentity_Mask)); |
| 85 | mat.setTranslate(1, 2, 3); |
| 86 | REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kTranslate_Mask)); |
| 87 | REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
| 88 | REPORTER_ASSERT(reporter, bits_isonly(inverse.getType(), SkMatrix44::kTranslate_Mask)); |
| 89 | |
| 90 | SkMatrix44 a, b, c; |
| 91 | a.set3x3(1, 2, 3, 4, 5, 6, 7, 8, 9); |
| 92 | b.setTranslate(10, 11, 12); |
| 93 | |
| 94 | c.setConcat(a, b); |
| 95 | mat = a; |
| 96 | mat.preTranslate(10, 11, 12); |
| 97 | REPORTER_ASSERT(reporter, mat == c); |
| 98 | |
| 99 | c.setConcat(b, a); |
| 100 | mat = a; |
| 101 | mat.postTranslate(10, 11, 12); |
| 102 | REPORTER_ASSERT(reporter, mat == c); |
| 103 | } |
| 104 | |
| 105 | static void test_scale(skiatest::Reporter* reporter) { |
| 106 | SkMatrix44 mat, inverse; |
| 107 | |
| 108 | mat.setScale(1, 1, 1); |
| 109 | REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kIdentity_Mask)); |
| 110 | mat.setScale(1, 2, 3); |
| 111 | REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kScale_Mask)); |
| 112 | REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
| 113 | REPORTER_ASSERT(reporter, bits_isonly(inverse.getType(), SkMatrix44::kScale_Mask)); |
| 114 | |
| 115 | SkMatrix44 a, b, c; |
| 116 | a.set3x3(1, 2, 3, 4, 5, 6, 7, 8, 9); |
| 117 | b.setScale(10, 11, 12); |
| 118 | |
| 119 | c.setConcat(a, b); |
| 120 | mat = a; |
| 121 | mat.preScale(10, 11, 12); |
| 122 | REPORTER_ASSERT(reporter, mat == c); |
| 123 | |
| 124 | c.setConcat(b, a); |
| 125 | mat = a; |
| 126 | mat.postScale(10, 11, 12); |
| 127 | REPORTER_ASSERT(reporter, mat == c); |
| 128 | } |
| 129 | |
| 130 | static void make_i(SkMatrix44* mat) { mat->setIdentity(); } |
| 131 | static void make_t(SkMatrix44* mat) { mat->setTranslate(1, 2, 3); } |
| 132 | static void make_s(SkMatrix44* mat) { mat->setScale(1, 2, 3); } |
| 133 | static void make_st(SkMatrix44* mat) { |
| 134 | mat->setScale(1, 2, 3); |
| 135 | mat->postTranslate(1, 2, 3); |
| 136 | } |
| 137 | static void make_a(SkMatrix44* mat) { |
| 138 | mat->setRotateDegreesAbout(1, 2, 3, 45); |
| 139 | } |
| 140 | static void make_p(SkMatrix44* mat) { |
| 141 | SkMScalar data[] = { |
| 142 | 1, 2, 3, 4, 5, 6, 7, 8, |
| 143 | 1, 2, 3, 4, 5, 6, 7, 8, |
| 144 | }; |
| 145 | mat->setRowMajor(data); |
| 146 | } |
| 147 | |
| 148 | typedef void (*Make44Proc)(SkMatrix44*); |
| 149 | |
| 150 | static const Make44Proc gMakeProcs[] = { |
| 151 | make_i, make_t, make_s, make_st, make_a, make_p |
| 152 | }; |
| 153 | |
| 154 | static void test_map2(skiatest::Reporter* reporter, const SkMatrix44& mat) { |
| 155 | SkMScalar src2[] = { 1, 2 }; |
| 156 | SkMScalar src4[] = { src2[0], src2[1], 0, 1 }; |
| 157 | SkMScalar dstA[4], dstB[4]; |
| 158 | |
| 159 | for (int i = 0; i < 4; ++i) { |
| 160 | dstA[i] = 123456789; |
| 161 | dstB[i] = 987654321; |
| 162 | } |
| 163 | |
| 164 | mat.map2(src2, 1, dstA); |
| 165 | mat.mapMScalars(src4, dstB); |
| 166 | |
| 167 | for (int i = 0; i < 4; ++i) { |
| 168 | REPORTER_ASSERT(reporter, dstA[i] == dstB[i]); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | static void test_map2(skiatest::Reporter* reporter) { |
| 173 | SkMatrix44 mat; |
| 174 | |
| 175 | for (size_t i = 0; i < SK_ARRAY_COUNT(gMakeProcs); ++i) { |
| 176 | gMakeProcs[i](&mat); |
| 177 | test_map2(reporter, mat); |
| 178 | } |
| 179 | } |
| 180 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 181 | static void test_gettype(skiatest::Reporter* reporter) { |
| 182 | SkMatrix44 matrix; |
skia.committer@gmail.com | e659c2e | 2012-12-04 02:01:25 +0000 | [diff] [blame] | 183 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 184 | REPORTER_ASSERT(reporter, matrix.isIdentity()); |
| 185 | REPORTER_ASSERT(reporter, SkMatrix44::kIdentity_Mask == matrix.getType()); |
skia.committer@gmail.com | e659c2e | 2012-12-04 02:01:25 +0000 | [diff] [blame] | 186 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 187 | int expectedMask; |
| 188 | |
| 189 | matrix.set(1, 1, 0); |
| 190 | expectedMask = SkMatrix44::kScale_Mask; |
| 191 | REPORTER_ASSERT(reporter, matrix.getType() == expectedMask); |
| 192 | |
| 193 | matrix.set(0, 3, 1); // translate-x |
| 194 | expectedMask |= SkMatrix44::kTranslate_Mask; |
| 195 | REPORTER_ASSERT(reporter, matrix.getType() == expectedMask); |
| 196 | |
| 197 | matrix.set(2, 0, 1); |
| 198 | expectedMask |= SkMatrix44::kAffine_Mask; |
| 199 | REPORTER_ASSERT(reporter, matrix.getType() == expectedMask); |
skia.committer@gmail.com | e659c2e | 2012-12-04 02:01:25 +0000 | [diff] [blame] | 200 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 201 | matrix.set(3, 2, 1); |
| 202 | REPORTER_ASSERT(reporter, matrix.getType() & SkMatrix44::kPerspective_Mask); |
| 203 | } |
| 204 | |
reed@google.com | 6f2b44d | 2011-06-24 18:13:39 +0000 | [diff] [blame] | 205 | static void test_common_angles(skiatest::Reporter* reporter) { |
| 206 | SkMatrix44 rot; |
| 207 | // Test precision of rotation in common cases |
| 208 | int common_angles[] = { 0, 90, -90, 180, -180, 270, -270, 360, -360 }; |
| 209 | for (int i = 0; i < 9; ++i) { |
robertphillips@google.com | 09042b8 | 2012-04-06 20:01:46 +0000 | [diff] [blame] | 210 | rot.setRotateDegreesAbout(0, 0, -1, SkIntToScalar(common_angles[i])); |
reed@google.com | 6f2b44d | 2011-06-24 18:13:39 +0000 | [diff] [blame] | 211 | |
| 212 | SkMatrix rot3x3 = rot; |
| 213 | REPORTER_ASSERT(reporter, rot3x3.rectStaysRect()); |
| 214 | } |
| 215 | } |
| 216 | |
reed@google.com | 80b577e | 2012-11-09 21:25:06 +0000 | [diff] [blame] | 217 | static void test_concat(skiatest::Reporter* reporter) { |
| 218 | int i; |
| 219 | SkMatrix44 a, b, c, d; |
| 220 | |
| 221 | a.setTranslate(10, 10, 10); |
| 222 | b.setScale(2, 2, 2); |
| 223 | |
| 224 | SkScalar src[8] = { |
| 225 | 0, 0, 0, 1, |
| 226 | 1, 1, 1, 1 |
| 227 | }; |
| 228 | SkScalar dst[8]; |
| 229 | |
| 230 | c.setConcat(a, b); |
| 231 | |
| 232 | d = a; |
| 233 | d.preConcat(b); |
| 234 | REPORTER_ASSERT(reporter, d == c); |
skia.committer@gmail.com | 453995e | 2012-11-10 02:01:26 +0000 | [diff] [blame] | 235 | |
reed@google.com | 1ea95be | 2012-11-09 21:39:48 +0000 | [diff] [blame] | 236 | c.mapScalars(src, dst); c.mapScalars(src + 4, dst + 4); |
reed@google.com | 80b577e | 2012-11-09 21:25:06 +0000 | [diff] [blame] | 237 | for (i = 0; i < 3; ++i) { |
| 238 | REPORTER_ASSERT(reporter, 10 == dst[i]); |
| 239 | REPORTER_ASSERT(reporter, 12 == dst[i + 4]); |
| 240 | } |
skia.committer@gmail.com | 453995e | 2012-11-10 02:01:26 +0000 | [diff] [blame] | 241 | |
reed@google.com | 80b577e | 2012-11-09 21:25:06 +0000 | [diff] [blame] | 242 | c.setConcat(b, a); |
| 243 | |
| 244 | d = a; |
| 245 | d.postConcat(b); |
| 246 | REPORTER_ASSERT(reporter, d == c); |
| 247 | |
reed@google.com | 1ea95be | 2012-11-09 21:39:48 +0000 | [diff] [blame] | 248 | c.mapScalars(src, dst); c.mapScalars(src + 4, dst + 4); |
reed@google.com | 80b577e | 2012-11-09 21:25:06 +0000 | [diff] [blame] | 249 | for (i = 0; i < 3; ++i) { |
| 250 | REPORTER_ASSERT(reporter, 20 == dst[i]); |
| 251 | REPORTER_ASSERT(reporter, 22 == dst[i + 4]); |
| 252 | } |
| 253 | } |
| 254 | |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 255 | static void test_determinant(skiatest::Reporter* reporter) { |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 256 | SkMatrix44 a; |
| 257 | REPORTER_ASSERT(reporter, nearly_equal_double(1, a.determinant())); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 258 | a.set(1, 1, 2); |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 259 | REPORTER_ASSERT(reporter, nearly_equal_double(2, a.determinant())); |
| 260 | SkMatrix44 b; |
| 261 | REPORTER_ASSERT(reporter, a.invert(&b)); |
| 262 | REPORTER_ASSERT(reporter, nearly_equal_double(0.5, b.determinant())); |
| 263 | SkMatrix44 c = b = a; |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 264 | c.set(0, 1, 4); |
| 265 | b.set(1, 0, 4); |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 266 | REPORTER_ASSERT(reporter, |
| 267 | nearly_equal_double(a.determinant(), |
| 268 | b.determinant())); |
| 269 | SkMatrix44 d = a; |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 270 | d.set(0, 0, 8); |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 271 | REPORTER_ASSERT(reporter, nearly_equal_double(16, d.determinant())); |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 272 | |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 273 | SkMatrix44 e = a; |
| 274 | e.postConcat(d); |
| 275 | REPORTER_ASSERT(reporter, nearly_equal_double(32, e.determinant())); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 276 | e.set(0, 0, 0); |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 277 | REPORTER_ASSERT(reporter, nearly_equal_double(0, e.determinant())); |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 278 | } |
| 279 | |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 280 | static void test_transpose(skiatest::Reporter* reporter) { |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 281 | SkMatrix44 a; |
| 282 | SkMatrix44 b; |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 283 | |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 284 | int i = 0; |
| 285 | for (int row = 0; row < 4; ++row) { |
| 286 | for (int col = 0; col < 4; ++col) { |
| 287 | a.setDouble(row, col, i); |
| 288 | b.setDouble(col, row, i++); |
| 289 | } |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 290 | } |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 291 | |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 292 | a.transpose(); |
| 293 | REPORTER_ASSERT(reporter, nearly_equal(a, b)); |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static void test_get_set_double(skiatest::Reporter* reporter) { |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 297 | SkMatrix44 a; |
| 298 | for (int row = 0; row < 4; ++row) { |
| 299 | for (int col = 0; col < 4; ++col) { |
| 300 | a.setDouble(row, col, 3.141592653589793); |
| 301 | REPORTER_ASSERT(reporter, |
| 302 | nearly_equal_double(3.141592653589793, |
| 303 | a.getDouble(row, col))); |
| 304 | a.setDouble(row, col, 0); |
| 305 | REPORTER_ASSERT(reporter, |
| 306 | nearly_equal_double(0, a.getDouble(row, col))); |
| 307 | } |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 308 | } |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | static void test_set_row_col_major(skiatest::Reporter* reporter) { |
| 312 | SkMatrix44 a, b, c, d; |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 313 | for (int row = 0; row < 4; ++row) { |
| 314 | for (int col = 0; col < 4; ++col) { |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 315 | a.setDouble(row, col, row * 4 + col); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 316 | } |
| 317 | } |
skia.committer@gmail.com | e659c2e | 2012-12-04 02:01:25 +0000 | [diff] [blame] | 318 | |
vollick@chromium.org | f11cf9f | 2012-11-19 21:02:06 +0000 | [diff] [blame] | 319 | double bufferd[16]; |
| 320 | float bufferf[16]; |
| 321 | a.asColMajord(bufferd); |
| 322 | b.setColMajord(bufferd); |
| 323 | REPORTER_ASSERT(reporter, nearly_equal(a, b)); |
| 324 | b.setRowMajord(bufferd); |
| 325 | b.transpose(); |
| 326 | REPORTER_ASSERT(reporter, nearly_equal(a, b)); |
| 327 | a.asColMajorf(bufferf); |
| 328 | b.setColMajorf(bufferf); |
| 329 | REPORTER_ASSERT(reporter, nearly_equal(a, b)); |
| 330 | b.setRowMajorf(bufferf); |
| 331 | b.transpose(); |
| 332 | REPORTER_ASSERT(reporter, nearly_equal(a, b)); |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 333 | } |
| 334 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 335 | static void TestMatrix44(skiatest::Reporter* reporter) { |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 336 | SkMatrix44 mat, inverse, iden1, iden2, rot; |
| 337 | |
| 338 | mat.reset(); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 339 | mat.setTranslate(1, 1, 1); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 340 | mat.invert(&inverse); |
| 341 | iden1.setConcat(mat, inverse); |
| 342 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 343 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 344 | mat.setScale(2, 2, 2); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 345 | mat.invert(&inverse); |
| 346 | iden1.setConcat(mat, inverse); |
| 347 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 348 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 349 | mat.setScale(SK_MScalar1/2, SK_MScalar1/2, SK_MScalar1/2); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 350 | mat.invert(&inverse); |
| 351 | iden1.setConcat(mat, inverse); |
| 352 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 353 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 354 | mat.setScale(3, 3, 3); |
| 355 | rot.setRotateDegreesAbout(0, 0, -1, 90); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 356 | mat.postConcat(rot); |
| 357 | REPORTER_ASSERT(reporter, mat.invert(NULL)); |
| 358 | mat.invert(&inverse); |
| 359 | iden1.setConcat(mat, inverse); |
| 360 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 361 | iden2.setConcat(inverse, mat); |
| 362 | REPORTER_ASSERT(reporter, is_identity(iden2)); |
reed@google.com | da9fac0 | 2011-06-13 14:46:52 +0000 | [diff] [blame] | 363 | |
| 364 | // test rol/col Major getters |
| 365 | { |
| 366 | mat.setTranslate(2, 3, 4); |
| 367 | float dataf[16]; |
| 368 | double datad[16]; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 369 | |
reed@google.com | da9fac0 | 2011-06-13 14:46:52 +0000 | [diff] [blame] | 370 | mat.asColMajorf(dataf); |
| 371 | assert16<float>(reporter, dataf, |
| 372 | 1, 0, 0, 0, |
| 373 | 0, 1, 0, 0, |
| 374 | 0, 0, 1, 0, |
| 375 | 2, 3, 4, 1); |
| 376 | mat.asColMajord(datad); |
| 377 | assert16<double>(reporter, datad, 1, 0, 0, 0, |
| 378 | 0, 1, 0, 0, |
| 379 | 0, 0, 1, 0, |
| 380 | 2, 3, 4, 1); |
| 381 | mat.asRowMajorf(dataf); |
| 382 | assert16<float>(reporter, dataf, 1, 0, 0, 2, |
| 383 | 0, 1, 0, 3, |
| 384 | 0, 0, 1, 4, |
| 385 | 0, 0, 0, 1); |
| 386 | mat.asRowMajord(datad); |
| 387 | assert16<double>(reporter, datad, 1, 0, 0, 2, |
| 388 | 0, 1, 0, 3, |
| 389 | 0, 0, 1, 4, |
| 390 | 0, 0, 0, 1); |
| 391 | } |
reed@google.com | 6f2b44d | 2011-06-24 18:13:39 +0000 | [diff] [blame] | 392 | |
reed@google.com | 80b577e | 2012-11-09 21:25:06 +0000 | [diff] [blame] | 393 | test_concat(reporter); |
| 394 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 395 | if (false) { // avoid bit rot, suppress warning (working on making this pass) |
| 396 | test_common_angles(reporter); |
| 397 | } |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 398 | |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 399 | test_gettype(reporter); |
vollick@chromium.org | 3959a76 | 2012-11-13 15:08:22 +0000 | [diff] [blame] | 400 | test_determinant(reporter); |
vollick@chromium.org | 9b21c25 | 2012-11-14 21:33:55 +0000 | [diff] [blame] | 401 | test_transpose(reporter); |
| 402 | test_get_set_double(reporter); |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame] | 403 | test_set_row_col_major(reporter); |
reed@google.com | 99b5c7f | 2012-12-05 22:13:59 +0000 | [diff] [blame^] | 404 | test_translate(reporter); |
| 405 | test_scale(reporter); |
| 406 | test_map2(reporter); |
reed@google.com | 125002a | 2011-06-09 19:13:41 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | #include "TestClassDef.h" |
| 410 | DEFINE_TESTCLASS("Matrix44", Matrix44TestClass, TestMatrix44) |