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

Side by Side Diff: ui/gfx/transform_unittest.cc

Issue 27223008: Provide approximate type functions for SkMatrix44. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move code to gfx::Transform class. Created 7 years, 2 months 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
« ui/gfx/transform.cc ('K') | « ui/gfx/transform.cc ('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 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "ui/gfx/transform.h" 8 #include "ui/gfx/transform.h"
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 matrix.set(2, 3, 44.f); 134 matrix.set(2, 3, 44.f);
135 matrix.set(3, 3, 45.f); 135 matrix.set(3, 3, 45.f);
136 136
137 // Sanity check 137 // Sanity check
138 EXPECT_ROW1_EQ(30.0f, 34.0f, 38.0f, 42.0f, (*transform)); 138 EXPECT_ROW1_EQ(30.0f, 34.0f, 38.0f, 42.0f, (*transform));
139 EXPECT_ROW2_EQ(31.0f, 35.0f, 39.0f, 43.0f, (*transform)); 139 EXPECT_ROW2_EQ(31.0f, 35.0f, 39.0f, 43.0f, (*transform));
140 EXPECT_ROW3_EQ(32.0f, 36.0f, 40.0f, 44.0f, (*transform)); 140 EXPECT_ROW3_EQ(32.0f, 36.0f, 40.0f, 44.0f, (*transform));
141 EXPECT_ROW4_EQ(33.0f, 37.0f, 41.0f, 45.0f, (*transform)); 141 EXPECT_ROW4_EQ(33.0f, 37.0f, 41.0f, 45.0f, (*transform));
142 } 142 }
143 143
144 const SkMScalar kApproxZero =
145 SkFloatToMScalar(std::numeric_limits<float>::epsilon());
146 const SkMScalar kApproxOne = 1 - kApproxZero;
147
148 void InitializeApproxIdentityMatrix(Transform* transform) {
149 SkMatrix44& matrix = transform->matrix();
150 matrix.set(0, 0, kApproxOne);
151 matrix.set(0, 1, kApproxZero);
152 matrix.set(0, 2, kApproxZero);
153 matrix.set(0, 3, kApproxZero);
154
155 matrix.set(1, 0, kApproxZero);
156 matrix.set(1, 1, kApproxOne);
157 matrix.set(1, 2, kApproxZero);
158 matrix.set(1, 3, kApproxZero);
159
160 matrix.set(2, 0, kApproxZero);
161 matrix.set(2, 1, kApproxZero);
162 matrix.set(2, 2, kApproxOne);
163 matrix.set(2, 3, kApproxZero);
164
165 matrix.set(3, 0, kApproxZero);
166 matrix.set(3, 1, kApproxZero);
167 matrix.set(3, 2, kApproxZero);
168 matrix.set(3, 3, kApproxOne);
169 }
170
144 #ifdef SK_MSCALAR_IS_DOUBLE 171 #ifdef SK_MSCALAR_IS_DOUBLE
145 #define ERROR_THRESHOLD 1e-14 172 #define ERROR_THRESHOLD 1e-14
146 #else 173 #else
147 #define ERROR_THRESHOLD 1e-7 174 #define ERROR_THRESHOLD 1e-7
148 #endif 175 #endif
149 #define LOOSE_ERROR_THRESHOLD 1e-7 176 #define LOOSE_ERROR_THRESHOLD 1e-7
150 177
151 TEST(XFormTest, Equality) { 178 TEST(XFormTest, Equality) {
152 Transform lhs, rhs, interpolated; 179 Transform lhs, rhs, interpolated;
153 rhs.matrix().set3x3(1, 2, 3, 180 rhs.matrix().set3x3(1, 2, 3,
(...skipping 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 // Note carefully - expecting true here. 2214 // Note carefully - expecting true here.
2188 A.MakeIdentity(); 2215 A.MakeIdentity();
2189 A.matrix().set(2, 3, 2.f); 2216 A.matrix().set(2, 3, 2.f);
2190 EXPECT_TRUE(A.IsIdentityOrTranslation()); 2217 EXPECT_TRUE(A.IsIdentityOrTranslation());
2191 2218
2192 A.MakeIdentity(); 2219 A.MakeIdentity();
2193 A.matrix().set(3, 3, 2.f); 2220 A.matrix().set(3, 3, 2.f);
2194 EXPECT_FALSE(A.IsIdentityOrTranslation()); 2221 EXPECT_FALSE(A.IsIdentityOrTranslation());
2195 } 2222 }
2196 2223
2224 TEST(XFormTest, verifyIsApproximatelyIdentityOrTranslation) {
2225 Transform A;
2226 SkMatrix44& matrix = A.matrix();
2227
2228 // Exact pure translation.
2229 A.MakeIdentity();
2230
2231 // Set translate values to values other than 0 or 1.
2232 matrix.set(0, 3, 3.4);
2233 matrix.set(1, 3, 4.4);
2234 matrix.set(2, 3, 5.6);
2235
2236 EXPECT_TRUE(A.IsApproximatelyIdentityOrTranslation(0));
2237 EXPECT_TRUE(A.IsApproximatelyIdentityOrTranslation(kApproxZero));
2238
danakj 2013/10/17 17:43:18 1 blank line only
2239
2240 // Approximately pure translation.
2241 InitializeApproxIdentityMatrix(&A);
2242
2243 // Some values must be exact.
2244 matrix.set(3, 0, 0);
2245 matrix.set(3, 1, 0);
2246 matrix.set(3, 2, 0);
2247 matrix.set(3, 3, 1);
2248
2249 // Set translate values to values other than 0 or 1.
2250 matrix.set(0, 3, 3.4);
2251 matrix.set(1, 3, 4.4);
2252 matrix.set(2, 3, 5.6);
2253
2254 EXPECT_FALSE(A.IsApproximatelyIdentityOrTranslation(0));
2255 EXPECT_TRUE(A.IsApproximatelyIdentityOrTranslation(kApproxZero));
2256
danakj 2013/10/17 17:43:18 1 blank line only
2257
2258 // Not approximately pure translation.
2259 InitializeApproxIdentityMatrix(&A);
2260
2261 // Some values must be exact.
2262 matrix.set(3, 0, 0);
2263 matrix.set(3, 1, 0);
2264 matrix.set(3, 2, 0);
2265 matrix.set(3, 3, 1);
2266
2267 // Set some values (not translate values) to values other than 0 or 1.
2268 matrix.set(0, 1, 3.4);
2269 matrix.set(3, 2, 4.4);
2270 matrix.set(2, 0, 5.6);
2271
2272 EXPECT_FALSE(A.IsApproximatelyIdentityOrTranslation(0));
2273 EXPECT_FALSE(A.IsApproximatelyIdentityOrTranslation(kApproxZero));
2274 }
2275
2197 TEST(XFormTest, verifyIsScaleOrTranslation) { 2276 TEST(XFormTest, verifyIsScaleOrTranslation) {
2198 Transform A; 2277 Transform A;
2199 2278
2200 InitializeTestMatrix(&A); 2279 InitializeTestMatrix(&A);
2201 EXPECT_FALSE(A.IsScaleOrTranslation()); 2280 EXPECT_FALSE(A.IsScaleOrTranslation());
2202 2281
2203 A.MakeIdentity(); 2282 A.MakeIdentity();
2204 EXPECT_TRUE(A.IsScaleOrTranslation()); 2283 EXPECT_TRUE(A.IsScaleOrTranslation());
2205 2284
2206 // Modifying any non-scale or non-translation components should cause 2285 // Modifying any non-scale or non-translation components should cause
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
2555 EXPECT_EQ(expected.ToString(), box.ToString()); 2634 EXPECT_EQ(expected.ToString(), box.ToString());
2556 2635
2557 Transform singular; 2636 Transform singular;
2558 singular.Scale3d(0.f, 0.f, 0.f); 2637 singular.Scale3d(0.f, 0.f, 0.f);
2559 EXPECT_FALSE(singular.TransformBoxReverse(&box)); 2638 EXPECT_FALSE(singular.TransformBoxReverse(&box));
2560 } 2639 }
2561 2640
2562 } // namespace 2641 } // namespace
2563 2642
2564 } // namespace gfx 2643 } // namespace gfx
OLDNEW
« ui/gfx/transform.cc ('K') | « ui/gfx/transform.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698