OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkMatrix44.h" | 9 #include "SkMatrix44.h" |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 return nearly_equal(m, identity); | 72 return nearly_equal(m, identity); |
73 } | 73 } |
74 | 74 |
75 /////////////////////////////////////////////////////////////////////////////// | 75 /////////////////////////////////////////////////////////////////////////////// |
76 static bool bits_isonly(int value, int mask) { | 76 static bool bits_isonly(int value, int mask) { |
77 return 0 == (value & ~mask); | 77 return 0 == (value & ~mask); |
78 } | 78 } |
79 | 79 |
80 static void test_constructor(skiatest::Reporter* reporter) { | 80 static void test_constructor(skiatest::Reporter* reporter) { |
81 // Allocate a matrix on the heap | 81 // Allocate a matrix on the heap |
82 SkMatrix44* placeholderMatrix = new SkMatrix44(); | 82 SkMatrix44* placeholderMatrix = new SkMatrix44(); |
reed1
2013/03/21 14:21:52
SkAutoTDelete<SkMatrix44> deleteMe(placeHodlerMatr
| |
83 for (int row = 0; row < 4; ++row) { | 83 for (int row = 0; row < 4; ++row) { |
84 for (int col = 0; col < 4; ++col) { | 84 for (int col = 0; col < 4; ++col) { |
85 placeholderMatrix->setDouble(row, col, row * col); | 85 placeholderMatrix->setDouble(row, col, row * col); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 // Use placement-new syntax to trigger the constructor on top of the heap | 89 // Use placement-new syntax to trigger the constructor on top of the heap |
90 // address we already initialized. This allows us to check that the | 90 // address we already initialized. This allows us to check that the |
91 // constructor did avoid initializing the matrix contents. | 91 // constructor did avoid initializing the matrix contents. |
92 SkMatrix44* testMatrix = new(placeholderMatrix) SkMatrix44(SkMatrix44::kUnin itialized_Constructor); | 92 SkMatrix44* testMatrix = new(placeholderMatrix) SkMatrix44(SkMatrix44::kUnin itialized_Constructor); |
93 REPORTER_ASSERT(reporter, testMatrix == placeholderMatrix); | 93 REPORTER_ASSERT(reporter, testMatrix == placeholderMatrix); |
94 REPORTER_ASSERT(reporter, !testMatrix->isIdentity()); | 94 REPORTER_ASSERT(reporter, !testMatrix->isIdentity()); |
95 for (int row = 0; row < 4; ++row) { | 95 for (int row = 0; row < 4; ++row) { |
96 for (int col = 0; col < 4; ++col) { | 96 for (int col = 0; col < 4; ++col) { |
97 REPORTER_ASSERT(reporter, nearly_equal_double(row * col, testMatrix- >getDouble(row, col))); | 97 REPORTER_ASSERT(reporter, nearly_equal_double(row * col, testMatrix- >getDouble(row, col))); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 // Verify that kIdentity_Constructor really does initialize to an identity m atrix. | 101 // Verify that kIdentity_Constructor really does initialize to an identity m atrix. |
102 testMatrix = 0; | 102 testMatrix = 0; |
103 testMatrix = new(placeholderMatrix) SkMatrix44(SkMatrix44::kIdentity_Constru ctor); | 103 testMatrix = new(placeholderMatrix) SkMatrix44(SkMatrix44::kIdentity_Constru ctor); |
104 REPORTER_ASSERT(reporter, testMatrix == placeholderMatrix); | 104 REPORTER_ASSERT(reporter, testMatrix == placeholderMatrix); |
105 REPORTER_ASSERT(reporter, testMatrix->isIdentity()); | 105 REPORTER_ASSERT(reporter, testMatrix->isIdentity()); |
106 REPORTER_ASSERT(reporter, *testMatrix == SkMatrix44::I()); | 106 REPORTER_ASSERT(reporter, *testMatrix == SkMatrix44::I()); |
107 | |
108 delete placeholderMatrix; | |
107 } | 109 } |
108 | 110 |
109 static void test_translate(skiatest::Reporter* reporter) { | 111 static void test_translate(skiatest::Reporter* reporter) { |
110 SkMatrix44 mat, inverse; | 112 SkMatrix44 mat, inverse; |
111 | 113 |
112 mat.setTranslate(0, 0, 0); | 114 mat.setTranslate(0, 0, 0); |
113 REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kIdentity_M ask)); | 115 REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kIdentity_M ask)); |
114 mat.setTranslate(1, 2, 3); | 116 mat.setTranslate(1, 2, 3); |
115 REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kTranslate_ Mask)); | 117 REPORTER_ASSERT(reporter, bits_isonly(mat.getType(), SkMatrix44::kTranslate_ Mask)); |
116 REPORTER_ASSERT(reporter, mat.invert(&inverse)); | 118 REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 test_transpose(reporter); | 433 test_transpose(reporter); |
432 test_get_set_double(reporter); | 434 test_get_set_double(reporter); |
433 test_set_row_col_major(reporter); | 435 test_set_row_col_major(reporter); |
434 test_translate(reporter); | 436 test_translate(reporter); |
435 test_scale(reporter); | 437 test_scale(reporter); |
436 test_map2(reporter); | 438 test_map2(reporter); |
437 } | 439 } |
438 | 440 |
439 #include "TestClassDef.h" | 441 #include "TestClassDef.h" |
440 DEFINE_TESTCLASS("Matrix44", Matrix44TestClass, TestMatrix44) | 442 DEFINE_TESTCLASS("Matrix44", Matrix44TestClass, TestMatrix44) |
OLD | NEW |