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 | */ |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 7 | |
tomhudson@google.com | 889bd8b | 2011-09-27 17:38:17 +0000 | [diff] [blame] | 8 | #include "SkMath.h" |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 9 | #include "SkMatrix.h" |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 10 | #include "SkMatrixUtils.h" |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 11 | #include "SkRandom.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 12 | #include "Test.h" |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 13 | |
| 14 | static bool nearly_equal_scalar(SkScalar a, SkScalar b) { |
epoger@google.com | 2047f00 | 2011-05-17 17:36:59 +0000 | [diff] [blame] | 15 | const SkScalar tolerance = SK_Scalar1 / 200000; |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 16 | return SkScalarAbs(a - b) <= tolerance; |
| 17 | } |
| 18 | |
| 19 | static bool nearly_equal(const SkMatrix& a, const SkMatrix& b) { |
| 20 | for (int i = 0; i < 9; i++) { |
| 21 | if (!nearly_equal_scalar(a[i], b[i])) { |
bungeman@google.com | fab44db | 2013-10-11 18:50:45 +0000 | [diff] [blame] | 22 | SkDebugf("not equal %g %g\n", (float)a[i], (float)b[i]); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 23 | return false; |
| 24 | } |
| 25 | } |
| 26 | return true; |
| 27 | } |
| 28 | |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 29 | static bool are_equal(skiatest::Reporter* reporter, |
| 30 | const SkMatrix& a, |
| 31 | const SkMatrix& b) { |
| 32 | bool equal = a == b; |
| 33 | bool cheapEqual = a.cheapEqualTo(b); |
| 34 | if (equal != cheapEqual) { |
bsalomon@google.com | 39d4f3a | 2012-03-26 17:25:45 +0000 | [diff] [blame] | 35 | if (equal) { |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 36 | bool foundZeroSignDiff = false; |
| 37 | for (int i = 0; i < 9; ++i) { |
| 38 | float aVal = a.get(i); |
| 39 | float bVal = b.get(i); |
bsalomon@google.com | 373ebc6 | 2012-09-26 13:08:56 +0000 | [diff] [blame] | 40 | int aValI = *SkTCast<int*>(&aVal); |
| 41 | int bValI = *SkTCast<int*>(&bVal); |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 42 | if (0 == aVal && 0 == bVal && aValI != bValI) { |
| 43 | foundZeroSignDiff = true; |
| 44 | } else { |
| 45 | REPORTER_ASSERT(reporter, aVal == bVal && aValI == aValI); |
| 46 | } |
| 47 | } |
| 48 | REPORTER_ASSERT(reporter, foundZeroSignDiff); |
| 49 | } else { |
| 50 | bool foundNaN = false; |
| 51 | for (int i = 0; i < 9; ++i) { |
| 52 | float aVal = a.get(i); |
| 53 | float bVal = b.get(i); |
bsalomon@google.com | 373ebc6 | 2012-09-26 13:08:56 +0000 | [diff] [blame] | 54 | int aValI = *SkTCast<int*>(&aVal); |
| 55 | int bValI = *SkTCast<int*>(&bVal); |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 56 | if (sk_float_isnan(aVal) && aValI == bValI) { |
| 57 | foundNaN = true; |
| 58 | } else { |
| 59 | REPORTER_ASSERT(reporter, aVal == bVal && aValI == bValI); |
| 60 | } |
| 61 | } |
| 62 | REPORTER_ASSERT(reporter, foundNaN); |
| 63 | } |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 64 | } |
| 65 | return equal; |
| 66 | } |
| 67 | |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 68 | static bool is_identity(const SkMatrix& m) { |
| 69 | SkMatrix identity; |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 70 | identity.reset(); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 71 | return nearly_equal(m, identity); |
| 72 | } |
| 73 | |
reed@google.com | 97cd69c | 2012-10-12 14:35:48 +0000 | [diff] [blame] | 74 | static void test_matrix_recttorect(skiatest::Reporter* reporter) { |
| 75 | SkRect src, dst; |
| 76 | SkMatrix matrix; |
skia.committer@gmail.com | f57c01b | 2012-10-13 02:01:56 +0000 | [diff] [blame] | 77 | |
reed@google.com | 97cd69c | 2012-10-12 14:35:48 +0000 | [diff] [blame] | 78 | src.set(0, 0, SK_Scalar1*10, SK_Scalar1*10); |
| 79 | dst = src; |
| 80 | matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); |
| 81 | REPORTER_ASSERT(reporter, SkMatrix::kIdentity_Mask == matrix.getType()); |
| 82 | REPORTER_ASSERT(reporter, matrix.rectStaysRect()); |
skia.committer@gmail.com | f57c01b | 2012-10-13 02:01:56 +0000 | [diff] [blame] | 83 | |
reed@google.com | 97cd69c | 2012-10-12 14:35:48 +0000 | [diff] [blame] | 84 | dst.offset(SK_Scalar1, SK_Scalar1); |
| 85 | matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); |
| 86 | REPORTER_ASSERT(reporter, SkMatrix::kTranslate_Mask == matrix.getType()); |
| 87 | REPORTER_ASSERT(reporter, matrix.rectStaysRect()); |
skia.committer@gmail.com | f57c01b | 2012-10-13 02:01:56 +0000 | [diff] [blame] | 88 | |
reed@google.com | 97cd69c | 2012-10-12 14:35:48 +0000 | [diff] [blame] | 89 | dst.fRight += SK_Scalar1; |
| 90 | matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); |
skia.committer@gmail.com | e659c2e | 2012-12-04 02:01:25 +0000 | [diff] [blame] | 91 | REPORTER_ASSERT(reporter, |
robertphillips@google.com | 93f0332 | 2012-12-03 17:35:19 +0000 | [diff] [blame] | 92 | (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask) == matrix.getType()); |
reed@google.com | 97cd69c | 2012-10-12 14:35:48 +0000 | [diff] [blame] | 93 | REPORTER_ASSERT(reporter, matrix.rectStaysRect()); |
| 94 | |
| 95 | dst = src; |
| 96 | dst.fRight = src.fRight * 2; |
| 97 | matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); |
| 98 | REPORTER_ASSERT(reporter, SkMatrix::kScale_Mask == matrix.getType()); |
| 99 | REPORTER_ASSERT(reporter, matrix.rectStaysRect()); |
| 100 | } |
| 101 | |
reed@android.com | 4b7577b | 2009-06-29 16:14:41 +0000 | [diff] [blame] | 102 | static void test_flatten(skiatest::Reporter* reporter, const SkMatrix& m) { |
| 103 | // add 100 in case we have a bug, I don't want to kill my stack in the test |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 104 | static const size_t kBufferSize = SkMatrix::kMaxFlattenSize + 100; |
| 105 | char buffer[kBufferSize]; |
| 106 | size_t size1 = m.writeToMemory(NULL); |
| 107 | size_t size2 = m.writeToMemory(buffer); |
reed@android.com | 4b7577b | 2009-06-29 16:14:41 +0000 | [diff] [blame] | 108 | REPORTER_ASSERT(reporter, size1 == size2); |
| 109 | REPORTER_ASSERT(reporter, size1 <= SkMatrix::kMaxFlattenSize); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 110 | |
reed@android.com | 4b7577b | 2009-06-29 16:14:41 +0000 | [diff] [blame] | 111 | SkMatrix m2; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 112 | size_t size3 = m2.readFromMemory(buffer, kBufferSize); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 113 | REPORTER_ASSERT(reporter, size1 == size3); |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 114 | REPORTER_ASSERT(reporter, are_equal(reporter, m, m2)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 115 | |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 116 | char buffer2[kBufferSize]; |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 117 | size3 = m2.writeToMemory(buffer2); |
| 118 | REPORTER_ASSERT(reporter, size1 == size3); |
reed@android.com | 4b7577b | 2009-06-29 16:14:41 +0000 | [diff] [blame] | 119 | REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0); |
| 120 | } |
| 121 | |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 122 | static void test_matrix_min_max_scale(skiatest::Reporter* reporter) { |
commit-bot@chromium.org | 311a3cd | 2014-05-20 17:02:03 +0000 | [diff] [blame] | 123 | SkScalar scales[2]; |
| 124 | bool success; |
| 125 | |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 126 | SkMatrix identity; |
| 127 | identity.reset(); |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 128 | REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMinScale()); |
| 129 | REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMaxScale()); |
commit-bot@chromium.org | 311a3cd | 2014-05-20 17:02:03 +0000 | [diff] [blame] | 130 | success = identity.getMinMaxScales(scales); |
| 131 | REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 == scales[1]); |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 132 | |
| 133 | SkMatrix scale; |
| 134 | scale.setScale(SK_Scalar1 * 2, SK_Scalar1 * 4); |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 135 | REPORTER_ASSERT(reporter, SK_Scalar1 * 2 == scale.getMinScale()); |
| 136 | REPORTER_ASSERT(reporter, SK_Scalar1 * 4 == scale.getMaxScale()); |
commit-bot@chromium.org | 311a3cd | 2014-05-20 17:02:03 +0000 | [diff] [blame] | 137 | success = scale.getMinMaxScales(scales); |
| 138 | REPORTER_ASSERT(reporter, success && SK_Scalar1 * 2 == scales[0] && SK_Scalar1 * 4 == scales[1]); |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 139 | |
| 140 | SkMatrix rot90Scale; |
| 141 | rot90Scale.setRotate(90 * SK_Scalar1); |
| 142 | rot90Scale.postScale(SK_Scalar1 / 4, SK_Scalar1 / 2); |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 143 | REPORTER_ASSERT(reporter, SK_Scalar1 / 4 == rot90Scale.getMinScale()); |
| 144 | REPORTER_ASSERT(reporter, SK_Scalar1 / 2 == rot90Scale.getMaxScale()); |
commit-bot@chromium.org | 311a3cd | 2014-05-20 17:02:03 +0000 | [diff] [blame] | 145 | success = rot90Scale.getMinMaxScales(scales); |
| 146 | REPORTER_ASSERT(reporter, success && SK_Scalar1 / 4 == scales[0] && SK_Scalar1 / 2 == scales[1]); |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 147 | |
| 148 | SkMatrix rotate; |
| 149 | rotate.setRotate(128 * SK_Scalar1); |
commit-bot@chromium.org | 311a3cd | 2014-05-20 17:02:03 +0000 | [diff] [blame] | 150 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMinScale(), SK_ScalarNearlyZero)); |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 151 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMaxScale(), SK_ScalarNearlyZero)); |
commit-bot@chromium.org | 311a3cd | 2014-05-20 17:02:03 +0000 | [diff] [blame] | 152 | success = rotate.getMinMaxScales(scales); |
| 153 | REPORTER_ASSERT(reporter, success); |
| 154 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, scales[0], SK_ScalarNearlyZero)); |
| 155 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, scales[1], SK_ScalarNearlyZero)); |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 156 | |
| 157 | SkMatrix translate; |
| 158 | translate.setTranslate(10 * SK_Scalar1, -5 * SK_Scalar1); |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 159 | REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMinScale()); |
| 160 | REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMaxScale()); |
commit-bot@chromium.org | 311a3cd | 2014-05-20 17:02:03 +0000 | [diff] [blame] | 161 | success = translate.getMinMaxScales(scales); |
| 162 | REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 == scales[1]); |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 163 | |
| 164 | SkMatrix perspX; |
| 165 | perspX.reset(); |
bungeman@google.com | 07faed1 | 2011-10-07 21:55:56 +0000 | [diff] [blame] | 166 | perspX.setPerspX(SkScalarToPersp(SK_Scalar1 / 1000)); |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 167 | REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMinScale()); |
| 168 | REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMaxScale()); |
commit-bot@chromium.org | 311a3cd | 2014-05-20 17:02:03 +0000 | [diff] [blame] | 169 | // Verify that getMinMaxScales() doesn't update the scales array on failure. |
| 170 | scales[0] = -5; |
| 171 | scales[1] = -5; |
| 172 | success = perspX.getMinMaxScales(scales); |
| 173 | REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * SK_Scalar1 == scales[1]); |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 174 | |
| 175 | SkMatrix perspY; |
| 176 | perspY.reset(); |
commit-bot@chromium.org | cea9abb | 2013-12-09 19:15:37 +0000 | [diff] [blame] | 177 | perspY.setPerspY(SkScalarToPersp(-SK_Scalar1 / 500)); |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 178 | REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMinScale()); |
| 179 | REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxScale()); |
commit-bot@chromium.org | 311a3cd | 2014-05-20 17:02:03 +0000 | [diff] [blame] | 180 | scales[0] = -5; |
| 181 | scales[1] = -5; |
| 182 | success = perspY.getMinMaxScales(scales); |
| 183 | REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * SK_Scalar1 == scales[1]); |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 184 | |
| 185 | SkMatrix baseMats[] = {scale, rot90Scale, rotate, |
| 186 | translate, perspX, perspY}; |
| 187 | SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)]; |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 188 | for (size_t i = 0; i < SK_ARRAY_COUNT(baseMats); ++i) { |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 189 | mats[i] = baseMats[i]; |
| 190 | bool invertable = mats[i].invert(&mats[i + SK_ARRAY_COUNT(baseMats)]); |
| 191 | REPORTER_ASSERT(reporter, invertable); |
| 192 | } |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 193 | SkRandom rand; |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 194 | for (int m = 0; m < 1000; ++m) { |
| 195 | SkMatrix mat; |
| 196 | mat.reset(); |
| 197 | for (int i = 0; i < 4; ++i) { |
| 198 | int x = rand.nextU() % SK_ARRAY_COUNT(mats); |
| 199 | mat.postConcat(mats[x]); |
| 200 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 201 | |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 202 | SkScalar minScale = mat.getMinScale(); |
| 203 | SkScalar maxScale = mat.getMaxScale(); |
| 204 | REPORTER_ASSERT(reporter, (minScale < 0) == (maxScale < 0)); |
| 205 | REPORTER_ASSERT(reporter, (maxScale < 0) == mat.hasPerspective()); |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 206 | |
commit-bot@chromium.org | 311a3cd | 2014-05-20 17:02:03 +0000 | [diff] [blame] | 207 | SkScalar scales[2]; |
| 208 | bool success = mat.getMinMaxScales(scales); |
| 209 | REPORTER_ASSERT(reporter, success == !mat.hasPerspective()); |
| 210 | REPORTER_ASSERT(reporter, !success || (scales[0] == minScale && scales[1] == maxScale)); |
| 211 | |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 212 | if (mat.hasPerspective()) { |
| 213 | m -= 1; // try another non-persp matrix |
| 214 | continue; |
| 215 | } |
| 216 | |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 217 | // test a bunch of vectors. All should be scaled by between minScale and maxScale |
commit-bot@chromium.org | cea9abb | 2013-12-09 19:15:37 +0000 | [diff] [blame] | 218 | // (modulo some error) and we should find a vector that is scaled by almost each. |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 219 | static const SkScalar gVectorScaleTol = (105 * SK_Scalar1) / 100; |
| 220 | static const SkScalar gCloseScaleTol = (97 * SK_Scalar1) / 100; |
commit-bot@chromium.org | cea9abb | 2013-12-09 19:15:37 +0000 | [diff] [blame] | 221 | SkScalar max = 0, min = SK_ScalarMax; |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 222 | SkVector vectors[1000]; |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 223 | for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) { |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 224 | vectors[i].fX = rand.nextSScalar1(); |
| 225 | vectors[i].fY = rand.nextSScalar1(); |
| 226 | if (!vectors[i].normalize()) { |
| 227 | i -= 1; |
| 228 | continue; |
| 229 | } |
| 230 | } |
| 231 | mat.mapVectors(vectors, SK_ARRAY_COUNT(vectors)); |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 232 | for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) { |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 233 | SkScalar d = vectors[i].length(); |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 234 | REPORTER_ASSERT(reporter, SkScalarDiv(d, maxScale) < gVectorScaleTol); |
| 235 | REPORTER_ASSERT(reporter, SkScalarDiv(minScale, d) < gVectorScaleTol); |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 236 | if (max < d) { |
| 237 | max = d; |
| 238 | } |
commit-bot@chromium.org | cea9abb | 2013-12-09 19:15:37 +0000 | [diff] [blame] | 239 | if (min > d) { |
| 240 | min = d; |
| 241 | } |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 242 | } |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 243 | REPORTER_ASSERT(reporter, SkScalarDiv(max, maxScale) >= gCloseScaleTol); |
| 244 | REPORTER_ASSERT(reporter, SkScalarDiv(minScale, min) >= gCloseScaleTol); |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 248 | static void test_matrix_is_similarity(skiatest::Reporter* reporter) { |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 249 | SkMatrix mat; |
| 250 | |
| 251 | // identity |
| 252 | mat.setIdentity(); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 253 | REPORTER_ASSERT(reporter, mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 254 | |
| 255 | // translation only |
| 256 | mat.reset(); |
| 257 | mat.setTranslate(SkIntToScalar(100), SkIntToScalar(100)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 258 | REPORTER_ASSERT(reporter, mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 259 | |
| 260 | // scale with same size |
| 261 | mat.reset(); |
| 262 | mat.setScale(SkIntToScalar(15), SkIntToScalar(15)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 263 | REPORTER_ASSERT(reporter, mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 264 | |
| 265 | // scale with one negative |
| 266 | mat.reset(); |
| 267 | mat.setScale(SkIntToScalar(-15), SkIntToScalar(15)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 268 | REPORTER_ASSERT(reporter, mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 269 | |
| 270 | // scale with different size |
| 271 | mat.reset(); |
| 272 | mat.setScale(SkIntToScalar(15), SkIntToScalar(20)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 273 | REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 274 | |
| 275 | // scale with same size at a pivot point |
| 276 | mat.reset(); |
| 277 | mat.setScale(SkIntToScalar(15), SkIntToScalar(15), |
| 278 | SkIntToScalar(2), SkIntToScalar(2)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 279 | REPORTER_ASSERT(reporter, mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 280 | |
| 281 | // scale with different size at a pivot point |
| 282 | mat.reset(); |
| 283 | mat.setScale(SkIntToScalar(15), SkIntToScalar(20), |
| 284 | SkIntToScalar(2), SkIntToScalar(2)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 285 | REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 286 | |
| 287 | // skew with same size |
| 288 | mat.reset(); |
| 289 | mat.setSkew(SkIntToScalar(15), SkIntToScalar(15)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 290 | REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 291 | |
| 292 | // skew with different size |
| 293 | mat.reset(); |
| 294 | mat.setSkew(SkIntToScalar(15), SkIntToScalar(20)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 295 | REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 296 | |
| 297 | // skew with same size at a pivot point |
| 298 | mat.reset(); |
| 299 | mat.setSkew(SkIntToScalar(15), SkIntToScalar(15), |
| 300 | SkIntToScalar(2), SkIntToScalar(2)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 301 | REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 302 | |
| 303 | // skew with different size at a pivot point |
| 304 | mat.reset(); |
| 305 | mat.setSkew(SkIntToScalar(15), SkIntToScalar(20), |
| 306 | SkIntToScalar(2), SkIntToScalar(2)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 307 | REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 308 | |
| 309 | // perspective x |
| 310 | mat.reset(); |
| 311 | mat.setPerspX(SkScalarToPersp(SK_Scalar1 / 2)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 312 | REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 313 | |
| 314 | // perspective y |
| 315 | mat.reset(); |
| 316 | mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 317 | REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 318 | |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 319 | // rotate |
| 320 | for (int angle = 0; angle < 360; ++angle) { |
| 321 | mat.reset(); |
| 322 | mat.setRotate(SkIntToScalar(angle)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 323 | REPORTER_ASSERT(reporter, mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | // see if there are any accumulated precision issues |
| 327 | mat.reset(); |
| 328 | for (int i = 1; i < 360; i++) { |
| 329 | mat.postRotate(SkIntToScalar(1)); |
| 330 | } |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 331 | REPORTER_ASSERT(reporter, mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 332 | |
| 333 | // rotate + translate |
| 334 | mat.reset(); |
| 335 | mat.setRotate(SkIntToScalar(30)); |
| 336 | mat.postTranslate(SkIntToScalar(10), SkIntToScalar(20)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 337 | REPORTER_ASSERT(reporter, mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 338 | |
| 339 | // rotate + uniform scale |
| 340 | mat.reset(); |
| 341 | mat.setRotate(SkIntToScalar(30)); |
| 342 | mat.postScale(SkIntToScalar(2), SkIntToScalar(2)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 343 | REPORTER_ASSERT(reporter, mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 344 | |
| 345 | // rotate + non-uniform scale |
| 346 | mat.reset(); |
| 347 | mat.setRotate(SkIntToScalar(30)); |
| 348 | mat.postScale(SkIntToScalar(3), SkIntToScalar(2)); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 349 | REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 350 | |
| 351 | // all zero |
| 352 | mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 353 | REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 354 | |
| 355 | // all zero except perspective |
| 356 | mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, SK_Scalar1); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 357 | REPORTER_ASSERT(reporter, !mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 358 | |
| 359 | // scales zero, only skews |
| 360 | mat.setAll(0, SK_Scalar1, 0, |
| 361 | SK_Scalar1, 0, 0, |
| 362 | 0, 0, SkMatrix::I()[8]); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 363 | REPORTER_ASSERT(reporter, mat.isSimilarity()); |
bsalomon@google.com | 69afee1 | 2012-04-25 15:07:40 +0000 | [diff] [blame] | 364 | } |
| 365 | |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 366 | // For test_matrix_decomposition, below. |
skia.committer@gmail.com | 5c561cb | 2013-07-25 07:01:00 +0000 | [diff] [blame] | 367 | static bool scalar_nearly_equal_relative(SkScalar a, SkScalar b, |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 368 | SkScalar tolerance = SK_ScalarNearlyZero) { |
| 369 | // from Bruce Dawson |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 370 | // absolute check |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 371 | SkScalar diff = SkScalarAbs(a - b); |
| 372 | if (diff < tolerance) { |
| 373 | return true; |
| 374 | } |
| 375 | |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 376 | // relative check |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 377 | a = SkScalarAbs(a); |
| 378 | b = SkScalarAbs(b); |
| 379 | SkScalar largest = (b > a) ? b : a; |
| 380 | |
| 381 | if (diff <= largest*tolerance) { |
| 382 | return true; |
| 383 | } |
| 384 | |
| 385 | return false; |
| 386 | } |
| 387 | |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 388 | static bool check_matrix_recomposition(const SkMatrix& mat, |
| 389 | const SkPoint& rotation1, |
| 390 | const SkPoint& scale, |
| 391 | const SkPoint& rotation2) { |
| 392 | SkScalar c1 = rotation1.fX; |
| 393 | SkScalar s1 = rotation1.fY; |
| 394 | SkScalar scaleX = scale.fX; |
| 395 | SkScalar scaleY = scale.fY; |
| 396 | SkScalar c2 = rotation2.fX; |
| 397 | SkScalar s2 = rotation2.fY; |
skia.committer@gmail.com | 85092f0 | 2013-09-04 07:01:39 +0000 | [diff] [blame] | 398 | |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 399 | // We do a relative check here because large scale factors cause problems with an absolute check |
| 400 | bool result = scalar_nearly_equal_relative(mat[SkMatrix::kMScaleX], |
| 401 | scaleX*c1*c2 - scaleY*s1*s2) && |
| 402 | scalar_nearly_equal_relative(mat[SkMatrix::kMSkewX], |
| 403 | -scaleX*s1*c2 - scaleY*c1*s2) && |
| 404 | scalar_nearly_equal_relative(mat[SkMatrix::kMSkewY], |
| 405 | scaleX*c1*s2 + scaleY*s1*c2) && |
| 406 | scalar_nearly_equal_relative(mat[SkMatrix::kMScaleY], |
| 407 | -scaleX*s1*s2 + scaleY*c1*c2); |
| 408 | return result; |
| 409 | } |
| 410 | |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 411 | static void test_matrix_decomposition(skiatest::Reporter* reporter) { |
| 412 | SkMatrix mat; |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 413 | SkPoint rotation1, scale, rotation2; |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 414 | |
| 415 | const float kRotation0 = 15.5f; |
| 416 | const float kRotation1 = -50.f; |
| 417 | const float kScale0 = 5000.f; |
| 418 | const float kScale1 = 0.001f; |
| 419 | |
| 420 | // identity |
| 421 | mat.reset(); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 422 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 423 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 424 | // make sure it doesn't crash if we pass in NULLs |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 425 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, NULL, NULL, NULL)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 426 | |
| 427 | // rotation only |
| 428 | mat.setRotate(kRotation0); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 429 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 430 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 431 | |
| 432 | // uniform scale only |
| 433 | mat.setScale(kScale0, kScale0); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 434 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 435 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 436 | |
| 437 | // anisotropic scale only |
| 438 | mat.setScale(kScale1, kScale0); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 439 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 440 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 441 | |
| 442 | // rotation then uniform scale |
| 443 | mat.setRotate(kRotation1); |
| 444 | mat.postScale(kScale0, kScale0); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 445 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 446 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 447 | |
| 448 | // uniform scale then rotation |
| 449 | mat.setScale(kScale0, kScale0); |
| 450 | mat.postRotate(kRotation1); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 451 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 452 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 453 | |
| 454 | // rotation then uniform scale+reflection |
| 455 | mat.setRotate(kRotation0); |
| 456 | mat.postScale(kScale1, -kScale1); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 457 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 458 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 459 | |
| 460 | // uniform scale+reflection, then rotate |
| 461 | mat.setScale(kScale0, -kScale0); |
| 462 | mat.postRotate(kRotation1); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 463 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 464 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 465 | |
| 466 | // rotation then anisotropic scale |
| 467 | mat.setRotate(kRotation1); |
| 468 | mat.postScale(kScale1, kScale0); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 469 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 470 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 471 | |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 472 | // rotation then anisotropic scale |
| 473 | mat.setRotate(90); |
| 474 | mat.postScale(kScale1, kScale0); |
| 475 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 476 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
skia.committer@gmail.com | 85092f0 | 2013-09-04 07:01:39 +0000 | [diff] [blame] | 477 | |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 478 | // anisotropic scale then rotation |
| 479 | mat.setScale(kScale1, kScale0); |
| 480 | mat.postRotate(kRotation0); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 481 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 482 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
skia.committer@gmail.com | 85092f0 | 2013-09-04 07:01:39 +0000 | [diff] [blame] | 483 | |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 484 | // anisotropic scale then rotation |
| 485 | mat.setScale(kScale1, kScale0); |
| 486 | mat.postRotate(90); |
| 487 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 488 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 489 | |
| 490 | // rotation, uniform scale, then different rotation |
| 491 | mat.setRotate(kRotation1); |
| 492 | mat.postScale(kScale0, kScale0); |
| 493 | mat.postRotate(kRotation0); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 494 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 495 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 496 | |
| 497 | // rotation, anisotropic scale, then different rotation |
| 498 | mat.setRotate(kRotation0); |
| 499 | mat.postScale(kScale1, kScale0); |
| 500 | mat.postRotate(kRotation1); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 501 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 502 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
skia.committer@gmail.com | 85092f0 | 2013-09-04 07:01:39 +0000 | [diff] [blame] | 503 | |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 504 | // rotation, anisotropic scale + reflection, then different rotation |
| 505 | mat.setRotate(kRotation0); |
| 506 | mat.postScale(-kScale1, kScale0); |
| 507 | mat.postRotate(kRotation1); |
| 508 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 509 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 510 | |
| 511 | // try some random matrices |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 512 | SkRandom rand; |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 513 | for (int m = 0; m < 1000; ++m) { |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 514 | SkScalar rot0 = rand.nextRangeF(-180, 180); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 515 | SkScalar sx = rand.nextRangeF(-3000.f, 3000.f); |
| 516 | SkScalar sy = rand.nextRangeF(-3000.f, 3000.f); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 517 | SkScalar rot1 = rand.nextRangeF(-180, 180); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 518 | mat.setRotate(rot0); |
| 519 | mat.postScale(sx, sy); |
| 520 | mat.postRotate(rot1); |
| 521 | |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 522 | if (SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)) { |
| 523 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 524 | } else { |
| 525 | // if the matrix is degenerate, the basis vectors should be near-parallel or near-zero |
| 526 | SkScalar perpdot = mat[SkMatrix::kMScaleX]*mat[SkMatrix::kMScaleY] - |
| 527 | mat[SkMatrix::kMSkewX]*mat[SkMatrix::kMSkewY]; |
| 528 | REPORTER_ASSERT(reporter, SkScalarNearlyZero(perpdot)); |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | // translation shouldn't affect this |
| 533 | mat.postTranslate(-1000.f, 1000.f); |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 534 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 535 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 536 | |
| 537 | // perspective shouldn't affect this |
jvanverth@google.com | 588f3d3 | 2013-07-24 18:44:10 +0000 | [diff] [blame] | 538 | mat[SkMatrix::kMPersp0] = 12.f; |
| 539 | mat[SkMatrix::kMPersp1] = 4.f; |
| 540 | mat[SkMatrix::kMPersp2] = 1872.f; |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 541 | REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
| 542 | REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 543 | |
| 544 | // degenerate matrices |
| 545 | // mostly zero entries |
| 546 | mat.reset(); |
| 547 | mat[SkMatrix::kMScaleX] = 0.f; |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 548 | REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 549 | mat.reset(); |
| 550 | mat[SkMatrix::kMScaleY] = 0.f; |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 551 | REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 552 | mat.reset(); |
| 553 | // linearly dependent entries |
| 554 | mat[SkMatrix::kMScaleX] = 1.f; |
| 555 | mat[SkMatrix::kMSkewX] = 2.f; |
| 556 | mat[SkMatrix::kMSkewY] = 4.f; |
| 557 | mat[SkMatrix::kMScaleY] = 8.f; |
commit-bot@chromium.org | 5b2e264 | 2013-09-03 19:08:14 +0000 | [diff] [blame] | 558 | REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 559 | } |
| 560 | |
egdaniel@google.com | 259fbaf | 2013-08-15 21:12:11 +0000 | [diff] [blame] | 561 | // For test_matrix_homogeneous, below. |
| 562 | static bool scalar_array_nearly_equal_relative(const SkScalar a[], const SkScalar b[], int count) { |
| 563 | for (int i = 0; i < count; ++i) { |
| 564 | if (!scalar_nearly_equal_relative(a[i], b[i])) { |
| 565 | return false; |
| 566 | } |
| 567 | } |
| 568 | return true; |
| 569 | } |
| 570 | |
| 571 | // For test_matrix_homogeneous, below. |
| 572 | // Maps a single triple in src using m and compares results to those in dst |
| 573 | static bool naive_homogeneous_mapping(const SkMatrix& m, const SkScalar src[3], |
| 574 | const SkScalar dst[3]) { |
| 575 | SkScalar res[3]; |
| 576 | SkScalar ms[9] = {m[0], m[1], m[2], |
| 577 | m[3], m[4], m[5], |
| 578 | m[6], m[7], m[8]}; |
| 579 | res[0] = src[0] * ms[0] + src[1] * ms[1] + src[2] * ms[2]; |
| 580 | res[1] = src[0] * ms[3] + src[1] * ms[4] + src[2] * ms[5]; |
| 581 | res[2] = src[0] * ms[6] + src[1] * ms[7] + src[2] * ms[8]; |
| 582 | return scalar_array_nearly_equal_relative(res, dst, 3); |
| 583 | } |
| 584 | |
| 585 | static void test_matrix_homogeneous(skiatest::Reporter* reporter) { |
| 586 | SkMatrix mat; |
| 587 | |
| 588 | const float kRotation0 = 15.5f; |
| 589 | const float kRotation1 = -50.f; |
| 590 | const float kScale0 = 5000.f; |
| 591 | |
| 592 | const int kTripleCount = 1000; |
| 593 | const int kMatrixCount = 1000; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 594 | SkRandom rand; |
egdaniel@google.com | 259fbaf | 2013-08-15 21:12:11 +0000 | [diff] [blame] | 595 | |
| 596 | SkScalar randTriples[3*kTripleCount]; |
| 597 | for (int i = 0; i < 3*kTripleCount; ++i) { |
| 598 | randTriples[i] = rand.nextRangeF(-3000.f, 3000.f); |
| 599 | } |
| 600 | |
| 601 | SkMatrix mats[kMatrixCount]; |
| 602 | for (int i = 0; i < kMatrixCount; ++i) { |
| 603 | for (int j = 0; j < 9; ++j) { |
| 604 | mats[i].set(j, rand.nextRangeF(-3000.f, 3000.f)); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | // identity |
| 609 | { |
| 610 | mat.reset(); |
| 611 | SkScalar dst[3*kTripleCount]; |
| 612 | mat.mapHomogeneousPoints(dst, randTriples, kTripleCount); |
| 613 | REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(randTriples, dst, kTripleCount*3)); |
| 614 | } |
| 615 | |
| 616 | // zero matrix |
| 617 | { |
| 618 | mat.setAll(0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f); |
| 619 | SkScalar dst[3*kTripleCount]; |
| 620 | mat.mapHomogeneousPoints(dst, randTriples, kTripleCount); |
| 621 | SkScalar zeros[3] = {0.f, 0.f, 0.f}; |
| 622 | for (int i = 0; i < kTripleCount; ++i) { |
| 623 | REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(&dst[i*3], zeros, 3)); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | // zero point |
| 628 | { |
| 629 | SkScalar zeros[3] = {0.f, 0.f, 0.f}; |
| 630 | for (int i = 0; i < kMatrixCount; ++i) { |
| 631 | SkScalar dst[3]; |
| 632 | mats[i].mapHomogeneousPoints(dst, zeros, 1); |
| 633 | REPORTER_ASSERT(reporter, scalar_array_nearly_equal_relative(dst, zeros, 3)); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | // doesn't crash with null dst, src, count == 0 |
| 638 | { |
| 639 | mats[0].mapHomogeneousPoints(NULL, NULL, 0); |
| 640 | } |
| 641 | |
| 642 | // uniform scale of point |
| 643 | { |
| 644 | mat.setScale(kScale0, kScale0); |
| 645 | SkScalar dst[3]; |
| 646 | SkScalar src[3] = {randTriples[0], randTriples[1], 1.f}; |
| 647 | SkPoint pnt; |
| 648 | pnt.set(src[0], src[1]); |
| 649 | mat.mapHomogeneousPoints(dst, src, 1); |
| 650 | mat.mapPoints(&pnt, &pnt, 1); |
| 651 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[0], pnt.fX)); |
| 652 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[1], pnt.fY)); |
| 653 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[2], SK_Scalar1)); |
| 654 | } |
| 655 | |
| 656 | // rotation of point |
| 657 | { |
| 658 | mat.setRotate(kRotation0); |
| 659 | SkScalar dst[3]; |
| 660 | SkScalar src[3] = {randTriples[0], randTriples[1], 1.f}; |
| 661 | SkPoint pnt; |
| 662 | pnt.set(src[0], src[1]); |
| 663 | mat.mapHomogeneousPoints(dst, src, 1); |
| 664 | mat.mapPoints(&pnt, &pnt, 1); |
| 665 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[0], pnt.fX)); |
| 666 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[1], pnt.fY)); |
| 667 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[2], SK_Scalar1)); |
| 668 | } |
| 669 | |
| 670 | // rotation, scale, rotation of point |
| 671 | { |
| 672 | mat.setRotate(kRotation1); |
| 673 | mat.postScale(kScale0, kScale0); |
| 674 | mat.postRotate(kRotation0); |
| 675 | SkScalar dst[3]; |
| 676 | SkScalar src[3] = {randTriples[0], randTriples[1], 1.f}; |
| 677 | SkPoint pnt; |
| 678 | pnt.set(src[0], src[1]); |
| 679 | mat.mapHomogeneousPoints(dst, src, 1); |
| 680 | mat.mapPoints(&pnt, &pnt, 1); |
| 681 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[0], pnt.fX)); |
| 682 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[1], pnt.fY)); |
| 683 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst[2], SK_Scalar1)); |
| 684 | } |
| 685 | |
| 686 | // compare with naive approach |
| 687 | { |
| 688 | for (int i = 0; i < kMatrixCount; ++i) { |
| 689 | for (int j = 0; j < kTripleCount; ++j) { |
| 690 | SkScalar dst[3]; |
| 691 | mats[i].mapHomogeneousPoints(dst, &randTriples[j*3], 1); |
| 692 | REPORTER_ASSERT(reporter, naive_homogeneous_mapping(mats[i], &randTriples[j*3], dst)); |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | } |
| 698 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 699 | DEF_TEST(Matrix, reporter) { |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 700 | SkMatrix mat, inverse, iden1, iden2; |
| 701 | |
| 702 | mat.reset(); |
| 703 | mat.setTranslate(SK_Scalar1, SK_Scalar1); |
reed@google.com | 5bfa55b | 2012-04-19 18:59:25 +0000 | [diff] [blame] | 704 | REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 705 | iden1.setConcat(mat, inverse); |
| 706 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 707 | |
reed@google.com | 2fb96cc | 2013-01-04 17:02:33 +0000 | [diff] [blame] | 708 | mat.setScale(SkIntToScalar(2), SkIntToScalar(4)); |
reed@google.com | 5bfa55b | 2012-04-19 18:59:25 +0000 | [diff] [blame] | 709 | REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 710 | iden1.setConcat(mat, inverse); |
| 711 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
reed@android.com | 4b7577b | 2009-06-29 16:14:41 +0000 | [diff] [blame] | 712 | test_flatten(reporter, mat); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 713 | |
reed@google.com | 2fb96cc | 2013-01-04 17:02:33 +0000 | [diff] [blame] | 714 | mat.setScale(SK_Scalar1/2, SkIntToScalar(2)); |
reed@google.com | 5bfa55b | 2012-04-19 18:59:25 +0000 | [diff] [blame] | 715 | REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 716 | iden1.setConcat(mat, inverse); |
| 717 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
reed@android.com | 4b7577b | 2009-06-29 16:14:41 +0000 | [diff] [blame] | 718 | test_flatten(reporter, mat); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 719 | |
| 720 | mat.setScale(SkIntToScalar(3), SkIntToScalar(5), SkIntToScalar(20), 0); |
| 721 | mat.postRotate(SkIntToScalar(25)); |
| 722 | REPORTER_ASSERT(reporter, mat.invert(NULL)); |
reed@google.com | 5bfa55b | 2012-04-19 18:59:25 +0000 | [diff] [blame] | 723 | REPORTER_ASSERT(reporter, mat.invert(&inverse)); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 724 | iden1.setConcat(mat, inverse); |
| 725 | REPORTER_ASSERT(reporter, is_identity(iden1)); |
| 726 | iden2.setConcat(inverse, mat); |
| 727 | REPORTER_ASSERT(reporter, is_identity(iden2)); |
reed@android.com | 4b7577b | 2009-06-29 16:14:41 +0000 | [diff] [blame] | 728 | test_flatten(reporter, mat); |
| 729 | test_flatten(reporter, iden2); |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 730 | |
reed@google.com | 2fb96cc | 2013-01-04 17:02:33 +0000 | [diff] [blame] | 731 | mat.setScale(0, SK_Scalar1); |
reed@google.com | e40591d | 2013-01-30 15:47:42 +0000 | [diff] [blame] | 732 | REPORTER_ASSERT(reporter, !mat.invert(NULL)); |
reed@google.com | 2fb96cc | 2013-01-04 17:02:33 +0000 | [diff] [blame] | 733 | REPORTER_ASSERT(reporter, !mat.invert(&inverse)); |
| 734 | mat.setScale(SK_Scalar1, 0); |
reed@google.com | e40591d | 2013-01-30 15:47:42 +0000 | [diff] [blame] | 735 | REPORTER_ASSERT(reporter, !mat.invert(NULL)); |
reed@google.com | 2fb96cc | 2013-01-04 17:02:33 +0000 | [diff] [blame] | 736 | REPORTER_ASSERT(reporter, !mat.invert(&inverse)); |
| 737 | |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 738 | // rectStaysRect test |
| 739 | { |
| 740 | static const struct { |
| 741 | SkScalar m00, m01, m10, m11; |
| 742 | bool mStaysRect; |
| 743 | } |
| 744 | gRectStaysRectSamples[] = { |
| 745 | { 0, 0, 0, 0, false }, |
| 746 | { 0, 0, 0, SK_Scalar1, false }, |
| 747 | { 0, 0, SK_Scalar1, 0, false }, |
| 748 | { 0, 0, SK_Scalar1, SK_Scalar1, false }, |
| 749 | { 0, SK_Scalar1, 0, 0, false }, |
| 750 | { 0, SK_Scalar1, 0, SK_Scalar1, false }, |
| 751 | { 0, SK_Scalar1, SK_Scalar1, 0, true }, |
| 752 | { 0, SK_Scalar1, SK_Scalar1, SK_Scalar1, false }, |
| 753 | { SK_Scalar1, 0, 0, 0, false }, |
| 754 | { SK_Scalar1, 0, 0, SK_Scalar1, true }, |
| 755 | { SK_Scalar1, 0, SK_Scalar1, 0, false }, |
| 756 | { SK_Scalar1, 0, SK_Scalar1, SK_Scalar1, false }, |
| 757 | { SK_Scalar1, SK_Scalar1, 0, 0, false }, |
| 758 | { SK_Scalar1, SK_Scalar1, 0, SK_Scalar1, false }, |
| 759 | { SK_Scalar1, SK_Scalar1, SK_Scalar1, 0, false }, |
| 760 | { SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, false } |
| 761 | }; |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 762 | |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 763 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRectStaysRectSamples); i++) { |
| 764 | SkMatrix m; |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 765 | |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 766 | m.reset(); |
| 767 | m.set(SkMatrix::kMScaleX, gRectStaysRectSamples[i].m00); |
| 768 | m.set(SkMatrix::kMSkewX, gRectStaysRectSamples[i].m01); |
| 769 | m.set(SkMatrix::kMSkewY, gRectStaysRectSamples[i].m10); |
| 770 | m.set(SkMatrix::kMScaleY, gRectStaysRectSamples[i].m11); |
| 771 | REPORTER_ASSERT(reporter, |
| 772 | m.rectStaysRect() == gRectStaysRectSamples[i].mStaysRect); |
| 773 | } |
| 774 | } |
bungeman@google.com | 1ddd7c3 | 2011-07-13 19:41:55 +0000 | [diff] [blame] | 775 | |
bungeman@google.com | ba7983e | 2011-07-13 20:18:16 +0000 | [diff] [blame] | 776 | mat.reset(); |
bungeman@google.com | 1ddd7c3 | 2011-07-13 19:41:55 +0000 | [diff] [blame] | 777 | mat.set(SkMatrix::kMScaleX, SkIntToScalar(1)); |
| 778 | mat.set(SkMatrix::kMSkewX, SkIntToScalar(2)); |
| 779 | mat.set(SkMatrix::kMTransX, SkIntToScalar(3)); |
| 780 | mat.set(SkMatrix::kMSkewY, SkIntToScalar(4)); |
| 781 | mat.set(SkMatrix::kMScaleY, SkIntToScalar(5)); |
| 782 | mat.set(SkMatrix::kMTransY, SkIntToScalar(6)); |
bungeman@google.com | 1ddd7c3 | 2011-07-13 19:41:55 +0000 | [diff] [blame] | 783 | SkScalar affine[6]; |
| 784 | REPORTER_ASSERT(reporter, mat.asAffine(affine)); |
| 785 | |
| 786 | #define affineEqual(e) affine[SkMatrix::kA##e] == mat.get(SkMatrix::kM##e) |
| 787 | REPORTER_ASSERT(reporter, affineEqual(ScaleX)); |
| 788 | REPORTER_ASSERT(reporter, affineEqual(SkewY)); |
| 789 | REPORTER_ASSERT(reporter, affineEqual(SkewX)); |
| 790 | REPORTER_ASSERT(reporter, affineEqual(ScaleY)); |
| 791 | REPORTER_ASSERT(reporter, affineEqual(TransX)); |
| 792 | REPORTER_ASSERT(reporter, affineEqual(TransY)); |
| 793 | #undef affineEqual |
| 794 | |
bungeman@google.com | 07faed1 | 2011-10-07 21:55:56 +0000 | [diff] [blame] | 795 | mat.set(SkMatrix::kMPersp1, SkScalarToPersp(SK_Scalar1 / 2)); |
bungeman@google.com | 1ddd7c3 | 2011-07-13 19:41:55 +0000 | [diff] [blame] | 796 | REPORTER_ASSERT(reporter, !mat.asAffine(affine)); |
bsalomon@google.com | 3839632 | 2011-09-09 19:32:04 +0000 | [diff] [blame] | 797 | |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 798 | SkMatrix mat2; |
| 799 | mat2.reset(); |
| 800 | mat.reset(); |
| 801 | SkScalar zero = 0; |
| 802 | mat.set(SkMatrix::kMSkewX, -zero); |
| 803 | REPORTER_ASSERT(reporter, are_equal(reporter, mat, mat2)); |
| 804 | |
| 805 | mat2.reset(); |
| 806 | mat.reset(); |
| 807 | mat.set(SkMatrix::kMSkewX, SK_ScalarNaN); |
| 808 | mat2.set(SkMatrix::kMSkewX, SK_ScalarNaN); |
| 809 | REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2)); |
| 810 | |
commit-bot@chromium.org | 1878651 | 2014-05-20 14:53:45 +0000 | [diff] [blame] | 811 | test_matrix_min_max_scale(reporter); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 812 | test_matrix_is_similarity(reporter); |
reed@google.com | 97cd69c | 2012-10-12 14:35:48 +0000 | [diff] [blame] | 813 | test_matrix_recttorect(reporter); |
commit-bot@chromium.org | 08284e4 | 2013-07-24 18:08:08 +0000 | [diff] [blame] | 814 | test_matrix_decomposition(reporter); |
egdaniel@google.com | 259fbaf | 2013-08-15 21:12:11 +0000 | [diff] [blame] | 815 | test_matrix_homogeneous(reporter); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 816 | } |
commit-bot@chromium.org | 99bd7d8 | 2014-05-19 15:51:12 +0000 | [diff] [blame] | 817 | |
| 818 | DEF_TEST(Matrix_Concat, r) { |
| 819 | SkMatrix a; |
| 820 | a.setTranslate(10, 20); |
| 821 | |
| 822 | SkMatrix b; |
| 823 | b.setScale(3, 5); |
| 824 | |
| 825 | SkMatrix expected; |
| 826 | expected.setConcat(a,b); |
| 827 | |
| 828 | REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b)); |
| 829 | } |