Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: tests/MatrixTest.cpp

Issue 806543002: add get9 and set9 to matrix, to aid in making keys (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkMatrix.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkMath.h" 8 #include "SkMath.h"
9 #include "SkMatrix.h" 9 #include "SkMatrix.h"
10 #include "SkMatrixUtils.h" 10 #include "SkMatrixUtils.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 return equal; 65 return equal;
66 } 66 }
67 67
68 static bool is_identity(const SkMatrix& m) { 68 static bool is_identity(const SkMatrix& m) {
69 SkMatrix identity; 69 SkMatrix identity;
70 identity.reset(); 70 identity.reset();
71 return nearly_equal(m, identity); 71 return nearly_equal(m, identity);
72 } 72 }
73 73
74 static void assert9(skiatest::Reporter* reporter, const SkMatrix& m,
75 SkScalar a, SkScalar b, SkScalar c,
76 SkScalar d, SkScalar e, SkScalar f,
77 SkScalar g, SkScalar h, SkScalar i) {
78 SkScalar buffer[9];
79 m.get9(buffer);
80 REPORTER_ASSERT(reporter, buffer[0] == a);
81 REPORTER_ASSERT(reporter, buffer[1] == b);
82 REPORTER_ASSERT(reporter, buffer[2] == c);
83 REPORTER_ASSERT(reporter, buffer[3] == d);
84 REPORTER_ASSERT(reporter, buffer[4] == e);
85 REPORTER_ASSERT(reporter, buffer[5] == f);
86 REPORTER_ASSERT(reporter, buffer[6] == g);
87 REPORTER_ASSERT(reporter, buffer[7] == h);
88 REPORTER_ASSERT(reporter, buffer[8] == i);
89 }
90
91 static void test_set9(skiatest::Reporter* reporter) {
92
93 SkMatrix m;
94 m.reset();
95 assert9(reporter, m, 1, 0, 0, 0, 1, 0, 0, 0, 1);
96
97 m.setScale(2, 3);
98 assert9(reporter, m, 2, 0, 0, 0, 3, 0, 0, 0, 1);
99
100 m.postTranslate(4, 5);
101 assert9(reporter, m, 2, 0, 4, 0, 3, 5, 0, 0, 1);
102
103 SkScalar buffer[9];
104 sk_bzero(buffer, sizeof(buffer));
105 buffer[SkMatrix::kMScaleX] = 1;
106 buffer[SkMatrix::kMScaleY] = 1;
107 buffer[SkMatrix::kMPersp2] = 1;
108 REPORTER_ASSERT(reporter, !m.isIdentity());
109 m.set9(buffer);
110 REPORTER_ASSERT(reporter, m.isIdentity());
111 }
112
74 static void test_matrix_recttorect(skiatest::Reporter* reporter) { 113 static void test_matrix_recttorect(skiatest::Reporter* reporter) {
75 SkRect src, dst; 114 SkRect src, dst;
76 SkMatrix matrix; 115 SkMatrix matrix;
77 116
78 src.set(0, 0, SK_Scalar1*10, SK_Scalar1*10); 117 src.set(0, 0, SK_Scalar1*10, SK_Scalar1*10);
79 dst = src; 118 dst = src;
80 matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); 119 matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit);
81 REPORTER_ASSERT(reporter, SkMatrix::kIdentity_Mask == matrix.getType()); 120 REPORTER_ASSERT(reporter, SkMatrix::kIdentity_Mask == matrix.getType());
82 REPORTER_ASSERT(reporter, matrix.rectStaysRect()); 121 REPORTER_ASSERT(reporter, matrix.rectStaysRect());
83 122
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 mat.reset(); 881 mat.reset();
843 mat.set(SkMatrix::kMSkewX, SK_ScalarNaN); 882 mat.set(SkMatrix::kMSkewX, SK_ScalarNaN);
844 mat2.set(SkMatrix::kMSkewX, SK_ScalarNaN); 883 mat2.set(SkMatrix::kMSkewX, SK_ScalarNaN);
845 REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2)); 884 REPORTER_ASSERT(reporter, !are_equal(reporter, mat, mat2));
846 885
847 test_matrix_min_max_scale(reporter); 886 test_matrix_min_max_scale(reporter);
848 test_matrix_preserve_shape(reporter); 887 test_matrix_preserve_shape(reporter);
849 test_matrix_recttorect(reporter); 888 test_matrix_recttorect(reporter);
850 test_matrix_decomposition(reporter); 889 test_matrix_decomposition(reporter);
851 test_matrix_homogeneous(reporter); 890 test_matrix_homogeneous(reporter);
891 test_set9(reporter);
852 } 892 }
853 893
854 DEF_TEST(Matrix_Concat, r) { 894 DEF_TEST(Matrix_Concat, r) {
855 SkMatrix a; 895 SkMatrix a;
856 a.setTranslate(10, 20); 896 a.setTranslate(10, 20);
857 897
858 SkMatrix b; 898 SkMatrix b;
859 b.setScale(3, 5); 899 b.setScale(3, 5);
860 900
861 SkMatrix expected; 901 SkMatrix expected;
862 expected.setConcat(a,b); 902 expected.setConcat(a,b);
863 903
864 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b)); 904 REPORTER_ASSERT(r, expected == SkMatrix::Concat(a, b));
865 } 905 }
OLDNEW
« no previous file with comments | « src/core/SkMatrix.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698