blob: 5dfe2ca9366af468c46416fe9c1557d52542c693 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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.orge4fafb12013-12-12 21:11:12 +00007
tomhudson@google.com889bd8b2011-09-27 17:38:17 +00008#include "SkMath.h"
Cary Clark6d6d6032017-10-20 12:14:33 -04009#include "SkMatrixPriv.h"
commit-bot@chromium.org08284e42013-07-24 18:08:08 +000010#include "SkMatrixUtils.h"
Cary Clarke4442cb2017-10-18 11:46:18 -040011#include "SkPoint3.h"
bsalomon@google.com38396322011-09-09 19:32:04 +000012#include "SkRandom.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000013#include "Test.h"
reed@android.comed673312009-02-27 16:24:51 +000014
15static bool nearly_equal_scalar(SkScalar a, SkScalar b) {
epoger@google.com2047f002011-05-17 17:36:59 +000016 const SkScalar tolerance = SK_Scalar1 / 200000;
reed@android.comed673312009-02-27 16:24:51 +000017 return SkScalarAbs(a - b) <= tolerance;
18}
19
20static bool nearly_equal(const SkMatrix& a, const SkMatrix& b) {
21 for (int i = 0; i < 9; i++) {
22 if (!nearly_equal_scalar(a[i], b[i])) {
bungeman@google.comfab44db2013-10-11 18:50:45 +000023 SkDebugf("not equal %g %g\n", (float)a[i], (float)b[i]);
reed@android.comed673312009-02-27 16:24:51 +000024 return false;
25 }
26 }
27 return true;
28}
29
bsalomon@google.com8fe84b52012-03-26 15:24:27 +000030static bool are_equal(skiatest::Reporter* reporter,
31 const SkMatrix& a,
32 const SkMatrix& b) {
33 bool equal = a == b;
34 bool cheapEqual = a.cheapEqualTo(b);
35 if (equal != cheapEqual) {
bsalomon@google.com39d4f3a2012-03-26 17:25:45 +000036 if (equal) {
bsalomon@google.com8fe84b52012-03-26 15:24:27 +000037 bool foundZeroSignDiff = false;
38 for (int i = 0; i < 9; ++i) {
39 float aVal = a.get(i);
40 float bVal = b.get(i);
bsalomon@google.com373ebc62012-09-26 13:08:56 +000041 int aValI = *SkTCast<int*>(&aVal);
42 int bValI = *SkTCast<int*>(&bVal);
bsalomon@google.com8fe84b52012-03-26 15:24:27 +000043 if (0 == aVal && 0 == bVal && aValI != bValI) {
44 foundZeroSignDiff = true;
45 } else {
halcanarye76ca8b2016-05-20 10:36:50 -070046 REPORTER_ASSERT(reporter, aVal == bVal && aValI == bValI);
bsalomon@google.com8fe84b52012-03-26 15:24:27 +000047 }
48 }
49 REPORTER_ASSERT(reporter, foundZeroSignDiff);
50 } else {
51 bool foundNaN = false;
52 for (int i = 0; i < 9; ++i) {
53 float aVal = a.get(i);
54 float bVal = b.get(i);
bsalomon@google.com373ebc62012-09-26 13:08:56 +000055 int aValI = *SkTCast<int*>(&aVal);
56 int bValI = *SkTCast<int*>(&bVal);
bsalomon@google.com8fe84b52012-03-26 15:24:27 +000057 if (sk_float_isnan(aVal) && aValI == bValI) {
58 foundNaN = true;
59 } else {
60 REPORTER_ASSERT(reporter, aVal == bVal && aValI == bValI);
61 }
62 }
63 REPORTER_ASSERT(reporter, foundNaN);
64 }
bsalomon@google.com8fe84b52012-03-26 15:24:27 +000065 }
66 return equal;
67}
68
reed@android.comed673312009-02-27 16:24:51 +000069static bool is_identity(const SkMatrix& m) {
70 SkMatrix identity;
reed@android.com80e39a72009-04-02 16:59:40 +000071 identity.reset();
reed@android.comed673312009-02-27 16:24:51 +000072 return nearly_equal(m, identity);
73}
74
reed451e8222014-12-13 08:46:48 -080075static void assert9(skiatest::Reporter* reporter, const SkMatrix& m,
76 SkScalar a, SkScalar b, SkScalar c,
77 SkScalar d, SkScalar e, SkScalar f,
78 SkScalar g, SkScalar h, SkScalar i) {
79 SkScalar buffer[9];
80 m.get9(buffer);
81 REPORTER_ASSERT(reporter, buffer[0] == a);
82 REPORTER_ASSERT(reporter, buffer[1] == b);
83 REPORTER_ASSERT(reporter, buffer[2] == c);
84 REPORTER_ASSERT(reporter, buffer[3] == d);
85 REPORTER_ASSERT(reporter, buffer[4] == e);
86 REPORTER_ASSERT(reporter, buffer[5] == f);
87 REPORTER_ASSERT(reporter, buffer[6] == g);
88 REPORTER_ASSERT(reporter, buffer[7] == h);
89 REPORTER_ASSERT(reporter, buffer[8] == i);
90}
91
92static void test_set9(skiatest::Reporter* reporter) {
93
94 SkMatrix m;
95 m.reset();
96 assert9(reporter, m, 1, 0, 0, 0, 1, 0, 0, 0, 1);
halcanary9d524f22016-03-29 09:03:52 -070097
reed451e8222014-12-13 08:46:48 -080098 m.setScale(2, 3);
99 assert9(reporter, m, 2, 0, 0, 0, 3, 0, 0, 0, 1);
halcanary9d524f22016-03-29 09:03:52 -0700100
reed451e8222014-12-13 08:46:48 -0800101 m.postTranslate(4, 5);
102 assert9(reporter, m, 2, 0, 4, 0, 3, 5, 0, 0, 1);
103
104 SkScalar buffer[9];
105 sk_bzero(buffer, sizeof(buffer));
106 buffer[SkMatrix::kMScaleX] = 1;
107 buffer[SkMatrix::kMScaleY] = 1;
108 buffer[SkMatrix::kMPersp2] = 1;
109 REPORTER_ASSERT(reporter, !m.isIdentity());
110 m.set9(buffer);
111 REPORTER_ASSERT(reporter, m.isIdentity());
112}
113
reed@google.com97cd69c2012-10-12 14:35:48 +0000114static void test_matrix_recttorect(skiatest::Reporter* reporter) {
115 SkRect src, dst;
116 SkMatrix matrix;
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000117
reed@google.com97cd69c2012-10-12 14:35:48 +0000118 src.set(0, 0, SK_Scalar1*10, SK_Scalar1*10);
119 dst = src;
120 matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
121 REPORTER_ASSERT(reporter, SkMatrix::kIdentity_Mask == matrix.getType());
122 REPORTER_ASSERT(reporter, matrix.rectStaysRect());
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000123
reed@google.com97cd69c2012-10-12 14:35:48 +0000124 dst.offset(SK_Scalar1, SK_Scalar1);
125 matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
126 REPORTER_ASSERT(reporter, SkMatrix::kTranslate_Mask == matrix.getType());
127 REPORTER_ASSERT(reporter, matrix.rectStaysRect());
skia.committer@gmail.comf57c01b2012-10-13 02:01:56 +0000128
reed@google.com97cd69c2012-10-12 14:35:48 +0000129 dst.fRight += SK_Scalar1;
130 matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
skia.committer@gmail.come659c2e2012-12-04 02:01:25 +0000131 REPORTER_ASSERT(reporter,
robertphillips@google.com93f03322012-12-03 17:35:19 +0000132 (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask) == matrix.getType());
reed@google.com97cd69c2012-10-12 14:35:48 +0000133 REPORTER_ASSERT(reporter, matrix.rectStaysRect());
134
135 dst = src;
136 dst.fRight = src.fRight * 2;
137 matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
138 REPORTER_ASSERT(reporter, SkMatrix::kScale_Mask == matrix.getType());
139 REPORTER_ASSERT(reporter, matrix.rectStaysRect());
140}
141
reed@android.com4b7577b2009-06-29 16:14:41 +0000142static void test_flatten(skiatest::Reporter* reporter, const SkMatrix& m) {
143 // add 100 in case we have a bug, I don't want to kill my stack in the test
Cary Clark6d6d6032017-10-20 12:14:33 -0400144 static const size_t kBufferSize = SkMatrixPriv::kMaxFlattenSize + 100;
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +0000145 char buffer[kBufferSize];
Cary Clark6d6d6032017-10-20 12:14:33 -0400146 size_t size1 = SkMatrixPriv::WriteToMemory(m, nullptr);
147 size_t size2 = SkMatrixPriv::WriteToMemory(m, buffer);
reed@android.com4b7577b2009-06-29 16:14:41 +0000148 REPORTER_ASSERT(reporter, size1 == size2);
Cary Clark6d6d6032017-10-20 12:14:33 -0400149 REPORTER_ASSERT(reporter, size1 <= SkMatrixPriv::kMaxFlattenSize);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000150
reed@android.com4b7577b2009-06-29 16:14:41 +0000151 SkMatrix m2;
Cary Clark6d6d6032017-10-20 12:14:33 -0400152 size_t size3 = SkMatrixPriv::ReadFromMemory(&m2, buffer, kBufferSize);
djsollen@google.com94e75ee2012-06-08 18:30:46 +0000153 REPORTER_ASSERT(reporter, size1 == size3);
bsalomon@google.com8fe84b52012-03-26 15:24:27 +0000154 REPORTER_ASSERT(reporter, are_equal(reporter, m, m2));
rmistry@google.comd6176b02012-08-23 18:14:13 +0000155
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +0000156 char buffer2[kBufferSize];
Cary Clark6d6d6032017-10-20 12:14:33 -0400157 size3 = SkMatrixPriv::WriteToMemory(m2, buffer2);
djsollen@google.com94e75ee2012-06-08 18:30:46 +0000158 REPORTER_ASSERT(reporter, size1 == size3);
reed@android.com4b7577b2009-06-29 16:14:41 +0000159 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
160}
161
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000162static void test_matrix_min_max_scale(skiatest::Reporter* reporter) {
commit-bot@chromium.org311a3cd2014-05-20 17:02:03 +0000163 SkScalar scales[2];
164 bool success;
165
bsalomon@google.com38396322011-09-09 19:32:04 +0000166 SkMatrix identity;
167 identity.reset();
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000168 REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMinScale());
169 REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMaxScale());
commit-bot@chromium.org311a3cd2014-05-20 17:02:03 +0000170 success = identity.getMinMaxScales(scales);
171 REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 == scales[1]);
bsalomon@google.com38396322011-09-09 19:32:04 +0000172
173 SkMatrix scale;
174 scale.setScale(SK_Scalar1 * 2, SK_Scalar1 * 4);
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000175 REPORTER_ASSERT(reporter, SK_Scalar1 * 2 == scale.getMinScale());
176 REPORTER_ASSERT(reporter, SK_Scalar1 * 4 == scale.getMaxScale());
commit-bot@chromium.org311a3cd2014-05-20 17:02:03 +0000177 success = scale.getMinMaxScales(scales);
178 REPORTER_ASSERT(reporter, success && SK_Scalar1 * 2 == scales[0] && SK_Scalar1 * 4 == scales[1]);
bsalomon@google.com38396322011-09-09 19:32:04 +0000179
180 SkMatrix rot90Scale;
181 rot90Scale.setRotate(90 * SK_Scalar1);
182 rot90Scale.postScale(SK_Scalar1 / 4, SK_Scalar1 / 2);
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000183 REPORTER_ASSERT(reporter, SK_Scalar1 / 4 == rot90Scale.getMinScale());
184 REPORTER_ASSERT(reporter, SK_Scalar1 / 2 == rot90Scale.getMaxScale());
commit-bot@chromium.org311a3cd2014-05-20 17:02:03 +0000185 success = rot90Scale.getMinMaxScales(scales);
186 REPORTER_ASSERT(reporter, success && SK_Scalar1 / 4 == scales[0] && SK_Scalar1 / 2 == scales[1]);
bsalomon@google.com38396322011-09-09 19:32:04 +0000187
188 SkMatrix rotate;
189 rotate.setRotate(128 * SK_Scalar1);
commit-bot@chromium.org311a3cd2014-05-20 17:02:03 +0000190 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMinScale(), SK_ScalarNearlyZero));
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000191 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMaxScale(), SK_ScalarNearlyZero));
commit-bot@chromium.org311a3cd2014-05-20 17:02:03 +0000192 success = rotate.getMinMaxScales(scales);
193 REPORTER_ASSERT(reporter, success);
194 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, scales[0], SK_ScalarNearlyZero));
195 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, scales[1], SK_ScalarNearlyZero));
bsalomon@google.com38396322011-09-09 19:32:04 +0000196
197 SkMatrix translate;
198 translate.setTranslate(10 * SK_Scalar1, -5 * SK_Scalar1);
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000199 REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMinScale());
200 REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMaxScale());
commit-bot@chromium.org311a3cd2014-05-20 17:02:03 +0000201 success = translate.getMinMaxScales(scales);
202 REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 == scales[1]);
bsalomon@google.com38396322011-09-09 19:32:04 +0000203
204 SkMatrix perspX;
205 perspX.reset();
reed3f43f8a2015-01-20 19:58:36 -0800206 perspX.setPerspX(SK_Scalar1 / 1000);
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000207 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMinScale());
208 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMaxScale());
commit-bot@chromium.org311a3cd2014-05-20 17:02:03 +0000209 success = perspX.getMinMaxScales(scales);
bsalomonef2c7c72015-12-17 15:33:13 -0800210 REPORTER_ASSERT(reporter, !success);
211
212 // skbug.com/4718
213 SkMatrix big;
214 big.setAll(2.39394089e+36f, 8.85347779e+36f, 9.26526204e+36f,
215 3.9159619e+36f, 1.44823453e+37f, 1.51559342e+37f,
216 0.f, 0.f, 1.f);
bsalomonef2c7c72015-12-17 15:33:13 -0800217 success = big.getMinMaxScales(scales);
218 REPORTER_ASSERT(reporter, !success);
bsalomon@google.com38396322011-09-09 19:32:04 +0000219
kolczykcea22ae2016-07-16 11:52:37 -0700220 // skbug.com/4718
221 SkMatrix givingNegativeNearlyZeros;
222 givingNegativeNearlyZeros.setAll(0.00436534f, 0.114138f, 0.37141f,
223 0.00358857f, 0.0936228f, -0.0174198f,
224 0.f, 0.f, 1.f);
225 success = givingNegativeNearlyZeros.getMinMaxScales(scales);
226 REPORTER_ASSERT(reporter, success && 0 == scales[0]);
227
bsalomon@google.com38396322011-09-09 19:32:04 +0000228 SkMatrix perspY;
229 perspY.reset();
reed3f43f8a2015-01-20 19:58:36 -0800230 perspY.setPerspY(-SK_Scalar1 / 500);
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000231 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMinScale());
232 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxScale());
commit-bot@chromium.org311a3cd2014-05-20 17:02:03 +0000233 scales[0] = -5;
234 scales[1] = -5;
235 success = perspY.getMinMaxScales(scales);
236 REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * SK_Scalar1 == scales[1]);
bsalomon@google.com38396322011-09-09 19:32:04 +0000237
238 SkMatrix baseMats[] = {scale, rot90Scale, rotate,
239 translate, perspX, perspY};
240 SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)];
tomhudson@google.com83a44462011-10-27 15:27:51 +0000241 for (size_t i = 0; i < SK_ARRAY_COUNT(baseMats); ++i) {
bsalomon@google.com38396322011-09-09 19:32:04 +0000242 mats[i] = baseMats[i];
bungemane55131c2016-08-24 12:01:31 -0700243 bool invertible = mats[i].invert(&mats[i + SK_ARRAY_COUNT(baseMats)]);
244 REPORTER_ASSERT(reporter, invertible);
bsalomon@google.com38396322011-09-09 19:32:04 +0000245 }
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000246 SkRandom rand;
bsalomon@google.com38396322011-09-09 19:32:04 +0000247 for (int m = 0; m < 1000; ++m) {
248 SkMatrix mat;
249 mat.reset();
250 for (int i = 0; i < 4; ++i) {
251 int x = rand.nextU() % SK_ARRAY_COUNT(mats);
252 mat.postConcat(mats[x]);
253 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000254
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000255 SkScalar minScale = mat.getMinScale();
256 SkScalar maxScale = mat.getMaxScale();
257 REPORTER_ASSERT(reporter, (minScale < 0) == (maxScale < 0));
258 REPORTER_ASSERT(reporter, (maxScale < 0) == mat.hasPerspective());
bsalomon@google.com38396322011-09-09 19:32:04 +0000259
commit-bot@chromium.org311a3cd2014-05-20 17:02:03 +0000260 SkScalar scales[2];
261 bool success = mat.getMinMaxScales(scales);
262 REPORTER_ASSERT(reporter, success == !mat.hasPerspective());
263 REPORTER_ASSERT(reporter, !success || (scales[0] == minScale && scales[1] == maxScale));
264
bsalomon@google.com38396322011-09-09 19:32:04 +0000265 if (mat.hasPerspective()) {
266 m -= 1; // try another non-persp matrix
267 continue;
268 }
269
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000270 // test a bunch of vectors. All should be scaled by between minScale and maxScale
commit-bot@chromium.orgcea9abb2013-12-09 19:15:37 +0000271 // (modulo some error) and we should find a vector that is scaled by almost each.
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000272 static const SkScalar gVectorScaleTol = (105 * SK_Scalar1) / 100;
273 static const SkScalar gCloseScaleTol = (97 * SK_Scalar1) / 100;
commit-bot@chromium.orgcea9abb2013-12-09 19:15:37 +0000274 SkScalar max = 0, min = SK_ScalarMax;
bsalomon@google.com38396322011-09-09 19:32:04 +0000275 SkVector vectors[1000];
tomhudson@google.com83a44462011-10-27 15:27:51 +0000276 for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) {
bsalomon@google.com38396322011-09-09 19:32:04 +0000277 vectors[i].fX = rand.nextSScalar1();
278 vectors[i].fY = rand.nextSScalar1();
279 if (!vectors[i].normalize()) {
280 i -= 1;
281 continue;
282 }
283 }
284 mat.mapVectors(vectors, SK_ARRAY_COUNT(vectors));
tomhudson@google.com83a44462011-10-27 15:27:51 +0000285 for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) {
bsalomon@google.com38396322011-09-09 19:32:04 +0000286 SkScalar d = vectors[i].length();
reed80ea19c2015-05-12 10:37:34 -0700287 REPORTER_ASSERT(reporter, d / maxScale < gVectorScaleTol);
288 REPORTER_ASSERT(reporter, minScale / d < gVectorScaleTol);
bsalomon@google.com38396322011-09-09 19:32:04 +0000289 if (max < d) {
290 max = d;
291 }
commit-bot@chromium.orgcea9abb2013-12-09 19:15:37 +0000292 if (min > d) {
293 min = d;
294 }
bsalomon@google.com38396322011-09-09 19:32:04 +0000295 }
reed80ea19c2015-05-12 10:37:34 -0700296 REPORTER_ASSERT(reporter, max / maxScale >= gCloseScaleTol);
297 REPORTER_ASSERT(reporter, minScale / min >= gCloseScaleTol);
bsalomon@google.com38396322011-09-09 19:32:04 +0000298 }
299}
300
jvanverth17a845f2014-09-02 13:15:40 -0700301static void test_matrix_preserve_shape(skiatest::Reporter* reporter) {
bsalomon@google.com69afee12012-04-25 15:07:40 +0000302 SkMatrix mat;
303
304 // identity
305 mat.setIdentity();
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000306 REPORTER_ASSERT(reporter, mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700307 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000308
309 // translation only
310 mat.reset();
311 mat.setTranslate(SkIntToScalar(100), SkIntToScalar(100));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000312 REPORTER_ASSERT(reporter, mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700313 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000314
315 // scale with same size
316 mat.reset();
317 mat.setScale(SkIntToScalar(15), SkIntToScalar(15));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000318 REPORTER_ASSERT(reporter, mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700319 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000320
321 // scale with one negative
322 mat.reset();
323 mat.setScale(SkIntToScalar(-15), SkIntToScalar(15));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000324 REPORTER_ASSERT(reporter, mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700325 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000326
327 // scale with different size
328 mat.reset();
329 mat.setScale(SkIntToScalar(15), SkIntToScalar(20));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000330 REPORTER_ASSERT(reporter, !mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700331 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000332
333 // scale with same size at a pivot point
334 mat.reset();
335 mat.setScale(SkIntToScalar(15), SkIntToScalar(15),
336 SkIntToScalar(2), SkIntToScalar(2));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000337 REPORTER_ASSERT(reporter, mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700338 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000339
340 // scale with different size at a pivot point
341 mat.reset();
342 mat.setScale(SkIntToScalar(15), SkIntToScalar(20),
343 SkIntToScalar(2), SkIntToScalar(2));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000344 REPORTER_ASSERT(reporter, !mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700345 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000346
347 // skew with same size
348 mat.reset();
349 mat.setSkew(SkIntToScalar(15), SkIntToScalar(15));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000350 REPORTER_ASSERT(reporter, !mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700351 REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000352
353 // skew with different size
354 mat.reset();
355 mat.setSkew(SkIntToScalar(15), SkIntToScalar(20));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000356 REPORTER_ASSERT(reporter, !mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700357 REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000358
359 // skew with same size at a pivot point
360 mat.reset();
361 mat.setSkew(SkIntToScalar(15), SkIntToScalar(15),
362 SkIntToScalar(2), SkIntToScalar(2));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000363 REPORTER_ASSERT(reporter, !mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700364 REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000365
366 // skew with different size at a pivot point
367 mat.reset();
368 mat.setSkew(SkIntToScalar(15), SkIntToScalar(20),
369 SkIntToScalar(2), SkIntToScalar(2));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000370 REPORTER_ASSERT(reporter, !mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700371 REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000372
373 // perspective x
374 mat.reset();
reed3f43f8a2015-01-20 19:58:36 -0800375 mat.setPerspX(SK_Scalar1 / 2);
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000376 REPORTER_ASSERT(reporter, !mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700377 REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000378
379 // perspective y
380 mat.reset();
reed3f43f8a2015-01-20 19:58:36 -0800381 mat.setPerspY(SK_Scalar1 / 2);
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000382 REPORTER_ASSERT(reporter, !mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700383 REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000384
bsalomon@google.com69afee12012-04-25 15:07:40 +0000385 // rotate
386 for (int angle = 0; angle < 360; ++angle) {
387 mat.reset();
388 mat.setRotate(SkIntToScalar(angle));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000389 REPORTER_ASSERT(reporter, mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700390 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000391 }
392
393 // see if there are any accumulated precision issues
394 mat.reset();
395 for (int i = 1; i < 360; i++) {
396 mat.postRotate(SkIntToScalar(1));
397 }
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000398 REPORTER_ASSERT(reporter, mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700399 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000400
401 // rotate + translate
402 mat.reset();
403 mat.setRotate(SkIntToScalar(30));
404 mat.postTranslate(SkIntToScalar(10), SkIntToScalar(20));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000405 REPORTER_ASSERT(reporter, mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700406 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000407
408 // rotate + uniform scale
409 mat.reset();
410 mat.setRotate(SkIntToScalar(30));
411 mat.postScale(SkIntToScalar(2), SkIntToScalar(2));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000412 REPORTER_ASSERT(reporter, mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700413 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000414
415 // rotate + non-uniform scale
416 mat.reset();
417 mat.setRotate(SkIntToScalar(30));
418 mat.postScale(SkIntToScalar(3), SkIntToScalar(2));
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000419 REPORTER_ASSERT(reporter, !mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700420 REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
421
422 // non-uniform scale + rotate
423 mat.reset();
424 mat.setScale(SkIntToScalar(3), SkIntToScalar(2));
425 mat.postRotate(SkIntToScalar(30));
426 REPORTER_ASSERT(reporter, !mat.isSimilarity());
427 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000428
429 // all zero
430 mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0);
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000431 REPORTER_ASSERT(reporter, !mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700432 REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000433
434 // all zero except perspective
jvanverth17a845f2014-09-02 13:15:40 -0700435 mat.reset();
bsalomon@google.com69afee12012-04-25 15:07:40 +0000436 mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, SK_Scalar1);
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000437 REPORTER_ASSERT(reporter, !mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700438 REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000439
jvanverth17a845f2014-09-02 13:15:40 -0700440 // scales zero, only skews (rotation)
441 mat.setAll(0, SK_Scalar1, 0,
442 -SK_Scalar1, 0, 0,
443 0, 0, SkMatrix::I()[8]);
444 REPORTER_ASSERT(reporter, mat.isSimilarity());
445 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
446
447 // scales zero, only skews (reflection)
bsalomon@google.com69afee12012-04-25 15:07:40 +0000448 mat.setAll(0, SK_Scalar1, 0,
449 SK_Scalar1, 0, 0,
450 0, 0, SkMatrix::I()[8]);
jvanverth@google.com46d3d392013-01-22 13:34:01 +0000451 REPORTER_ASSERT(reporter, mat.isSimilarity());
jvanverth17a845f2014-09-02 13:15:40 -0700452 REPORTER_ASSERT(reporter, mat.preservesRightAngles());
bsalomon@google.com69afee12012-04-25 15:07:40 +0000453}
454
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000455// For test_matrix_decomposition, below.
skia.committer@gmail.com5c561cb2013-07-25 07:01:00 +0000456static bool scalar_nearly_equal_relative(SkScalar a, SkScalar b,
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000457 SkScalar tolerance = SK_ScalarNearlyZero) {
458 // from Bruce Dawson
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000459 // absolute check
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000460 SkScalar diff = SkScalarAbs(a - b);
461 if (diff < tolerance) {
462 return true;
463 }
464
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000465 // relative check
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000466 a = SkScalarAbs(a);
467 b = SkScalarAbs(b);
468 SkScalar largest = (b > a) ? b : a;
469
470 if (diff <= largest*tolerance) {
471 return true;
472 }
473
474 return false;
475}
476
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000477static bool check_matrix_recomposition(const SkMatrix& mat,
478 const SkPoint& rotation1,
479 const SkPoint& scale,
480 const SkPoint& rotation2) {
481 SkScalar c1 = rotation1.fX;
482 SkScalar s1 = rotation1.fY;
483 SkScalar scaleX = scale.fX;
484 SkScalar scaleY = scale.fY;
485 SkScalar c2 = rotation2.fX;
486 SkScalar s2 = rotation2.fY;
skia.committer@gmail.com85092f02013-09-04 07:01:39 +0000487
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000488 // We do a relative check here because large scale factors cause problems with an absolute check
489 bool result = scalar_nearly_equal_relative(mat[SkMatrix::kMScaleX],
490 scaleX*c1*c2 - scaleY*s1*s2) &&
491 scalar_nearly_equal_relative(mat[SkMatrix::kMSkewX],
492 -scaleX*s1*c2 - scaleY*c1*s2) &&
493 scalar_nearly_equal_relative(mat[SkMatrix::kMSkewY],
494 scaleX*c1*s2 + scaleY*s1*c2) &&
495 scalar_nearly_equal_relative(mat[SkMatrix::kMScaleY],
496 -scaleX*s1*s2 + scaleY*c1*c2);
497 return result;
498}
499
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000500static void test_matrix_decomposition(skiatest::Reporter* reporter) {
501 SkMatrix mat;
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000502 SkPoint rotation1, scale, rotation2;
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000503
504 const float kRotation0 = 15.5f;
505 const float kRotation1 = -50.f;
506 const float kScale0 = 5000.f;
507 const float kScale1 = 0.001f;
508
509 // identity
510 mat.reset();
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000511 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
512 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000513 // make sure it doesn't crash if we pass in NULLs
halcanary96fcdcc2015-08-27 07:41:13 -0700514 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, nullptr, nullptr, nullptr));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000515
516 // rotation only
517 mat.setRotate(kRotation0);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000518 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
519 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000520
521 // uniform scale only
522 mat.setScale(kScale0, kScale0);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000523 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
524 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000525
526 // anisotropic scale only
527 mat.setScale(kScale1, kScale0);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000528 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
529 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000530
531 // rotation then uniform scale
532 mat.setRotate(kRotation1);
533 mat.postScale(kScale0, kScale0);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000534 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
535 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000536
537 // uniform scale then rotation
538 mat.setScale(kScale0, kScale0);
539 mat.postRotate(kRotation1);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000540 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
541 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000542
543 // rotation then uniform scale+reflection
544 mat.setRotate(kRotation0);
545 mat.postScale(kScale1, -kScale1);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000546 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
547 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000548
549 // uniform scale+reflection, then rotate
550 mat.setScale(kScale0, -kScale0);
551 mat.postRotate(kRotation1);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000552 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
553 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000554
555 // rotation then anisotropic scale
556 mat.setRotate(kRotation1);
557 mat.postScale(kScale1, kScale0);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000558 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
559 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000560
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000561 // rotation then anisotropic scale
562 mat.setRotate(90);
563 mat.postScale(kScale1, kScale0);
564 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
565 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
skia.committer@gmail.com85092f02013-09-04 07:01:39 +0000566
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000567 // anisotropic scale then rotation
568 mat.setScale(kScale1, kScale0);
569 mat.postRotate(kRotation0);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000570 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
571 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
skia.committer@gmail.com85092f02013-09-04 07:01:39 +0000572
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000573 // anisotropic scale then rotation
574 mat.setScale(kScale1, kScale0);
575 mat.postRotate(90);
576 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
577 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000578
579 // rotation, uniform scale, then different rotation
580 mat.setRotate(kRotation1);
581 mat.postScale(kScale0, kScale0);
582 mat.postRotate(kRotation0);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000583 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
584 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000585
586 // rotation, anisotropic scale, then different rotation
587 mat.setRotate(kRotation0);
588 mat.postScale(kScale1, kScale0);
589 mat.postRotate(kRotation1);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000590 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
591 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
skia.committer@gmail.com85092f02013-09-04 07:01:39 +0000592
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000593 // rotation, anisotropic scale + reflection, then different rotation
594 mat.setRotate(kRotation0);
595 mat.postScale(-kScale1, kScale0);
596 mat.postRotate(kRotation1);
597 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
598 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000599
600 // try some random matrices
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000601 SkRandom rand;
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000602 for (int m = 0; m < 1000; ++m) {
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000603 SkScalar rot0 = rand.nextRangeF(-180, 180);
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000604 SkScalar sx = rand.nextRangeF(-3000.f, 3000.f);
605 SkScalar sy = rand.nextRangeF(-3000.f, 3000.f);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000606 SkScalar rot1 = rand.nextRangeF(-180, 180);
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000607 mat.setRotate(rot0);
608 mat.postScale(sx, sy);
609 mat.postRotate(rot1);
610
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000611 if (SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)) {
612 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000613 } else {
614 // if the matrix is degenerate, the basis vectors should be near-parallel or near-zero
615 SkScalar perpdot = mat[SkMatrix::kMScaleX]*mat[SkMatrix::kMScaleY] -
616 mat[SkMatrix::kMSkewX]*mat[SkMatrix::kMSkewY];
617 REPORTER_ASSERT(reporter, SkScalarNearlyZero(perpdot));
618 }
619 }
620
621 // translation shouldn't affect this
622 mat.postTranslate(-1000.f, 1000.f);
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000623 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
624 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000625
626 // perspective shouldn't affect this
jvanverth@google.com588f3d32013-07-24 18:44:10 +0000627 mat[SkMatrix::kMPersp0] = 12.f;
628 mat[SkMatrix::kMPersp1] = 4.f;
629 mat[SkMatrix::kMPersp2] = 1872.f;
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000630 REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
631 REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000632
633 // degenerate matrices
634 // mostly zero entries
635 mat.reset();
636 mat[SkMatrix::kMScaleX] = 0.f;
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000637 REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000638 mat.reset();
639 mat[SkMatrix::kMScaleY] = 0.f;
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000640 REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000641 mat.reset();
642 // linearly dependent entries
643 mat[SkMatrix::kMScaleX] = 1.f;
644 mat[SkMatrix::kMSkewX] = 2.f;
645 mat[SkMatrix::kMSkewY] = 4.f;
646 mat[SkMatrix::kMScaleY] = 8.f;
commit-bot@chromium.org5b2e2642013-09-03 19:08:14 +0000647 REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000648}
649
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000650// For test_matrix_homogeneous, below.
Cary Clarke4442cb2017-10-18 11:46:18 -0400651static bool point3_array_nearly_equal_relative(const SkPoint3 a[], const SkPoint3 b[], int count) {
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000652 for (int i = 0; i < count; ++i) {
Cary Clarke4442cb2017-10-18 11:46:18 -0400653 if (!scalar_nearly_equal_relative(a[i].fX, b[i].fX)) {
654 return false;
655 }
656 if (!scalar_nearly_equal_relative(a[i].fY, b[i].fY)) {
657 return false;
658 }
659 if (!scalar_nearly_equal_relative(a[i].fZ, b[i].fZ)) {
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000660 return false;
661 }
662 }
663 return true;
664}
665
666// For test_matrix_homogeneous, below.
667// Maps a single triple in src using m and compares results to those in dst
Cary Clarke4442cb2017-10-18 11:46:18 -0400668static bool naive_homogeneous_mapping(const SkMatrix& m, const SkPoint3& src,
669 const SkPoint3& dst) {
670 SkPoint3 res;
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000671 SkScalar ms[9] = {m[0], m[1], m[2],
672 m[3], m[4], m[5],
673 m[6], m[7], m[8]};
Cary Clarke4442cb2017-10-18 11:46:18 -0400674 res.fX = src.fX * ms[0] + src.fY * ms[1] + src.fZ * ms[2];
675 res.fY = src.fX * ms[3] + src.fY * ms[4] + src.fZ * ms[5];
676 res.fZ = src.fX * ms[6] + src.fY * ms[7] + src.fZ * ms[8];
677 return point3_array_nearly_equal_relative(&res, &dst, 1);
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000678}
679
680static void test_matrix_homogeneous(skiatest::Reporter* reporter) {
681 SkMatrix mat;
682
683 const float kRotation0 = 15.5f;
684 const float kRotation1 = -50.f;
685 const float kScale0 = 5000.f;
686
Mike Klein6613cc52017-12-19 09:09:33 -0500687#if defined(SK_BUILD_FOR_GOOGLE3)
688 // Stack frame size is limited in SK_BUILD_FOR_GOOGLE3.
benjaminwagner7d974f52015-10-19 13:55:55 -0700689 const int kTripleCount = 100;
690 const int kMatrixCount = 100;
691#else
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000692 const int kTripleCount = 1000;
693 const int kMatrixCount = 1000;
benjaminwagner7d974f52015-10-19 13:55:55 -0700694#endif
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000695 SkRandom rand;
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000696
Cary Clarke4442cb2017-10-18 11:46:18 -0400697 SkPoint3 randTriples[kTripleCount];
698 for (int i = 0; i < kTripleCount; ++i) {
699 randTriples[i].fX = rand.nextRangeF(-3000.f, 3000.f);
700 randTriples[i].fY = rand.nextRangeF(-3000.f, 3000.f);
701 randTriples[i].fZ = rand.nextRangeF(-3000.f, 3000.f);
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000702 }
703
704 SkMatrix mats[kMatrixCount];
705 for (int i = 0; i < kMatrixCount; ++i) {
706 for (int j = 0; j < 9; ++j) {
707 mats[i].set(j, rand.nextRangeF(-3000.f, 3000.f));
708 }
709 }
710
711 // identity
712 {
713 mat.reset();
Cary Clarke4442cb2017-10-18 11:46:18 -0400714 SkPoint3 dst[kTripleCount];
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000715 mat.mapHomogeneousPoints(dst, randTriples, kTripleCount);
Cary Clarke4442cb2017-10-18 11:46:18 -0400716 REPORTER_ASSERT(reporter, point3_array_nearly_equal_relative(randTriples, dst, kTripleCount));
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000717 }
718
Cary Clarke4442cb2017-10-18 11:46:18 -0400719 const SkPoint3 zeros = {0.f, 0.f, 0.f};
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000720 // zero matrix
721 {
722 mat.setAll(0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
Cary Clarke4442cb2017-10-18 11:46:18 -0400723 SkPoint3 dst[kTripleCount];
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000724 mat.mapHomogeneousPoints(dst, randTriples, kTripleCount);
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000725 for (int i = 0; i < kTripleCount; ++i) {
Cary Clarke4442cb2017-10-18 11:46:18 -0400726 REPORTER_ASSERT(reporter, point3_array_nearly_equal_relative(&dst[i], &zeros, 1));
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000727 }
728 }
729
730 // zero point
731 {
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000732 for (int i = 0; i < kMatrixCount; ++i) {
Cary Clarke4442cb2017-10-18 11:46:18 -0400733 SkPoint3 dst;
734 mats[i].mapHomogeneousPoints(&dst, &zeros, 1);
735 REPORTER_ASSERT(reporter, point3_array_nearly_equal_relative(&dst, &zeros, 1));
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000736 }
737 }
738
739 // doesn't crash with null dst, src, count == 0
740 {
halcanary96fcdcc2015-08-27 07:41:13 -0700741 mats[0].mapHomogeneousPoints(nullptr, nullptr, 0);
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000742 }
743
744 // uniform scale of point
745 {
746 mat.setScale(kScale0, kScale0);
Cary Clarke4442cb2017-10-18 11:46:18 -0400747 SkPoint3 dst;
748 SkPoint3 src = {randTriples[0].fX, randTriples[0].fY, 1.f};
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000749 SkPoint pnt;
Cary Clarke4442cb2017-10-18 11:46:18 -0400750 pnt.set(src.fX, src.fY);
751 mat.mapHomogeneousPoints(&dst, &src, 1);
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000752 mat.mapPoints(&pnt, &pnt, 1);
Cary Clarke4442cb2017-10-18 11:46:18 -0400753 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fX, pnt.fX));
754 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fY, pnt.fY));
755 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fZ, SK_Scalar1));
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000756 }
757
758 // rotation of point
759 {
760 mat.setRotate(kRotation0);
Cary Clarke4442cb2017-10-18 11:46:18 -0400761 SkPoint3 dst;
762 SkPoint3 src = {randTriples[0].fX, randTriples[0].fY, 1.f};
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000763 SkPoint pnt;
Cary Clarke4442cb2017-10-18 11:46:18 -0400764 pnt.set(src.fX, src.fY);
765 mat.mapHomogeneousPoints(&dst, &src, 1);
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000766 mat.mapPoints(&pnt, &pnt, 1);
Cary Clarke4442cb2017-10-18 11:46:18 -0400767 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fX, pnt.fX));
768 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fY, pnt.fY));
769 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fZ, SK_Scalar1));
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000770 }
771
772 // rotation, scale, rotation of point
773 {
774 mat.setRotate(kRotation1);
775 mat.postScale(kScale0, kScale0);
776 mat.postRotate(kRotation0);
Cary Clarke4442cb2017-10-18 11:46:18 -0400777 SkPoint3 dst;
778 SkPoint3 src = {randTriples[0].fX, randTriples[0].fY, 1.f};
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000779 SkPoint pnt;
Cary Clarke4442cb2017-10-18 11:46:18 -0400780 pnt.set(src.fX, src.fY);
781 mat.mapHomogeneousPoints(&dst, &src, 1);
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000782 mat.mapPoints(&pnt, &pnt, 1);
Cary Clarke4442cb2017-10-18 11:46:18 -0400783 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fX, pnt.fX));
784 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fY, pnt.fY));
785 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fZ, SK_Scalar1));
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000786 }
787
788 // compare with naive approach
789 {
790 for (int i = 0; i < kMatrixCount; ++i) {
791 for (int j = 0; j < kTripleCount; ++j) {
Cary Clarke4442cb2017-10-18 11:46:18 -0400792 SkPoint3 dst;
793 mats[i].mapHomogeneousPoints(&dst, &randTriples[j], 1);
794 REPORTER_ASSERT(reporter, naive_homogeneous_mapping(mats[i], randTriples[j], dst));
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000795 }
796 }
797 }
798
799}
800
reedadf99902015-03-19 16:10:54 -0700801static bool check_decompScale(const SkMatrix& matrix) {
802 SkSize scale;
803 SkMatrix remaining;
804
805 if (!matrix.decomposeScale(&scale, &remaining)) {
806 return false;
807 }
808 if (scale.width() <= 0 || scale.height() <= 0) {
809 return false;
810 }
811 remaining.preScale(scale.width(), scale.height());
812 return nearly_equal(matrix, remaining);
813}
814
815static void test_decompScale(skiatest::Reporter* reporter) {
816 SkMatrix m;
817
818 m.reset();
819 REPORTER_ASSERT(reporter, check_decompScale(m));
820 m.setScale(2, 3);
821 REPORTER_ASSERT(reporter, check_decompScale(m));
822 m.setRotate(35, 0, 0);
823 REPORTER_ASSERT(reporter, check_decompScale(m));
824
825 m.setScale(1, 0);
826 REPORTER_ASSERT(reporter, !check_decompScale(m));
827}
828
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +0000829DEF_TEST(Matrix, reporter) {
reed@android.comed673312009-02-27 16:24:51 +0000830 SkMatrix mat, inverse, iden1, iden2;
831
832 mat.reset();
833 mat.setTranslate(SK_Scalar1, SK_Scalar1);
reed@google.com5bfa55b2012-04-19 18:59:25 +0000834 REPORTER_ASSERT(reporter, mat.invert(&inverse));
reed@android.comed673312009-02-27 16:24:51 +0000835 iden1.setConcat(mat, inverse);
836 REPORTER_ASSERT(reporter, is_identity(iden1));
837
reed@google.com2fb96cc2013-01-04 17:02:33 +0000838 mat.setScale(SkIntToScalar(2), SkIntToScalar(4));
reed@google.com5bfa55b2012-04-19 18:59:25 +0000839 REPORTER_ASSERT(reporter, mat.invert(&inverse));
reed@android.comed673312009-02-27 16:24:51 +0000840 iden1.setConcat(mat, inverse);
841 REPORTER_ASSERT(reporter, is_identity(iden1));
reed@android.com4b7577b2009-06-29 16:14:41 +0000842 test_flatten(reporter, mat);
reed@android.comed673312009-02-27 16:24:51 +0000843
reed@google.com2fb96cc2013-01-04 17:02:33 +0000844 mat.setScale(SK_Scalar1/2, SkIntToScalar(2));
reed@google.com5bfa55b2012-04-19 18:59:25 +0000845 REPORTER_ASSERT(reporter, mat.invert(&inverse));
reed@android.comed673312009-02-27 16:24:51 +0000846 iden1.setConcat(mat, inverse);
847 REPORTER_ASSERT(reporter, is_identity(iden1));
reed@android.com4b7577b2009-06-29 16:14:41 +0000848 test_flatten(reporter, mat);
reed@android.comed673312009-02-27 16:24:51 +0000849
850 mat.setScale(SkIntToScalar(3), SkIntToScalar(5), SkIntToScalar(20), 0);
851 mat.postRotate(SkIntToScalar(25));
halcanary96fcdcc2015-08-27 07:41:13 -0700852 REPORTER_ASSERT(reporter, mat.invert(nullptr));
reed@google.com5bfa55b2012-04-19 18:59:25 +0000853 REPORTER_ASSERT(reporter, mat.invert(&inverse));
reed@android.comed673312009-02-27 16:24:51 +0000854 iden1.setConcat(mat, inverse);
855 REPORTER_ASSERT(reporter, is_identity(iden1));
856 iden2.setConcat(inverse, mat);
857 REPORTER_ASSERT(reporter, is_identity(iden2));
reed@android.com4b7577b2009-06-29 16:14:41 +0000858 test_flatten(reporter, mat);
859 test_flatten(reporter, iden2);
reed@android.com80e39a72009-04-02 16:59:40 +0000860
reed@google.com2fb96cc2013-01-04 17:02:33 +0000861 mat.setScale(0, SK_Scalar1);
halcanary96fcdcc2015-08-27 07:41:13 -0700862 REPORTER_ASSERT(reporter, !mat.invert(nullptr));
reed@google.com2fb96cc2013-01-04 17:02:33 +0000863 REPORTER_ASSERT(reporter, !mat.invert(&inverse));
864 mat.setScale(SK_Scalar1, 0);
halcanary96fcdcc2015-08-27 07:41:13 -0700865 REPORTER_ASSERT(reporter, !mat.invert(nullptr));
reed@google.com2fb96cc2013-01-04 17:02:33 +0000866 REPORTER_ASSERT(reporter, !mat.invert(&inverse));
867
robertphillips20eee3f2015-06-19 05:14:26 -0700868 // Inverting this matrix results in a non-finite matrix
869 mat.setAll(0.0f, 1.0f, 2.0f,
870 0.0f, 1.0f, -3.40277175e+38f,
871 1.00003040f, 1.0f, 0.0f);
halcanary96fcdcc2015-08-27 07:41:13 -0700872 REPORTER_ASSERT(reporter, !mat.invert(nullptr));
robertphillips20eee3f2015-06-19 05:14:26 -0700873 REPORTER_ASSERT(reporter, !mat.invert(&inverse));
874
reed@android.comed673312009-02-27 16:24:51 +0000875 // rectStaysRect test
876 {
877 static const struct {
878 SkScalar m00, m01, m10, m11;
879 bool mStaysRect;
880 }
881 gRectStaysRectSamples[] = {
882 { 0, 0, 0, 0, false },
883 { 0, 0, 0, SK_Scalar1, false },
884 { 0, 0, SK_Scalar1, 0, false },
885 { 0, 0, SK_Scalar1, SK_Scalar1, false },
886 { 0, SK_Scalar1, 0, 0, false },
887 { 0, SK_Scalar1, 0, SK_Scalar1, false },
888 { 0, SK_Scalar1, SK_Scalar1, 0, true },
889 { 0, SK_Scalar1, SK_Scalar1, SK_Scalar1, false },
890 { SK_Scalar1, 0, 0, 0, false },
891 { SK_Scalar1, 0, 0, SK_Scalar1, true },
892 { SK_Scalar1, 0, SK_Scalar1, 0, false },
893 { SK_Scalar1, 0, SK_Scalar1, SK_Scalar1, false },
894 { SK_Scalar1, SK_Scalar1, 0, 0, false },
895 { SK_Scalar1, SK_Scalar1, 0, SK_Scalar1, false },
896 { SK_Scalar1, SK_Scalar1, SK_Scalar1, 0, false },
897 { SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, false }
898 };
reed@android.com80e39a72009-04-02 16:59:40 +0000899
reed@android.comed673312009-02-27 16:24:51 +0000900 for (size_t i = 0; i < SK_ARRAY_COUNT(gRectStaysRectSamples); i++) {
901 SkMatrix m;
reed@android.com80e39a72009-04-02 16:59:40 +0000902
reed@android.comed673312009-02-27 16:24:51 +0000903 m.reset();
904 m.set(SkMatrix::kMScaleX, gRectStaysRectSamples[i].m00);
905 m.set(SkMatrix::kMSkewX, gRectStaysRectSamples[i].m01);
906 m.set(SkMatrix::kMSkewY, gRectStaysRectSamples[i].m10);
907 m.set(SkMatrix::kMScaleY, gRectStaysRectSamples[i].m11);
908 REPORTER_ASSERT(reporter,
909 m.rectStaysRect() == gRectStaysRectSamples[i].mStaysRect);
910 }
911 }
bungeman@google.com1ddd7c32011-07-13 19:41:55 +0000912
bungeman@google.comba7983e2011-07-13 20:18:16 +0000913 mat.reset();
bungeman@google.com1ddd7c32011-07-13 19:41:55 +0000914 mat.set(SkMatrix::kMScaleX, SkIntToScalar(1));
915 mat.set(SkMatrix::kMSkewX, SkIntToScalar(2));
916 mat.set(SkMatrix::kMTransX, SkIntToScalar(3));
917 mat.set(SkMatrix::kMSkewY, SkIntToScalar(4));
918 mat.set(SkMatrix::kMScaleY, SkIntToScalar(5));
919 mat.set(SkMatrix::kMTransY, SkIntToScalar(6));
bungeman@google.com1ddd7c32011-07-13 19:41:55 +0000920 SkScalar affine[6];
921 REPORTER_ASSERT(reporter, mat.asAffine(affine));
922
Mike Reedf0cb7a02017-10-13 13:26:00 +0000923 #define affineEqual(e) affine[SkMatrix::kA##e] == mat.get(SkMatrix::kM##e)
bungeman@google.com1ddd7c32011-07-13 19:41:55 +0000924 REPORTER_ASSERT(reporter, affineEqual(ScaleX));
925 REPORTER_ASSERT(reporter, affineEqual(SkewY));
926 REPORTER_ASSERT(reporter, affineEqual(SkewX));
927 REPORTER_ASSERT(reporter, affineEqual(ScaleY));
928 REPORTER_ASSERT(reporter, affineEqual(TransX));
929 REPORTER_ASSERT(reporter, affineEqual(TransY));
930 #undef affineEqual
931
reed3f43f8a2015-01-20 19:58:36 -0800932 mat.set(SkMatrix::kMPersp1, SK_Scalar1 / 2);
bungeman@google.com1ddd7c32011-07-13 19:41:55 +0000933 REPORTER_ASSERT(reporter, !mat.asAffine(affine));
bsalomon@google.com38396322011-09-09 19:32:04 +0000934
bsalomon@google.com8fe84b52012-03-26 15:24:27 +0000935 SkMatrix mat2;
936 mat2.reset();
937 mat.reset();
938 SkScalar zero = 0;
939 mat.set(SkMatrix::kMSkewX, -zero);
940 REPORTER_ASSERT(reporter, are_equal(reporter, mat, mat2));
941
942 mat2.reset();
943 mat.reset();
944 mat.set(SkMatrix::kMSkewX, SK_ScalarNaN);
945 mat2.set(SkMatrix::kMSkewX, SK_ScalarNaN);
946 REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2));
947
commit-bot@chromium.org18786512014-05-20 14:53:45 +0000948 test_matrix_min_max_scale(reporter);
jvanverth17a845f2014-09-02 13:15:40 -0700949 test_matrix_preserve_shape(reporter);
reed@google.com97cd69c2012-10-12 14:35:48 +0000950 test_matrix_recttorect(reporter);
commit-bot@chromium.org08284e42013-07-24 18:08:08 +0000951 test_matrix_decomposition(reporter);
egdaniel@google.com259fbaf2013-08-15 21:12:11 +0000952 test_matrix_homogeneous(reporter);
reed451e8222014-12-13 08:46:48 -0800953 test_set9(reporter);
reedadf99902015-03-19 16:10:54 -0700954
955 test_decompScale(reporter);
reed2dcb6152016-07-05 20:10:42 -0700956
957 mat.setScaleTranslate(2, 3, 1, 4);
958 mat2.setScale(2, 3);
959 mat2.postTranslate(1, 4);
960 REPORTER_ASSERT(reporter, mat == mat2);
reed@android.comed673312009-02-27 16:24:51 +0000961}
commit-bot@chromium.org99bd7d82014-05-19 15:51:12 +0000962
963DEF_TEST(Matrix_Concat, r) {
964 SkMatrix a;
965 a.setTranslate(10, 20);
966
967 SkMatrix b;
968 b.setScale(3, 5);
969
970 SkMatrix expected;
971 expected.setConcat(a,b);
972
973 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b));
974}
reed47df89e2016-06-30 06:38:54 -0700975
976// Test that all variants of maprect are correct.
977DEF_TEST(Matrix_maprects, r) {
978 const SkScalar scale = 1000;
Ben Wagner63fd7602017-10-09 15:45:33 -0400979
reed47df89e2016-06-30 06:38:54 -0700980 SkMatrix mat;
981 mat.setScale(2, 3);
982 mat.postTranslate(1, 4);
983
984 SkRandom rand;
985 for (int i = 0; i < 10000; ++i) {
986 SkRect src = SkRect::MakeLTRB(rand.nextSScalar1() * scale,
987 rand.nextSScalar1() * scale,
988 rand.nextSScalar1() * scale,
989 rand.nextSScalar1() * scale);
Cary Clarkc06754b2018-05-16 21:28:55 -0400990 SkRect dst[4];
Ben Wagner63fd7602017-10-09 15:45:33 -0400991
reed47df89e2016-06-30 06:38:54 -0700992 mat.mapPoints((SkPoint*)&dst[0].fLeft, (SkPoint*)&src.fLeft, 2);
993 dst[0].sort();
994 mat.mapRect(&dst[1], src);
halcanaryc5769b22016-08-10 07:13:21 -0700995 mat.mapRectScaleTranslate(&dst[2], src);
Cary Clarkc06754b2018-05-16 21:28:55 -0400996 dst[3] = mat.mapRect(src);
reed47df89e2016-06-30 06:38:54 -0700997
998 REPORTER_ASSERT(r, dst[0] == dst[1]);
999 REPORTER_ASSERT(r, dst[0] == dst[2]);
Cary Clarkc06754b2018-05-16 21:28:55 -04001000 REPORTER_ASSERT(r, dst[0] == dst[3]);
1001 }
1002
1003 // We should report nonfinite-ness after a mapping
1004 {
1005 // We have special-cases in mapRect for different matrix types
1006 SkMatrix m0 = SkMatrix::MakeScale(1e20f, 1e20f);
1007 SkMatrix m1; m1.setRotate(30); m1.postScale(1e20f, 1e20f);
1008
1009 for (const auto& m : { m0, m1 }) {
1010 SkRect rect = { 0, 0, 1e20f, 1e20f };
1011 REPORTER_ASSERT(r, rect.isFinite());
1012 rect = m.mapRect(rect);
1013 REPORTER_ASSERT(r, !rect.isFinite());
1014 }
reed47df89e2016-06-30 06:38:54 -07001015 }
1016}