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

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: Pass constants as float not double in unit test. 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
« no previous file with comments | « 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 2050 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 // Note carefully - expecting true here. 2231 // Note carefully - expecting true here.
2205 A.MakeIdentity(); 2232 A.MakeIdentity();
2206 A.matrix().set(2, 3, 2.f); 2233 A.matrix().set(2, 3, 2.f);
2207 EXPECT_TRUE(A.IsIdentityOrTranslation()); 2234 EXPECT_TRUE(A.IsIdentityOrTranslation());
2208 2235
2209 A.MakeIdentity(); 2236 A.MakeIdentity();
2210 A.matrix().set(3, 3, 2.f); 2237 A.matrix().set(3, 3, 2.f);
2211 EXPECT_FALSE(A.IsIdentityOrTranslation()); 2238 EXPECT_FALSE(A.IsIdentityOrTranslation());
2212 } 2239 }
2213 2240
2241 TEST(XFormTest, verifyIsApproximatelyIdentityOrTranslation) {
2242 Transform A;
2243 SkMatrix44& matrix = A.matrix();
2244
2245 // Exact pure translation.
2246 A.MakeIdentity();
2247
2248 // Set translate values to values other than 0 or 1.
2249 matrix.set(0, 3, 3.4f);
2250 matrix.set(1, 3, 4.4f);
2251 matrix.set(2, 3, 5.6f);
2252
2253 EXPECT_TRUE(A.IsApproximatelyIdentityOrTranslation(0));
2254 EXPECT_TRUE(A.IsApproximatelyIdentityOrTranslation(kApproxZero));
2255
2256 // Approximately pure translation.
2257 InitializeApproxIdentityMatrix(&A);
2258
2259 // Some values must be exact.
2260 matrix.set(3, 0, 0);
2261 matrix.set(3, 1, 0);
2262 matrix.set(3, 2, 0);
2263 matrix.set(3, 3, 1);
2264
2265 // Set translate values to values other than 0 or 1.
2266 matrix.set(0, 3, 3.4f);
2267 matrix.set(1, 3, 4.4f);
2268 matrix.set(2, 3, 5.6f);
2269
2270 EXPECT_FALSE(A.IsApproximatelyIdentityOrTranslation(0));
2271 EXPECT_TRUE(A.IsApproximatelyIdentityOrTranslation(kApproxZero));
2272
2273 // Not approximately pure translation.
2274 InitializeApproxIdentityMatrix(&A);
2275
2276 // Some values must be exact.
2277 matrix.set(3, 0, 0);
2278 matrix.set(3, 1, 0);
2279 matrix.set(3, 2, 0);
2280 matrix.set(3, 3, 1);
2281
2282 // Set some values (not translate values) to values other than 0 or 1.
2283 matrix.set(0, 1, 3.4f);
2284 matrix.set(3, 2, 4.4f);
2285 matrix.set(2, 0, 5.6f);
2286
2287 EXPECT_FALSE(A.IsApproximatelyIdentityOrTranslation(0));
2288 EXPECT_FALSE(A.IsApproximatelyIdentityOrTranslation(kApproxZero));
2289 }
2290
2214 TEST(XFormTest, verifyIsScaleOrTranslation) { 2291 TEST(XFormTest, verifyIsScaleOrTranslation) {
2215 Transform A; 2292 Transform A;
2216 2293
2217 InitializeTestMatrix(&A); 2294 InitializeTestMatrix(&A);
2218 EXPECT_FALSE(A.IsScaleOrTranslation()); 2295 EXPECT_FALSE(A.IsScaleOrTranslation());
2219 2296
2220 A.MakeIdentity(); 2297 A.MakeIdentity();
2221 EXPECT_TRUE(A.IsScaleOrTranslation()); 2298 EXPECT_TRUE(A.IsScaleOrTranslation());
2222 2299
2223 // Modifying any non-scale or non-translation components should cause 2300 // Modifying any non-scale or non-translation components should cause
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
2572 EXPECT_EQ(expected.ToString(), box.ToString()); 2649 EXPECT_EQ(expected.ToString(), box.ToString());
2573 2650
2574 Transform singular; 2651 Transform singular;
2575 singular.Scale3d(0.f, 0.f, 0.f); 2652 singular.Scale3d(0.f, 0.f, 0.f);
2576 EXPECT_FALSE(singular.TransformBoxReverse(&box)); 2653 EXPECT_FALSE(singular.TransformBoxReverse(&box));
2577 } 2654 }
2578 2655
2579 } // namespace 2656 } // namespace
2580 2657
2581 } // namespace gfx 2658 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/transform.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698