blob: 30542dccaee86d2f9511f85eb130cac7ad0b668d [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.comed673312009-02-27 16:24:51 +00008#include "Test.h"
tomhudson@google.com889bd8b2011-09-27 17:38:17 +00009#include "SkMath.h"
reed@android.comed673312009-02-27 16:24:51 +000010#include "SkMatrix.h"
bsalomon@google.com38396322011-09-09 19:32:04 +000011#include "SkRandom.h"
reed@android.comed673312009-02-27 16:24:51 +000012
13static bool nearly_equal_scalar(SkScalar a, SkScalar b) {
epoger@google.com2047f002011-05-17 17:36:59 +000014 // Note that we get more compounded error for multiple operations when
15 // SK_SCALAR_IS_FIXED.
reed@android.comed673312009-02-27 16:24:51 +000016#ifdef SK_SCALAR_IS_FLOAT
epoger@google.com2047f002011-05-17 17:36:59 +000017 const SkScalar tolerance = SK_Scalar1 / 200000;
reed@android.comed673312009-02-27 16:24:51 +000018#else
epoger@google.com2047f002011-05-17 17:36:59 +000019 const SkScalar tolerance = SK_Scalar1 / 1024;
reed@android.comed673312009-02-27 16:24:51 +000020#endif
21
22 return SkScalarAbs(a - b) <= tolerance;
23}
24
25static bool nearly_equal(const SkMatrix& a, const SkMatrix& b) {
26 for (int i = 0; i < 9; i++) {
27 if (!nearly_equal_scalar(a[i], b[i])) {
reed@android.comd4134452011-02-09 02:24:26 +000028 printf("not equal %g %g\n", (float)a[i], (float)b[i]);
reed@android.comed673312009-02-27 16:24:51 +000029 return false;
30 }
31 }
32 return true;
33}
34
bsalomon@google.com8fe84b52012-03-26 15:24:27 +000035static bool are_equal(skiatest::Reporter* reporter,
36 const SkMatrix& a,
37 const SkMatrix& b) {
38 bool equal = a == b;
39 bool cheapEqual = a.cheapEqualTo(b);
40 if (equal != cheapEqual) {
41#if SK_SCALAR_IS_FLOAT
bsalomon@google.com39d4f3a2012-03-26 17:25:45 +000042 if (equal) {
bsalomon@google.com8fe84b52012-03-26 15:24:27 +000043 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 = *reinterpret_cast<int*>(&aVal);
48 int bValI = *reinterpret_cast<int*>(&bVal);
49 if (0 == aVal && 0 == bVal && aValI != bValI) {
50 foundZeroSignDiff = true;
51 } else {
52 REPORTER_ASSERT(reporter, aVal == bVal && aValI == aValI);
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 = *reinterpret_cast<int*>(&aVal);
62 int bValI = *reinterpret_cast<int*>(&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#else
72 REPORTER_ASSERT(reporter, false);
73#endif
74 }
75 return equal;
76}
77
reed@android.comed673312009-02-27 16:24:51 +000078static bool is_identity(const SkMatrix& m) {
79 SkMatrix identity;
reed@android.com80e39a72009-04-02 16:59:40 +000080 identity.reset();
reed@android.comed673312009-02-27 16:24:51 +000081 return nearly_equal(m, identity);
82}
83
reed@android.com4b7577b2009-06-29 16:14:41 +000084static void test_flatten(skiatest::Reporter* reporter, const SkMatrix& m) {
85 // add 100 in case we have a bug, I don't want to kill my stack in the test
86 char buffer[SkMatrix::kMaxFlattenSize + 100];
djsollen@google.com94e75ee2012-06-08 18:30:46 +000087 uint32_t size1 = m.writeToMemory(NULL);
88 uint32_t size2 = m.writeToMemory(buffer);
reed@android.com4b7577b2009-06-29 16:14:41 +000089 REPORTER_ASSERT(reporter, size1 == size2);
90 REPORTER_ASSERT(reporter, size1 <= SkMatrix::kMaxFlattenSize);
rmistry@google.comd6176b02012-08-23 18:14:13 +000091
reed@android.com4b7577b2009-06-29 16:14:41 +000092 SkMatrix m2;
djsollen@google.com94e75ee2012-06-08 18:30:46 +000093 uint32_t size3 = m2.readFromMemory(buffer);
94 REPORTER_ASSERT(reporter, size1 == size3);
bsalomon@google.com8fe84b52012-03-26 15:24:27 +000095 REPORTER_ASSERT(reporter, are_equal(reporter, m, m2));
rmistry@google.comd6176b02012-08-23 18:14:13 +000096
reed@android.com4b7577b2009-06-29 16:14:41 +000097 char buffer2[SkMatrix::kMaxFlattenSize + 100];
djsollen@google.com94e75ee2012-06-08 18:30:46 +000098 size3 = m2.writeToMemory(buffer2);
99 REPORTER_ASSERT(reporter, size1 == size3);
reed@android.com4b7577b2009-06-29 16:14:41 +0000100 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
101}
102
caryclark@google.com42639cd2012-06-06 12:03:39 +0000103static void test_matrix_max_stretch(skiatest::Reporter* reporter) {
bsalomon@google.com38396322011-09-09 19:32:04 +0000104 SkMatrix identity;
105 identity.reset();
106 REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMaxStretch());
107
108 SkMatrix scale;
109 scale.setScale(SK_Scalar1 * 2, SK_Scalar1 * 4);
110 REPORTER_ASSERT(reporter, SK_Scalar1 * 4 == scale.getMaxStretch());
111
112 SkMatrix rot90Scale;
113 rot90Scale.setRotate(90 * SK_Scalar1);
114 rot90Scale.postScale(SK_Scalar1 / 4, SK_Scalar1 / 2);
115 REPORTER_ASSERT(reporter, SK_Scalar1 / 2 == rot90Scale.getMaxStretch());
116
117 SkMatrix rotate;
118 rotate.setRotate(128 * SK_Scalar1);
119 REPORTER_ASSERT(reporter, SkScalarAbs(SK_Scalar1 - rotate.getMaxStretch()) <= SK_ScalarNearlyZero);
120
121 SkMatrix translate;
122 translate.setTranslate(10 * SK_Scalar1, -5 * SK_Scalar1);
123 REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMaxStretch());
124
125 SkMatrix perspX;
126 perspX.reset();
bungeman@google.com07faed12011-10-07 21:55:56 +0000127 perspX.setPerspX(SkScalarToPersp(SK_Scalar1 / 1000));
bsalomon@google.com38396322011-09-09 19:32:04 +0000128 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMaxStretch());
129
130 SkMatrix perspY;
131 perspY.reset();
bungeman@google.com07faed12011-10-07 21:55:56 +0000132 perspY.setPerspX(SkScalarToPersp(-SK_Scalar1 / 500));
bsalomon@google.com38396322011-09-09 19:32:04 +0000133 REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxStretch());
134
135 SkMatrix baseMats[] = {scale, rot90Scale, rotate,
136 translate, perspX, perspY};
137 SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)];
tomhudson@google.com83a44462011-10-27 15:27:51 +0000138 for (size_t i = 0; i < SK_ARRAY_COUNT(baseMats); ++i) {
bsalomon@google.com38396322011-09-09 19:32:04 +0000139 mats[i] = baseMats[i];
140 bool invertable = mats[i].invert(&mats[i + SK_ARRAY_COUNT(baseMats)]);
141 REPORTER_ASSERT(reporter, invertable);
142 }
143 SkRandom rand;
144 for (int m = 0; m < 1000; ++m) {
145 SkMatrix mat;
146 mat.reset();
147 for (int i = 0; i < 4; ++i) {
148 int x = rand.nextU() % SK_ARRAY_COUNT(mats);
149 mat.postConcat(mats[x]);
150 }
151 SkScalar stretch = mat.getMaxStretch();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000152
bsalomon@google.com38396322011-09-09 19:32:04 +0000153 if ((stretch < 0) != mat.hasPerspective()) {
154 stretch = mat.getMaxStretch();
155 }
156
157 REPORTER_ASSERT(reporter, (stretch < 0) == mat.hasPerspective());
158
159 if (mat.hasPerspective()) {
160 m -= 1; // try another non-persp matrix
161 continue;
162 }
163
164 // test a bunch of vectors. None should be scaled by more than stretch
165 // (modulo some error) and we should find a vector that is scaled by
166 // almost stretch.
167 static const SkScalar gStretchTol = (105 * SK_Scalar1) / 100;
168 static const SkScalar gMaxStretchTol = (97 * SK_Scalar1) / 100;
169 SkScalar max = 0;
170 SkVector vectors[1000];
tomhudson@google.com83a44462011-10-27 15:27:51 +0000171 for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) {
bsalomon@google.com38396322011-09-09 19:32:04 +0000172 vectors[i].fX = rand.nextSScalar1();
173 vectors[i].fY = rand.nextSScalar1();
174 if (!vectors[i].normalize()) {
175 i -= 1;
176 continue;
177 }
178 }
179 mat.mapVectors(vectors, SK_ARRAY_COUNT(vectors));
tomhudson@google.com83a44462011-10-27 15:27:51 +0000180 for (size_t i = 0; i < SK_ARRAY_COUNT(vectors); ++i) {
bsalomon@google.com38396322011-09-09 19:32:04 +0000181 SkScalar d = vectors[i].length();
182 REPORTER_ASSERT(reporter, SkScalarDiv(d, stretch) < gStretchTol);
183 if (max < d) {
184 max = d;
185 }
186 }
187 REPORTER_ASSERT(reporter, SkScalarDiv(max, stretch) >= gMaxStretchTol);
188 }
189}
190
bsalomon@google.com69afee12012-04-25 15:07:40 +0000191// This function is extracted from src/gpu/SkGpuDevice.cpp,
192// in order to make sure this function works correctly.
193static bool isSimilarityTransformation(const SkMatrix& matrix,
194 SkScalar tol = SK_ScalarNearlyZero) {
195 if (matrix.isIdentity() || matrix.getType() == SkMatrix::kTranslate_Mask) {
196 return true;
197 }
198 if (matrix.hasPerspective()) {
199 return false;
200 }
201
202 SkScalar mx = matrix.get(SkMatrix::kMScaleX);
203 SkScalar sx = matrix.get(SkMatrix::kMSkewX);
204 SkScalar my = matrix.get(SkMatrix::kMScaleY);
205 SkScalar sy = matrix.get(SkMatrix::kMSkewY);
206
207 if (mx == 0 && sx == 0 && my == 0 && sy == 0) {
208 return false;
209 }
210
211 // it has scales or skews, but it could also be rotation, check it out.
212 SkVector vec[2];
213 vec[0].set(mx, sx);
214 vec[1].set(sy, my);
215
216 return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) &&
217 SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(),
218 SkScalarSquare(tol));
219}
220
caryclark@google.com42639cd2012-06-06 12:03:39 +0000221static void test_matrix_is_similarity_transform(skiatest::Reporter* reporter) {
bsalomon@google.com69afee12012-04-25 15:07:40 +0000222 SkMatrix mat;
223
224 // identity
225 mat.setIdentity();
226 REPORTER_ASSERT(reporter, isSimilarityTransformation(mat));
227
228 // translation only
229 mat.reset();
230 mat.setTranslate(SkIntToScalar(100), SkIntToScalar(100));
231 REPORTER_ASSERT(reporter, isSimilarityTransformation(mat));
232
233 // scale with same size
234 mat.reset();
235 mat.setScale(SkIntToScalar(15), SkIntToScalar(15));
236 REPORTER_ASSERT(reporter, isSimilarityTransformation(mat));
237
238 // scale with one negative
239 mat.reset();
240 mat.setScale(SkIntToScalar(-15), SkIntToScalar(15));
241 REPORTER_ASSERT(reporter, isSimilarityTransformation(mat));
242
243 // scale with different size
244 mat.reset();
245 mat.setScale(SkIntToScalar(15), SkIntToScalar(20));
246 REPORTER_ASSERT(reporter, !isSimilarityTransformation(mat));
247
248 // scale with same size at a pivot point
249 mat.reset();
250 mat.setScale(SkIntToScalar(15), SkIntToScalar(15),
251 SkIntToScalar(2), SkIntToScalar(2));
252 REPORTER_ASSERT(reporter, isSimilarityTransformation(mat));
253
254 // scale with different size at a pivot point
255 mat.reset();
256 mat.setScale(SkIntToScalar(15), SkIntToScalar(20),
257 SkIntToScalar(2), SkIntToScalar(2));
258 REPORTER_ASSERT(reporter, !isSimilarityTransformation(mat));
259
260 // skew with same size
261 mat.reset();
262 mat.setSkew(SkIntToScalar(15), SkIntToScalar(15));
263 REPORTER_ASSERT(reporter, !isSimilarityTransformation(mat));
264
265 // skew with different size
266 mat.reset();
267 mat.setSkew(SkIntToScalar(15), SkIntToScalar(20));
268 REPORTER_ASSERT(reporter, !isSimilarityTransformation(mat));
269
270 // skew with same size at a pivot point
271 mat.reset();
272 mat.setSkew(SkIntToScalar(15), SkIntToScalar(15),
273 SkIntToScalar(2), SkIntToScalar(2));
274 REPORTER_ASSERT(reporter, !isSimilarityTransformation(mat));
275
276 // skew with different size at a pivot point
277 mat.reset();
278 mat.setSkew(SkIntToScalar(15), SkIntToScalar(20),
279 SkIntToScalar(2), SkIntToScalar(2));
280 REPORTER_ASSERT(reporter, !isSimilarityTransformation(mat));
281
282 // perspective x
283 mat.reset();
284 mat.setPerspX(SkScalarToPersp(SK_Scalar1 / 2));
285 REPORTER_ASSERT(reporter, !isSimilarityTransformation(mat));
286
287 // perspective y
288 mat.reset();
289 mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2));
290 REPORTER_ASSERT(reporter, !isSimilarityTransformation(mat));
291
292#if SK_SCALAR_IS_FLOAT
293 /* We bypass the following tests for SK_SCALAR_IS_FIXED build.
294 * The long discussion can be found in this issue:
295 * http://codereview.appspot.com/5999050/
296 * In short, we haven't found a perfect way to fix the precision
297 * issue, i.e. the way we use tolerance in isSimilarityTransformation
298 * is incorrect. The situation becomes worse in fixed build, so
299 * we disabled rotation related tests for fixed build.
300 */
301
302 // rotate
303 for (int angle = 0; angle < 360; ++angle) {
304 mat.reset();
305 mat.setRotate(SkIntToScalar(angle));
306 REPORTER_ASSERT(reporter, isSimilarityTransformation(mat));
307 }
308
309 // see if there are any accumulated precision issues
310 mat.reset();
311 for (int i = 1; i < 360; i++) {
312 mat.postRotate(SkIntToScalar(1));
313 }
314 REPORTER_ASSERT(reporter, isSimilarityTransformation(mat));
315
316 // rotate + translate
317 mat.reset();
318 mat.setRotate(SkIntToScalar(30));
319 mat.postTranslate(SkIntToScalar(10), SkIntToScalar(20));
320 REPORTER_ASSERT(reporter, isSimilarityTransformation(mat));
321
322 // rotate + uniform scale
323 mat.reset();
324 mat.setRotate(SkIntToScalar(30));
325 mat.postScale(SkIntToScalar(2), SkIntToScalar(2));
326 REPORTER_ASSERT(reporter, isSimilarityTransformation(mat));
327
328 // rotate + non-uniform scale
329 mat.reset();
330 mat.setRotate(SkIntToScalar(30));
331 mat.postScale(SkIntToScalar(3), SkIntToScalar(2));
332 REPORTER_ASSERT(reporter, !isSimilarityTransformation(mat));
333#endif
334
335 // all zero
336 mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0);
337 REPORTER_ASSERT(reporter, !isSimilarityTransformation(mat));
338
339 // all zero except perspective
340 mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, SK_Scalar1);
341 REPORTER_ASSERT(reporter, !isSimilarityTransformation(mat));
342
343 // scales zero, only skews
344 mat.setAll(0, SK_Scalar1, 0,
345 SK_Scalar1, 0, 0,
346 0, 0, SkMatrix::I()[8]);
347 REPORTER_ASSERT(reporter, isSimilarityTransformation(mat));
348}
349
caryclark@google.com42639cd2012-06-06 12:03:39 +0000350static void TestMatrix(skiatest::Reporter* reporter) {
reed@android.comed673312009-02-27 16:24:51 +0000351 SkMatrix mat, inverse, iden1, iden2;
352
353 mat.reset();
354 mat.setTranslate(SK_Scalar1, SK_Scalar1);
reed@google.com5bfa55b2012-04-19 18:59:25 +0000355 REPORTER_ASSERT(reporter, mat.invert(&inverse));
reed@android.comed673312009-02-27 16:24:51 +0000356 iden1.setConcat(mat, inverse);
357 REPORTER_ASSERT(reporter, is_identity(iden1));
358
359 mat.setScale(SkIntToScalar(2), SkIntToScalar(2));
reed@google.com5bfa55b2012-04-19 18:59:25 +0000360 REPORTER_ASSERT(reporter, mat.invert(&inverse));
reed@android.comed673312009-02-27 16:24:51 +0000361 iden1.setConcat(mat, inverse);
362 REPORTER_ASSERT(reporter, is_identity(iden1));
reed@android.com4b7577b2009-06-29 16:14:41 +0000363 test_flatten(reporter, mat);
reed@android.comed673312009-02-27 16:24:51 +0000364
365 mat.setScale(SK_Scalar1/2, SK_Scalar1/2);
reed@google.com5bfa55b2012-04-19 18:59:25 +0000366 REPORTER_ASSERT(reporter, mat.invert(&inverse));
reed@android.comed673312009-02-27 16:24:51 +0000367 iden1.setConcat(mat, inverse);
368 REPORTER_ASSERT(reporter, is_identity(iden1));
reed@android.com4b7577b2009-06-29 16:14:41 +0000369 test_flatten(reporter, mat);
reed@android.comed673312009-02-27 16:24:51 +0000370
371 mat.setScale(SkIntToScalar(3), SkIntToScalar(5), SkIntToScalar(20), 0);
372 mat.postRotate(SkIntToScalar(25));
373 REPORTER_ASSERT(reporter, mat.invert(NULL));
reed@google.com5bfa55b2012-04-19 18:59:25 +0000374 REPORTER_ASSERT(reporter, mat.invert(&inverse));
reed@android.comed673312009-02-27 16:24:51 +0000375 iden1.setConcat(mat, inverse);
376 REPORTER_ASSERT(reporter, is_identity(iden1));
377 iden2.setConcat(inverse, mat);
378 REPORTER_ASSERT(reporter, is_identity(iden2));
reed@android.com4b7577b2009-06-29 16:14:41 +0000379 test_flatten(reporter, mat);
380 test_flatten(reporter, iden2);
reed@android.com80e39a72009-04-02 16:59:40 +0000381
reed@android.comed673312009-02-27 16:24:51 +0000382 // rectStaysRect test
383 {
384 static const struct {
385 SkScalar m00, m01, m10, m11;
386 bool mStaysRect;
387 }
388 gRectStaysRectSamples[] = {
389 { 0, 0, 0, 0, false },
390 { 0, 0, 0, SK_Scalar1, false },
391 { 0, 0, SK_Scalar1, 0, false },
392 { 0, 0, SK_Scalar1, SK_Scalar1, false },
393 { 0, SK_Scalar1, 0, 0, false },
394 { 0, SK_Scalar1, 0, SK_Scalar1, false },
395 { 0, SK_Scalar1, SK_Scalar1, 0, true },
396 { 0, SK_Scalar1, SK_Scalar1, SK_Scalar1, false },
397 { SK_Scalar1, 0, 0, 0, false },
398 { SK_Scalar1, 0, 0, SK_Scalar1, true },
399 { SK_Scalar1, 0, SK_Scalar1, 0, false },
400 { SK_Scalar1, 0, SK_Scalar1, SK_Scalar1, false },
401 { SK_Scalar1, SK_Scalar1, 0, 0, false },
402 { SK_Scalar1, SK_Scalar1, 0, SK_Scalar1, false },
403 { SK_Scalar1, SK_Scalar1, SK_Scalar1, 0, false },
404 { SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, false }
405 };
reed@android.com80e39a72009-04-02 16:59:40 +0000406
reed@android.comed673312009-02-27 16:24:51 +0000407 for (size_t i = 0; i < SK_ARRAY_COUNT(gRectStaysRectSamples); i++) {
408 SkMatrix m;
reed@android.com80e39a72009-04-02 16:59:40 +0000409
reed@android.comed673312009-02-27 16:24:51 +0000410 m.reset();
411 m.set(SkMatrix::kMScaleX, gRectStaysRectSamples[i].m00);
412 m.set(SkMatrix::kMSkewX, gRectStaysRectSamples[i].m01);
413 m.set(SkMatrix::kMSkewY, gRectStaysRectSamples[i].m10);
414 m.set(SkMatrix::kMScaleY, gRectStaysRectSamples[i].m11);
415 REPORTER_ASSERT(reporter,
416 m.rectStaysRect() == gRectStaysRectSamples[i].mStaysRect);
417 }
418 }
bungeman@google.com1ddd7c32011-07-13 19:41:55 +0000419
bungeman@google.comba7983e2011-07-13 20:18:16 +0000420 mat.reset();
bungeman@google.com1ddd7c32011-07-13 19:41:55 +0000421 mat.set(SkMatrix::kMScaleX, SkIntToScalar(1));
422 mat.set(SkMatrix::kMSkewX, SkIntToScalar(2));
423 mat.set(SkMatrix::kMTransX, SkIntToScalar(3));
424 mat.set(SkMatrix::kMSkewY, SkIntToScalar(4));
425 mat.set(SkMatrix::kMScaleY, SkIntToScalar(5));
426 mat.set(SkMatrix::kMTransY, SkIntToScalar(6));
bungeman@google.com1ddd7c32011-07-13 19:41:55 +0000427 SkScalar affine[6];
428 REPORTER_ASSERT(reporter, mat.asAffine(affine));
429
430 #define affineEqual(e) affine[SkMatrix::kA##e] == mat.get(SkMatrix::kM##e)
431 REPORTER_ASSERT(reporter, affineEqual(ScaleX));
432 REPORTER_ASSERT(reporter, affineEqual(SkewY));
433 REPORTER_ASSERT(reporter, affineEqual(SkewX));
434 REPORTER_ASSERT(reporter, affineEqual(ScaleY));
435 REPORTER_ASSERT(reporter, affineEqual(TransX));
436 REPORTER_ASSERT(reporter, affineEqual(TransY));
437 #undef affineEqual
438
bungeman@google.com07faed12011-10-07 21:55:56 +0000439 mat.set(SkMatrix::kMPersp1, SkScalarToPersp(SK_Scalar1 / 2));
bungeman@google.com1ddd7c32011-07-13 19:41:55 +0000440 REPORTER_ASSERT(reporter, !mat.asAffine(affine));
bsalomon@google.com38396322011-09-09 19:32:04 +0000441
bsalomon@google.com8fe84b52012-03-26 15:24:27 +0000442 SkMatrix mat2;
443 mat2.reset();
444 mat.reset();
445 SkScalar zero = 0;
446 mat.set(SkMatrix::kMSkewX, -zero);
447 REPORTER_ASSERT(reporter, are_equal(reporter, mat, mat2));
448
449 mat2.reset();
450 mat.reset();
451 mat.set(SkMatrix::kMSkewX, SK_ScalarNaN);
452 mat2.set(SkMatrix::kMSkewX, SK_ScalarNaN);
bsalomon@google.com9ed2ecd2012-03-26 15:57:37 +0000453 // fixed pt doesn't have the property that NaN does not equal itself.
454#ifdef SK_SCALAR_IS_FIXED
455 REPORTER_ASSERT(reporter, are_equal(reporter, mat, mat2));
456#else
bsalomon@google.com8fe84b52012-03-26 15:24:27 +0000457 REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2));
bsalomon@google.com9ed2ecd2012-03-26 15:57:37 +0000458#endif
bsalomon@google.com8fe84b52012-03-26 15:24:27 +0000459
bsalomon@google.com38396322011-09-09 19:32:04 +0000460 test_matrix_max_stretch(reporter);
bsalomon@google.com69afee12012-04-25 15:07:40 +0000461 test_matrix_is_similarity_transform(reporter);
reed@android.comed673312009-02-27 16:24:51 +0000462}
463
reed@android.comd8730ea2009-02-27 22:06:06 +0000464#include "TestClassDef.h"
465DEFINE_TESTCLASS("Matrix", MatrixTestClass, TestMatrix)