• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
7 
8 #include "include/core/SkMath.h"
9 #include "include/core/SkPoint3.h"
10 #include "include/utils/SkRandom.h"
11 #include "src/core/SkMatrixPriv.h"
12 #include "src/core/SkMatrixUtils.h"
13 #include "tests/Test.h"
14 
nearly_equal_scalar(SkScalar a,SkScalar b)15 static bool nearly_equal_scalar(SkScalar a, SkScalar b) {
16     const SkScalar tolerance = SK_Scalar1 / 200000;
17     return SkScalarAbs(a - b) <= tolerance;
18 }
19 
nearly_equal(const SkMatrix & a,const SkMatrix & b)20 static 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])) {
23             SkDebugf("matrices not equal [%d] %g %g\n", i, (float)a[i], (float)b[i]);
24             return false;
25         }
26     }
27     return true;
28 }
29 
float_bits(float f)30 static int float_bits(float f) {
31     int result;
32     memcpy(&result, &f, 4);
33     return result;
34 }
35 
are_equal(skiatest::Reporter * reporter,const SkMatrix & a,const SkMatrix & b)36 static bool are_equal(skiatest::Reporter* reporter,
37                       const SkMatrix& a,
38                       const SkMatrix& b) {
39     bool equal = a == b;
40     bool cheapEqual = a.cheapEqualTo(b);
41     if (equal != cheapEqual) {
42         if (equal) {
43             bool foundZeroSignDiff = false;
44             for (int i = 0; i < 9; ++i) {
45                 float aVal = a.get(i);
46                 float bVal = b.get(i);
47                 int aValI = float_bits(aVal);
48                 int bValI = float_bits(bVal);
49                 if (0 == aVal && 0 == bVal && aValI != bValI) {
50                     foundZeroSignDiff = true;
51                 } else {
52                     REPORTER_ASSERT(reporter, aVal == bVal && aValI == bValI);
53                 }
54             }
55             REPORTER_ASSERT(reporter, foundZeroSignDiff);
56         } else {
57             bool foundNaN = false;
58             for (int i = 0; i < 9; ++i) {
59                 float aVal = a.get(i);
60                 float bVal = b.get(i);
61                 int aValI = float_bits(aVal);
62                 int bValI = float_bits(bVal);
63                 if (sk_float_isnan(aVal) && aValI == bValI) {
64                     foundNaN = true;
65                 } else {
66                     REPORTER_ASSERT(reporter, aVal == bVal && aValI == bValI);
67                 }
68             }
69             REPORTER_ASSERT(reporter, foundNaN);
70         }
71     }
72     return equal;
73 }
74 
is_identity(const SkMatrix & m)75 static bool is_identity(const SkMatrix& m) {
76     SkMatrix identity;
77     identity.reset();
78     return nearly_equal(m, identity);
79 }
80 
assert9(skiatest::Reporter * reporter,const SkMatrix & m,SkScalar a,SkScalar b,SkScalar c,SkScalar d,SkScalar e,SkScalar f,SkScalar g,SkScalar h,SkScalar i)81 static void assert9(skiatest::Reporter* reporter, const SkMatrix& m,
82                     SkScalar a, SkScalar b, SkScalar c,
83                     SkScalar d, SkScalar e, SkScalar f,
84                     SkScalar g, SkScalar h, SkScalar i) {
85     SkScalar buffer[9];
86     m.get9(buffer);
87     REPORTER_ASSERT(reporter, buffer[0] == a);
88     REPORTER_ASSERT(reporter, buffer[1] == b);
89     REPORTER_ASSERT(reporter, buffer[2] == c);
90     REPORTER_ASSERT(reporter, buffer[3] == d);
91     REPORTER_ASSERT(reporter, buffer[4] == e);
92     REPORTER_ASSERT(reporter, buffer[5] == f);
93     REPORTER_ASSERT(reporter, buffer[6] == g);
94     REPORTER_ASSERT(reporter, buffer[7] == h);
95     REPORTER_ASSERT(reporter, buffer[8] == i);
96 }
97 
test_set9(skiatest::Reporter * reporter)98 static void test_set9(skiatest::Reporter* reporter) {
99 
100     SkMatrix m;
101     m.reset();
102     assert9(reporter, m, 1, 0, 0, 0, 1, 0, 0, 0, 1);
103 
104     m.setScale(2, 3);
105     assert9(reporter, m, 2, 0, 0, 0, 3, 0, 0, 0, 1);
106 
107     m.postTranslate(4, 5);
108     assert9(reporter, m, 2, 0, 4, 0, 3, 5, 0, 0, 1);
109 
110     SkScalar buffer[9];
111     sk_bzero(buffer, sizeof(buffer));
112     buffer[SkMatrix::kMScaleX] = 1;
113     buffer[SkMatrix::kMScaleY] = 1;
114     buffer[SkMatrix::kMPersp2] = 1;
115     REPORTER_ASSERT(reporter, !m.isIdentity());
116     m.set9(buffer);
117     REPORTER_ASSERT(reporter, m.isIdentity());
118 }
119 
test_matrix_recttorect(skiatest::Reporter * reporter)120 static void test_matrix_recttorect(skiatest::Reporter* reporter) {
121     SkRect src, dst;
122     SkMatrix matrix;
123 
124     src.set(0, 0, 10, 10);
125     dst = src;
126     matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
127     REPORTER_ASSERT(reporter, SkMatrix::kIdentity_Mask == matrix.getType());
128     REPORTER_ASSERT(reporter, matrix.rectStaysRect());
129 
130     dst.offset(1, 1);
131     matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
132     REPORTER_ASSERT(reporter, SkMatrix::kTranslate_Mask == matrix.getType());
133     REPORTER_ASSERT(reporter, matrix.rectStaysRect());
134 
135     dst.fRight += 1;
136     matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
137     REPORTER_ASSERT(reporter,
138                     (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask) == matrix.getType());
139     REPORTER_ASSERT(reporter, matrix.rectStaysRect());
140 
141     dst = src;
142     dst.fRight = src.fRight * 2;
143     matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
144     REPORTER_ASSERT(reporter, SkMatrix::kScale_Mask == matrix.getType());
145     REPORTER_ASSERT(reporter, matrix.rectStaysRect());
146 }
147 
test_flatten(skiatest::Reporter * reporter,const SkMatrix & m)148 static void test_flatten(skiatest::Reporter* reporter, const SkMatrix& m) {
149     // add 100 in case we have a bug, I don't want to kill my stack in the test
150     static const size_t kBufferSize = SkMatrixPriv::kMaxFlattenSize + 100;
151     char buffer[kBufferSize];
152     size_t size1 = SkMatrixPriv::WriteToMemory(m, nullptr);
153     size_t size2 = SkMatrixPriv::WriteToMemory(m, buffer);
154     REPORTER_ASSERT(reporter, size1 == size2);
155     REPORTER_ASSERT(reporter, size1 <= SkMatrixPriv::kMaxFlattenSize);
156 
157     SkMatrix m2;
158     size_t size3 = SkMatrixPriv::ReadFromMemory(&m2, buffer, kBufferSize);
159     REPORTER_ASSERT(reporter, size1 == size3);
160     REPORTER_ASSERT(reporter, are_equal(reporter, m, m2));
161 
162     char buffer2[kBufferSize];
163     size3 = SkMatrixPriv::WriteToMemory(m2, buffer2);
164     REPORTER_ASSERT(reporter, size1 == size3);
165     REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
166 }
167 
test_matrix_min_max_scale(skiatest::Reporter * reporter)168 static void test_matrix_min_max_scale(skiatest::Reporter* reporter) {
169     SkScalar scales[2];
170     bool success;
171 
172     SkMatrix identity;
173     identity.reset();
174     REPORTER_ASSERT(reporter, 1 == identity.getMinScale());
175     REPORTER_ASSERT(reporter, 1 == identity.getMaxScale());
176     success = identity.getMinMaxScales(scales);
177     REPORTER_ASSERT(reporter, success && 1 == scales[0] && 1 == scales[1]);
178 
179     SkMatrix scale;
180     scale.setScale(2, 4);
181     REPORTER_ASSERT(reporter, 2 == scale.getMinScale());
182     REPORTER_ASSERT(reporter, 4 == scale.getMaxScale());
183     success = scale.getMinMaxScales(scales);
184     REPORTER_ASSERT(reporter, success && 2 == scales[0] && 4 == scales[1]);
185 
186     SkMatrix rot90Scale;
187     rot90Scale.setRotate(90).postScale(SK_Scalar1 / 4, SK_Scalar1 / 2);
188     REPORTER_ASSERT(reporter, SK_Scalar1 / 4 == rot90Scale.getMinScale());
189     REPORTER_ASSERT(reporter, SK_Scalar1 / 2 == rot90Scale.getMaxScale());
190     success = rot90Scale.getMinMaxScales(scales);
191     REPORTER_ASSERT(reporter, success && SK_Scalar1 / 4  == scales[0] && SK_Scalar1 / 2 == scales[1]);
192 
193     SkMatrix rotate;
194     rotate.setRotate(128);
195     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(1, rotate.getMinScale(), SK_ScalarNearlyZero));
196     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(1, rotate.getMaxScale(), SK_ScalarNearlyZero));
197     success = rotate.getMinMaxScales(scales);
198     REPORTER_ASSERT(reporter, success);
199     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(1, scales[0], SK_ScalarNearlyZero));
200     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(1, scales[1], SK_ScalarNearlyZero));
201 
202     SkMatrix translate;
203     translate.setTranslate(10, -5);
204     REPORTER_ASSERT(reporter, 1 == translate.getMinScale());
205     REPORTER_ASSERT(reporter, 1 == translate.getMaxScale());
206     success = translate.getMinMaxScales(scales);
207     REPORTER_ASSERT(reporter, success && 1 == scales[0] && 1 == scales[1]);
208 
209     SkMatrix perspX;
210     perspX.reset().setPerspX(SK_Scalar1 / 1000);
211     REPORTER_ASSERT(reporter, -1 == perspX.getMinScale());
212     REPORTER_ASSERT(reporter, -1 == perspX.getMaxScale());
213     success = perspX.getMinMaxScales(scales);
214     REPORTER_ASSERT(reporter, !success);
215 
216     // skbug.com/4718
217     SkMatrix big;
218     big.setAll(2.39394089e+36f, 8.85347779e+36f, 9.26526204e+36f,
219                3.9159619e+36f, 1.44823453e+37f, 1.51559342e+37f,
220                0.f, 0.f, 1.f);
221     success = big.getMinMaxScales(scales);
222     REPORTER_ASSERT(reporter, !success);
223 
224     // skbug.com/4718
225     SkMatrix givingNegativeNearlyZeros;
226     givingNegativeNearlyZeros.setAll(0.00436534f, 0.114138f, 0.37141f,
227                                      0.00358857f, 0.0936228f, -0.0174198f,
228                                      0.f, 0.f, 1.f);
229     success = givingNegativeNearlyZeros.getMinMaxScales(scales);
230     REPORTER_ASSERT(reporter, success && 0 == scales[0]);
231 
232     SkMatrix perspY;
233     perspY.reset().setPerspY(-SK_Scalar1 / 500);
234     REPORTER_ASSERT(reporter, -1 == perspY.getMinScale());
235     REPORTER_ASSERT(reporter, -1 == perspY.getMaxScale());
236     scales[0] = -5;
237     scales[1] = -5;
238     success = perspY.getMinMaxScales(scales);
239     REPORTER_ASSERT(reporter, !success && -5 == scales[0] && -5  == scales[1]);
240 
241     SkMatrix baseMats[] = {scale, rot90Scale, rotate,
242                            translate, perspX, perspY};
243     SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)];
244     for (size_t i = 0; i < SK_ARRAY_COUNT(baseMats); ++i) {
245         mats[i] = baseMats[i];
246         bool invertible = mats[i].invert(&mats[i + SK_ARRAY_COUNT(baseMats)]);
247         REPORTER_ASSERT(reporter, invertible);
248     }
249     SkRandom rand;
250     for (int m = 0; m < 1000; ++m) {
251         SkMatrix mat;
252         mat.reset();
253         for (int i = 0; i < 4; ++i) {
254             int x = rand.nextU() % SK_ARRAY_COUNT(mats);
255             mat.postConcat(mats[x]);
256         }
257 
258         SkScalar minScale = mat.getMinScale();
259         SkScalar maxScale = mat.getMaxScale();
260         REPORTER_ASSERT(reporter, (minScale < 0) == (maxScale < 0));
261         REPORTER_ASSERT(reporter, (maxScale < 0) == mat.hasPerspective());
262 
263         SkScalar scales[2];
264         bool success = mat.getMinMaxScales(scales);
265         REPORTER_ASSERT(reporter, success == !mat.hasPerspective());
266         REPORTER_ASSERT(reporter, !success || (scales[0] == minScale && scales[1] == maxScale));
267 
268         if (mat.hasPerspective()) {
269             m -= 1; // try another non-persp matrix
270             continue;
271         }
272 
273         // test a bunch of vectors. All should be scaled by between minScale and maxScale
274         // (modulo some error) and we should find a vector that is scaled by almost each.
275         static const SkScalar gVectorScaleTol = (105 * SK_Scalar1) / 100;
276         static const SkScalar gCloseScaleTol = (97 * SK_Scalar1) / 100;
277         SkScalar max = 0, min = SK_ScalarMax;
278         SkVector vectors[1000];
279         for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) {
280             vectors[i].fX = rand.nextSScalar1();
281             vectors[i].fY = rand.nextSScalar1();
282             if (!vectors[i].normalize()) {
283                 i -= 1;
284                 continue;
285             }
286         }
287         mat.mapVectors(vectors, SK_ARRAY_COUNT(vectors));
288         for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) {
289             SkScalar d = vectors[i].length();
290             REPORTER_ASSERT(reporter, d / maxScale < gVectorScaleTol);
291             REPORTER_ASSERT(reporter, minScale / d < gVectorScaleTol);
292             if (max < d) {
293                 max = d;
294             }
295             if (min > d) {
296                 min = d;
297             }
298         }
299         REPORTER_ASSERT(reporter, max / maxScale >= gCloseScaleTol);
300         REPORTER_ASSERT(reporter, minScale / min >= gCloseScaleTol);
301     }
302 }
303 
test_matrix_preserve_shape(skiatest::Reporter * reporter)304 static void test_matrix_preserve_shape(skiatest::Reporter* reporter) {
305     SkMatrix mat;
306 
307     // identity
308     mat.setIdentity();
309     REPORTER_ASSERT(reporter, mat.isSimilarity());
310     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
311 
312     // translation only
313     mat.setTranslate(100, 100);
314     REPORTER_ASSERT(reporter, mat.isSimilarity());
315     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
316 
317     // scale with same size
318     mat.setScale(15, 15);
319     REPORTER_ASSERT(reporter, mat.isSimilarity());
320     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
321 
322     // scale with one negative
323     mat.setScale(-15, 15);
324     REPORTER_ASSERT(reporter, mat.isSimilarity());
325     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
326 
327     // scale with different size
328     mat.setScale(15, 20);
329     REPORTER_ASSERT(reporter, !mat.isSimilarity());
330     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
331 
332     // scale with same size at a pivot point
333     mat.setScale(15, 15, 2, 2);
334     REPORTER_ASSERT(reporter, mat.isSimilarity());
335     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
336 
337     // scale with different size at a pivot point
338     mat.setScale(15, 20, 2, 2);
339     REPORTER_ASSERT(reporter, !mat.isSimilarity());
340     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
341 
342     // skew with same size
343     mat.setSkew(15, 15);
344     REPORTER_ASSERT(reporter, !mat.isSimilarity());
345     REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
346 
347     // skew with different size
348     mat.setSkew(15, 20);
349     REPORTER_ASSERT(reporter, !mat.isSimilarity());
350     REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
351 
352     // skew with same size at a pivot point
353     mat.setSkew(15, 15, 2, 2);
354     REPORTER_ASSERT(reporter, !mat.isSimilarity());
355     REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
356 
357     // skew with different size at a pivot point
358     mat.setSkew(15, 20, 2, 2);
359     REPORTER_ASSERT(reporter, !mat.isSimilarity());
360     REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
361 
362     // perspective x
363     mat.reset().setPerspX(SK_Scalar1 / 2);
364     REPORTER_ASSERT(reporter, !mat.isSimilarity());
365     REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
366 
367     // perspective y
368     mat.reset().setPerspY(SK_Scalar1 / 2);
369     REPORTER_ASSERT(reporter, !mat.isSimilarity());
370     REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
371 
372     // rotate
373     for (int angle = 0; angle < 360; ++angle) {
374         mat.setRotate(SkIntToScalar(angle));
375         REPORTER_ASSERT(reporter, mat.isSimilarity());
376         REPORTER_ASSERT(reporter, mat.preservesRightAngles());
377     }
378 
379     // see if there are any accumulated precision issues
380     mat.reset();
381     for (int i = 1; i < 360; i++) {
382         mat.postRotate(1);
383     }
384     REPORTER_ASSERT(reporter, mat.isSimilarity());
385     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
386 
387     // rotate + translate
388     mat.setRotate(30).postTranslate(10, 20);
389     REPORTER_ASSERT(reporter, mat.isSimilarity());
390     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
391 
392     // rotate + uniform scale
393     mat.setRotate(30).postScale(2, 2);
394     REPORTER_ASSERT(reporter, mat.isSimilarity());
395     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
396 
397     // rotate + non-uniform scale
398     mat.setRotate(30).postScale(3, 2);
399     REPORTER_ASSERT(reporter, !mat.isSimilarity());
400     REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
401 
402     // non-uniform scale + rotate
403     mat.setScale(3, 2).postRotate(30);
404     REPORTER_ASSERT(reporter, !mat.isSimilarity());
405     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
406 
407     // all zero
408     mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0);
409     REPORTER_ASSERT(reporter, !mat.isSimilarity());
410     REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
411 
412     // all zero except perspective
413     mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, 1);
414     REPORTER_ASSERT(reporter, !mat.isSimilarity());
415     REPORTER_ASSERT(reporter, !mat.preservesRightAngles());
416 
417     // scales zero, only skews (rotation)
418     mat.setAll(0, 1, 0,
419                -1, 0, 0,
420                0, 0, 1);
421     REPORTER_ASSERT(reporter, mat.isSimilarity());
422     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
423 
424     // scales zero, only skews (reflection)
425     mat.setAll(0, 1, 0,
426                1, 0, 0,
427                0, 0, 1);
428     REPORTER_ASSERT(reporter, mat.isSimilarity());
429     REPORTER_ASSERT(reporter, mat.preservesRightAngles());
430 }
431 
432 // For test_matrix_decomposition, below.
scalar_nearly_equal_relative(SkScalar a,SkScalar b,SkScalar tolerance=SK_ScalarNearlyZero)433 static bool scalar_nearly_equal_relative(SkScalar a, SkScalar b,
434                                          SkScalar tolerance = SK_ScalarNearlyZero) {
435     // from Bruce Dawson
436     // absolute check
437     SkScalar diff = SkScalarAbs(a - b);
438     if (diff < tolerance) {
439         return true;
440     }
441 
442     // relative check
443     a = SkScalarAbs(a);
444     b = SkScalarAbs(b);
445     SkScalar largest = (b > a) ? b : a;
446 
447     if (diff <= largest*tolerance) {
448         return true;
449     }
450 
451     return false;
452 }
453 
check_matrix_recomposition(const SkMatrix & mat,const SkPoint & rotation1,const SkPoint & scale,const SkPoint & rotation2)454 static bool check_matrix_recomposition(const SkMatrix& mat,
455                                        const SkPoint& rotation1,
456                                        const SkPoint& scale,
457                                        const SkPoint& rotation2) {
458     SkScalar c1 = rotation1.fX;
459     SkScalar s1 = rotation1.fY;
460     SkScalar scaleX = scale.fX;
461     SkScalar scaleY = scale.fY;
462     SkScalar c2 = rotation2.fX;
463     SkScalar s2 = rotation2.fY;
464 
465     // We do a relative check here because large scale factors cause problems with an absolute check
466     bool result = scalar_nearly_equal_relative(mat[SkMatrix::kMScaleX],
467                                                scaleX*c1*c2 - scaleY*s1*s2) &&
468                   scalar_nearly_equal_relative(mat[SkMatrix::kMSkewX],
469                                                -scaleX*s1*c2 - scaleY*c1*s2) &&
470                   scalar_nearly_equal_relative(mat[SkMatrix::kMSkewY],
471                                                scaleX*c1*s2 + scaleY*s1*c2) &&
472                   scalar_nearly_equal_relative(mat[SkMatrix::kMScaleY],
473                                                -scaleX*s1*s2 + scaleY*c1*c2);
474     return result;
475 }
476 
test_matrix_decomposition(skiatest::Reporter * reporter)477 static void test_matrix_decomposition(skiatest::Reporter* reporter) {
478     SkMatrix mat;
479     SkPoint rotation1, scale, rotation2;
480 
481     const float kRotation0 = 15.5f;
482     const float kRotation1 = -50.f;
483     const float kScale0 = 5000.f;
484     const float kScale1 = 0.001f;
485 
486     // identity
487     mat.reset();
488     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
489     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
490     // make sure it doesn't crash if we pass in NULLs
491     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, nullptr, nullptr, nullptr));
492 
493     // rotation only
494     mat.setRotate(kRotation0);
495     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
496     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
497 
498     // uniform scale only
499     mat.setScale(kScale0, kScale0);
500     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
501     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
502 
503     // anisotropic scale only
504     mat.setScale(kScale1, kScale0);
505     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
506     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
507 
508     // rotation then uniform scale
509     mat.setRotate(kRotation1).postScale(kScale0, kScale0);
510     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
511     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
512 
513     // uniform scale then rotation
514     mat.setScale(kScale0, kScale0).postRotate(kRotation1);
515     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
516     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
517 
518     // rotation then uniform scale+reflection
519     mat.setRotate(kRotation0).postScale(kScale1, -kScale1);
520     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
521     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
522 
523     // uniform scale+reflection, then rotate
524     mat.setScale(kScale0, -kScale0).postRotate(kRotation1);
525     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
526     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
527 
528     // rotation then anisotropic scale
529     mat.setRotate(kRotation1).postScale(kScale1, kScale0);
530     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
531     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
532 
533     // rotation then anisotropic scale
534     mat.setRotate(90).postScale(kScale1, kScale0);
535     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
536     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
537 
538     // anisotropic scale then rotation
539     mat.setScale(kScale1, kScale0).postRotate(kRotation0);
540     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
541     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
542 
543     // anisotropic scale then rotation
544     mat.setScale(kScale1, kScale0).postRotate(90);
545     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
546     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
547 
548     // rotation, uniform scale, then different rotation
549     mat.setRotate(kRotation1).postScale(kScale0, kScale0).postRotate(kRotation0);
550     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
551     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
552 
553     // rotation, anisotropic scale, then different rotation
554     mat.setRotate(kRotation0).postScale(kScale1, kScale0).postRotate(kRotation1);
555     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
556     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
557 
558     // rotation, anisotropic scale + reflection, then different rotation
559     mat.setRotate(kRotation0).postScale(-kScale1, kScale0).postRotate(kRotation1);
560     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
561     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
562 
563     // try some random matrices
564     SkRandom rand;
565     for (int m = 0; m < 1000; ++m) {
566         SkScalar rot0 = rand.nextRangeF(-180, 180);
567         SkScalar sx = rand.nextRangeF(-3000.f, 3000.f);
568         SkScalar sy = rand.nextRangeF(-3000.f, 3000.f);
569         SkScalar rot1 = rand.nextRangeF(-180, 180);
570         mat.setRotate(rot0).postScale(sx, sy).postRotate(rot1);
571 
572         if (SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2)) {
573             REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
574         } else {
575             // if the matrix is degenerate, the basis vectors should be near-parallel or near-zero
576             SkScalar perpdot = mat[SkMatrix::kMScaleX]*mat[SkMatrix::kMScaleY] -
577                                mat[SkMatrix::kMSkewX]*mat[SkMatrix::kMSkewY];
578             REPORTER_ASSERT(reporter, SkScalarNearlyZero(perpdot));
579         }
580     }
581 
582     // translation shouldn't affect this
583     mat.postTranslate(-1000.f, 1000.f);
584     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
585     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
586 
587     // perspective shouldn't affect this
588     mat[SkMatrix::kMPersp0] = 12.f;
589     mat[SkMatrix::kMPersp1] = 4.f;
590     mat[SkMatrix::kMPersp2] = 1872.f;
591     REPORTER_ASSERT(reporter, SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
592     REPORTER_ASSERT(reporter, check_matrix_recomposition(mat, rotation1, scale, rotation2));
593 
594     // degenerate matrices
595     // mostly zero entries
596     mat.reset();
597     mat[SkMatrix::kMScaleX] = 0.f;
598     REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
599     mat.reset();
600     mat[SkMatrix::kMScaleY] = 0.f;
601     REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
602     mat.reset();
603     // linearly dependent entries
604     mat[SkMatrix::kMScaleX] = 1.f;
605     mat[SkMatrix::kMSkewX] = 2.f;
606     mat[SkMatrix::kMSkewY] = 4.f;
607     mat[SkMatrix::kMScaleY] = 8.f;
608     REPORTER_ASSERT(reporter, !SkDecomposeUpper2x2(mat, &rotation1, &scale, &rotation2));
609 }
610 
611 // For test_matrix_homogeneous, below.
point3_array_nearly_equal_relative(const SkPoint3 a[],const SkPoint3 b[],int count)612 static bool point3_array_nearly_equal_relative(const SkPoint3 a[], const SkPoint3 b[], int count) {
613     for (int i = 0; i < count; ++i) {
614         if (!scalar_nearly_equal_relative(a[i].fX, b[i].fX)) {
615             return false;
616         }
617         if (!scalar_nearly_equal_relative(a[i].fY, b[i].fY)) {
618             return false;
619         }
620         if (!scalar_nearly_equal_relative(a[i].fZ, b[i].fZ)) {
621             return false;
622         }
623     }
624     return true;
625 }
626 
627 // For test_matrix_homogeneous, below.
628 // Maps a single triple in src using m and compares results to those in dst
naive_homogeneous_mapping(const SkMatrix & m,const SkPoint3 & src,const SkPoint3 & dst)629 static bool naive_homogeneous_mapping(const SkMatrix& m, const SkPoint3& src,
630                                       const SkPoint3& dst) {
631     SkPoint3 res;
632     SkScalar ms[9] = {m[0], m[1], m[2],
633                       m[3], m[4], m[5],
634                       m[6], m[7], m[8]};
635     res.fX = src.fX * ms[0] + src.fY * ms[1] + src.fZ * ms[2];
636     res.fY = src.fX * ms[3] + src.fY * ms[4] + src.fZ * ms[5];
637     res.fZ = src.fX * ms[6] + src.fY * ms[7] + src.fZ * ms[8];
638     return point3_array_nearly_equal_relative(&res, &dst, 1);
639 }
640 
test_matrix_homogeneous(skiatest::Reporter * reporter)641 static void test_matrix_homogeneous(skiatest::Reporter* reporter) {
642     SkMatrix mat;
643 
644     const float kRotation0 = 15.5f;
645     const float kRotation1 = -50.f;
646     const float kScale0 = 5000.f;
647 
648 #if defined(SK_BUILD_FOR_GOOGLE3)
649     // Stack frame size is limited in SK_BUILD_FOR_GOOGLE3.
650     const int kTripleCount = 100;
651     const int kMatrixCount = 100;
652 #else
653     const int kTripleCount = 1000;
654     const int kMatrixCount = 1000;
655 #endif
656     SkRandom rand;
657 
658     SkPoint3 randTriples[kTripleCount];
659     for (int i = 0; i < kTripleCount; ++i) {
660         randTriples[i].fX = rand.nextRangeF(-3000.f, 3000.f);
661         randTriples[i].fY = rand.nextRangeF(-3000.f, 3000.f);
662         randTriples[i].fZ = rand.nextRangeF(-3000.f, 3000.f);
663     }
664 
665     SkMatrix mats[kMatrixCount];
666     for (int i = 0; i < kMatrixCount; ++i) {
667         for (int j = 0; j < 9; ++j) {
668             mats[i].set(j, rand.nextRangeF(-3000.f, 3000.f));
669         }
670     }
671 
672     // identity
673     {
674     mat.reset();
675     SkPoint3 dst[kTripleCount];
676     mat.mapHomogeneousPoints(dst, randTriples, kTripleCount);
677     REPORTER_ASSERT(reporter, point3_array_nearly_equal_relative(randTriples, dst, kTripleCount));
678     }
679 
680     const SkPoint3 zeros = {0.f, 0.f, 0.f};
681     // zero matrix
682     {
683     mat.setAll(0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f);
684     SkPoint3 dst[kTripleCount];
685     mat.mapHomogeneousPoints(dst, randTriples, kTripleCount);
686     for (int i = 0; i < kTripleCount; ++i) {
687         REPORTER_ASSERT(reporter, point3_array_nearly_equal_relative(&dst[i], &zeros, 1));
688     }
689     }
690 
691     // zero point
692     {
693     for (int i = 0; i < kMatrixCount; ++i) {
694         SkPoint3 dst;
695         mats[i].mapHomogeneousPoints(&dst, &zeros, 1);
696         REPORTER_ASSERT(reporter, point3_array_nearly_equal_relative(&dst, &zeros, 1));
697     }
698     }
699 
700     // doesn't crash with null dst, src, count == 0
701     {
702     mats[0].mapHomogeneousPoints(nullptr, nullptr, 0);
703     }
704 
705     // uniform scale of point
706     {
707     mat.setScale(kScale0, kScale0);
708     SkPoint3 dst;
709     SkPoint3 src = {randTriples[0].fX, randTriples[0].fY, 1.f};
710     SkPoint pnt;
711     pnt.set(src.fX, src.fY);
712     mat.mapHomogeneousPoints(&dst, &src, 1);
713     mat.mapPoints(&pnt, &pnt, 1);
714     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fX, pnt.fX));
715     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fY, pnt.fY));
716     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fZ, 1));
717     }
718 
719     // rotation of point
720     {
721     mat.setRotate(kRotation0);
722     SkPoint3 dst;
723     SkPoint3 src = {randTriples[0].fX, randTriples[0].fY, 1.f};
724     SkPoint pnt;
725     pnt.set(src.fX, src.fY);
726     mat.mapHomogeneousPoints(&dst, &src, 1);
727     mat.mapPoints(&pnt, &pnt, 1);
728     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fX, pnt.fX));
729     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fY, pnt.fY));
730     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fZ, 1));
731     }
732 
733     // rotation, scale, rotation of point
734     {
735     mat.setRotate(kRotation1);
736     mat.postScale(kScale0, kScale0);
737     mat.postRotate(kRotation0);
738     SkPoint3 dst;
739     SkPoint3 src = {randTriples[0].fX, randTriples[0].fY, 1.f};
740     SkPoint pnt;
741     pnt.set(src.fX, src.fY);
742     mat.mapHomogeneousPoints(&dst, &src, 1);
743     mat.mapPoints(&pnt, &pnt, 1);
744     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fX, pnt.fX));
745     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fY, pnt.fY));
746     REPORTER_ASSERT(reporter, SkScalarNearlyEqual(dst.fZ, 1));
747     }
748 
749     // compare with naive approach
750     {
751     for (int i = 0; i < kMatrixCount; ++i) {
752         for (int j = 0; j < kTripleCount; ++j) {
753             SkPoint3 dst;
754             mats[i].mapHomogeneousPoints(&dst, &randTriples[j], 1);
755             REPORTER_ASSERT(reporter, naive_homogeneous_mapping(mats[i], randTriples[j], dst));
756         }
757     }
758     }
759 
760 }
761 
check_decompScale(const SkMatrix & original)762 static bool check_decompScale(const SkMatrix& original) {
763     SkSize scale;
764     SkMatrix remaining;
765 
766     if (!original.decomposeScale(&scale, &remaining)) {
767         return false;
768     }
769     if (scale.width() <= 0 || scale.height() <= 0) {
770         return false;
771     }
772 
773     // First ensure that the decomposition reconstitutes back to the original
774     {
775         SkMatrix reconstituted = remaining;
776 
777         reconstituted.preScale(scale.width(), scale.height());
778         if (!nearly_equal(original, reconstituted)) {
779             return false;
780         }
781     }
782 
783     // Then push some points through both paths and make sure they are the same.
784     static const int kNumPoints = 5;
785     const SkPoint testPts[kNumPoints] = {
786         {  0.0f,  0.0f },
787         {  1.0f,  1.0f },
788         {  1.0f,  0.5f },
789         { -1.0f, -0.5f },
790         { -1.0f,  2.0f }
791     };
792 
793     SkPoint v1[kNumPoints];
794     original.mapPoints(v1, testPts, kNumPoints);
795 
796     SkPoint v2[kNumPoints];
797     SkMatrix scaleMat = SkMatrix::MakeScale(scale.width(), scale.height());
798 
799     // Note, we intend the decomposition to be applied in the order scale and then remainder but,
800     // due to skbug.com/7211, the order is reversed!
801     scaleMat.mapPoints(v2, testPts, kNumPoints);
802     remaining.mapPoints(v2, kNumPoints);
803 
804     for (int i = 0; i < kNumPoints; ++i) {
805         if (!SkPointPriv::EqualsWithinTolerance(v1[i], v2[i], 0.00001f)) {
806             return false;
807         }
808     }
809 
810     return true;
811 }
812 
test_decompScale(skiatest::Reporter * reporter)813 static void test_decompScale(skiatest::Reporter* reporter) {
814     SkMatrix m;
815 
816     m.reset();
817     REPORTER_ASSERT(reporter, check_decompScale(m));
818     m.setScale(2, 3);
819     REPORTER_ASSERT(reporter, check_decompScale(m));
820     m.setRotate(35, 0, 0);
821     REPORTER_ASSERT(reporter, check_decompScale(m));
822 
823     m.setScale(1, 0);
824     REPORTER_ASSERT(reporter, !check_decompScale(m));
825 
826     m.setRotate(35, 0, 0).preScale(2, 3);
827     REPORTER_ASSERT(reporter, check_decompScale(m));
828 
829     m.setRotate(35, 0, 0).postScale(2, 3);
830     REPORTER_ASSERT(reporter, check_decompScale(m));
831 }
832 
DEF_TEST(Matrix,reporter)833 DEF_TEST(Matrix, reporter) {
834     SkMatrix    mat, inverse, iden1, iden2;
835 
836     mat.reset();
837     mat.setTranslate(1, 1);
838     REPORTER_ASSERT(reporter, mat.invert(&inverse));
839     iden1.setConcat(mat, inverse);
840     REPORTER_ASSERT(reporter, is_identity(iden1));
841 
842     mat.setScale(2, 4);
843     REPORTER_ASSERT(reporter, mat.invert(&inverse));
844     iden1.setConcat(mat, inverse);
845     REPORTER_ASSERT(reporter, is_identity(iden1));
846     test_flatten(reporter, mat);
847 
848     mat.setScale(SK_Scalar1/2, 2);
849     REPORTER_ASSERT(reporter, mat.invert(&inverse));
850     iden1.setConcat(mat, inverse);
851     REPORTER_ASSERT(reporter, is_identity(iden1));
852     test_flatten(reporter, mat);
853 
854     mat.setScale(3, 5, 20, 0).postRotate(25);
855     REPORTER_ASSERT(reporter, mat.invert(nullptr));
856     REPORTER_ASSERT(reporter, mat.invert(&inverse));
857     iden1.setConcat(mat, inverse);
858     REPORTER_ASSERT(reporter, is_identity(iden1));
859     iden2.setConcat(inverse, mat);
860     REPORTER_ASSERT(reporter, is_identity(iden2));
861     test_flatten(reporter, mat);
862     test_flatten(reporter, iden2);
863 
864     mat.setScale(0, 1);
865     REPORTER_ASSERT(reporter, !mat.invert(nullptr));
866     REPORTER_ASSERT(reporter, !mat.invert(&inverse));
867     mat.setScale(1, 0);
868     REPORTER_ASSERT(reporter, !mat.invert(nullptr));
869     REPORTER_ASSERT(reporter, !mat.invert(&inverse));
870 
871     // Inverting this matrix results in a non-finite matrix
872     mat.setAll(0.0f, 1.0f, 2.0f,
873                0.0f, 1.0f, -3.40277175e+38f,
874                1.00003040f, 1.0f, 0.0f);
875     REPORTER_ASSERT(reporter, !mat.invert(nullptr));
876     REPORTER_ASSERT(reporter, !mat.invert(&inverse));
877 
878     // rectStaysRect test
879     {
880         static const struct {
881             SkScalar    m00, m01, m10, m11;
882             bool        mStaysRect;
883         }
884         gRectStaysRectSamples[] = {
885             { 0, 0, 0, 0, false },
886             { 0, 0, 0, 1, false },
887             { 0, 0, 1, 0, false },
888             { 0, 0, 1, 1, false },
889             { 0, 1, 0, 0, false },
890             { 0, 1, 0, 1, false },
891             { 0, 1, 1, 0, true },
892             { 0, 1, 1, 1, false },
893             { 1, 0, 0, 0, false },
894             { 1, 0, 0, 1, true },
895             { 1, 0, 1, 0, false },
896             { 1, 0, 1, 1, false },
897             { 1, 1, 0, 0, false },
898             { 1, 1, 0, 1, false },
899             { 1, 1, 1, 0, false },
900             { 1, 1, 1, 1, false }
901         };
902 
903         for (size_t i = 0; i < SK_ARRAY_COUNT(gRectStaysRectSamples); i++) {
904             SkMatrix    m;
905 
906             m.reset();
907             m.set(SkMatrix::kMScaleX, gRectStaysRectSamples[i].m00);
908             m.set(SkMatrix::kMSkewX,  gRectStaysRectSamples[i].m01);
909             m.set(SkMatrix::kMSkewY,  gRectStaysRectSamples[i].m10);
910             m.set(SkMatrix::kMScaleY, gRectStaysRectSamples[i].m11);
911             REPORTER_ASSERT(reporter,
912                     m.rectStaysRect() == gRectStaysRectSamples[i].mStaysRect);
913         }
914     }
915 
916     mat.reset();
917     mat.set(SkMatrix::kMScaleX, 1)
918        .set(SkMatrix::kMSkewX,  2)
919        .set(SkMatrix::kMTransX, 3)
920        .set(SkMatrix::kMSkewY,  4)
921        .set(SkMatrix::kMScaleY, 5)
922        .set(SkMatrix::kMTransY, 6);
923     SkScalar affine[6];
924     REPORTER_ASSERT(reporter, mat.asAffine(affine));
925 
926     #define affineEqual(e) affine[SkMatrix::kA##e] == mat.get(SkMatrix::kM##e)
927     REPORTER_ASSERT(reporter, affineEqual(ScaleX));
928     REPORTER_ASSERT(reporter, affineEqual(SkewY));
929     REPORTER_ASSERT(reporter, affineEqual(SkewX));
930     REPORTER_ASSERT(reporter, affineEqual(ScaleY));
931     REPORTER_ASSERT(reporter, affineEqual(TransX));
932     REPORTER_ASSERT(reporter, affineEqual(TransY));
933     #undef affineEqual
934 
935     mat.set(SkMatrix::kMPersp1, SK_Scalar1 / 2);
936     REPORTER_ASSERT(reporter, !mat.asAffine(affine));
937 
938     SkMatrix mat2;
939     mat2.reset();
940     mat.reset();
941     SkScalar zero = 0;
942     mat.set(SkMatrix::kMSkewX, -zero);
943     REPORTER_ASSERT(reporter, are_equal(reporter, mat, mat2));
944 
945     mat2.reset();
946     mat.reset();
947     mat.set(SkMatrix::kMSkewX, SK_ScalarNaN);
948     mat2.set(SkMatrix::kMSkewX, SK_ScalarNaN);
949     REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2));
950 
951     test_matrix_min_max_scale(reporter);
952     test_matrix_preserve_shape(reporter);
953     test_matrix_recttorect(reporter);
954     test_matrix_decomposition(reporter);
955     test_matrix_homogeneous(reporter);
956     test_set9(reporter);
957 
958     test_decompScale(reporter);
959 
960     mat.setScaleTranslate(2, 3, 1, 4);
961     mat2.setScale(2, 3).postTranslate(1, 4);
962     REPORTER_ASSERT(reporter, mat == mat2);
963 }
964 
DEF_TEST(Matrix_Concat,r)965 DEF_TEST(Matrix_Concat, r) {
966     SkMatrix a;
967     a.setTranslate(10, 20);
968 
969     SkMatrix b;
970     b.setScale(3, 5);
971 
972     SkMatrix expected;
973     expected.setConcat(a,b);
974 
975     REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b));
976 }
977 
978 // Test that all variants of maprect are correct.
DEF_TEST(Matrix_maprects,r)979 DEF_TEST(Matrix_maprects, r) {
980     const SkScalar scale = 1000;
981 
982     SkMatrix mat;
983     mat.setScale(2, 3).postTranslate(1, 4);
984 
985     SkRandom rand;
986     for (int i = 0; i < 10000; ++i) {
987         SkRect src = SkRect::MakeLTRB(rand.nextSScalar1() * scale,
988                                       rand.nextSScalar1() * scale,
989                                       rand.nextSScalar1() * scale,
990                                       rand.nextSScalar1() * scale);
991         SkRect dst[4];
992 
993         mat.mapPoints((SkPoint*)&dst[0].fLeft, (SkPoint*)&src.fLeft, 2);
994         dst[0].sort();
995         mat.mapRect(&dst[1], src);
996         mat.mapRectScaleTranslate(&dst[2], src);
997         dst[3] = mat.mapRect(src);
998 
999         REPORTER_ASSERT(r, dst[0] == dst[1]);
1000         REPORTER_ASSERT(r, dst[0] == dst[2]);
1001         REPORTER_ASSERT(r, dst[0] == dst[3]);
1002     }
1003 
1004     // We should report nonfinite-ness after a mapping
1005     {
1006         // We have special-cases in mapRect for different matrix types
1007         SkMatrix m0 = SkMatrix::MakeScale(1e20f, 1e20f);
1008         SkMatrix m1; m1.setRotate(30); m1.postScale(1e20f, 1e20f);
1009 
1010         for (const auto& m : { m0, m1 }) {
1011             SkRect rect = { 0, 0, 1e20f, 1e20f };
1012             REPORTER_ASSERT(r, rect.isFinite());
1013             rect = m.mapRect(rect);
1014             REPORTER_ASSERT(r, !rect.isFinite());
1015         }
1016     }
1017 }
1018 
DEF_TEST(Matrix_Ctor,r)1019 DEF_TEST(Matrix_Ctor, r) {
1020     REPORTER_ASSERT(r, SkMatrix{} == SkMatrix::I());
1021 }
1022