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

Side by Side Diff: ui/gfx/geometry/cubic_bezier_unittest.cc

Issue 1846733003: UI GFX Geometry: Make UnitBezier a wrapper for gfx::CubicBezier (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add one more TODO for Range. Created 4 years, 8 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/geometry/cubic_bezier.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "ui/gfx/geometry/cubic_bezier.h" 5 #include "ui/gfx/geometry/cubic_bezier.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace gfx { 10 namespace gfx {
(...skipping 17 matching lines...) Expand all
28 EXPECT_NEAR(function.Solve(0.5), 0.5, epsilon); 28 EXPECT_NEAR(function.Solve(0.5), 0.5, epsilon);
29 EXPECT_NEAR(function.Solve(0.6), 0.63238, epsilon); 29 EXPECT_NEAR(function.Solve(0.6), 0.63238, epsilon);
30 EXPECT_NEAR(function.Solve(0.65), 0.69676, epsilon); 30 EXPECT_NEAR(function.Solve(0.65), 0.69676, epsilon);
31 EXPECT_NEAR(function.Solve(0.7), 0.75884, epsilon); 31 EXPECT_NEAR(function.Solve(0.7), 0.75884, epsilon);
32 EXPECT_NEAR(function.Solve(0.75), 0.81764, epsilon); 32 EXPECT_NEAR(function.Solve(0.75), 0.81764, epsilon);
33 EXPECT_NEAR(function.Solve(0.8), 0.87196, epsilon); 33 EXPECT_NEAR(function.Solve(0.8), 0.87196, epsilon);
34 EXPECT_NEAR(function.Solve(0.85), 0.92021, epsilon); 34 EXPECT_NEAR(function.Solve(0.85), 0.92021, epsilon);
35 EXPECT_NEAR(function.Solve(0.9), 0.96021, epsilon); 35 EXPECT_NEAR(function.Solve(0.9), 0.96021, epsilon);
36 EXPECT_NEAR(function.Solve(0.95), 0.98863, epsilon); 36 EXPECT_NEAR(function.Solve(0.95), 0.98863, epsilon);
37 EXPECT_NEAR(function.Solve(1), 1, epsilon); 37 EXPECT_NEAR(function.Solve(1), 1, epsilon);
38
39 CubicBezier basic_use(0.5, 1.0, 0.5, 1.0);
40 EXPECT_EQ(0.875, basic_use.Solve(0.5));
41
42 CubicBezier overshoot(0.5, 2.0, 0.5, 2.0);
43 EXPECT_EQ(1.625, overshoot.Solve(0.5));
44
45 CubicBezier undershoot(0.5, -1.0, 0.5, -1.0);
46 EXPECT_EQ(-0.625, undershoot.Solve(0.5));
38 } 47 }
39 48
40 // Tests that solving the bezier works with knots with y not in (0, 1). 49 // Tests that solving the bezier works with knots with y not in (0, 1).
41 TEST(CubicBezierTest, UnclampedYValues) { 50 TEST(CubicBezierTest, UnclampedYValues) {
42 CubicBezier function(0.5, -1.0, 0.5, 2.0); 51 CubicBezier function(0.5, -1.0, 0.5, 2.0);
43 52
44 double epsilon = 0.00015; 53 double epsilon = 0.00015;
45 54
46 EXPECT_NEAR(function.Solve(0.0), 0.0, epsilon); 55 EXPECT_NEAR(function.Solve(0.0), 0.0, epsilon);
47 EXPECT_NEAR(function.Solve(0.05), -0.08954, epsilon); 56 EXPECT_NEAR(function.Solve(0.05), -0.08954, epsilon);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 function->Range(&min, &max); 143 function->Range(&min, &max);
135 EXPECT_EQ(0.f, min); 144 EXPECT_EQ(0.f, min);
136 EXPECT_EQ(1.f, max); 145 EXPECT_EQ(1.f, max);
137 } 146 }
138 147
139 TEST(CubicBezierTest, Slope) { 148 TEST(CubicBezierTest, Slope) {
140 CubicBezier function(0.25, 0.0, 0.75, 1.0); 149 CubicBezier function(0.25, 0.0, 0.75, 1.0);
141 150
142 double epsilon = 0.00015; 151 double epsilon = 0.00015;
143 152
153 EXPECT_NEAR(function.Slope(-0.1), 0, epsilon);
144 EXPECT_NEAR(function.Slope(0), 0, epsilon); 154 EXPECT_NEAR(function.Slope(0), 0, epsilon);
145 EXPECT_NEAR(function.Slope(0.05), 0.42170, epsilon); 155 EXPECT_NEAR(function.Slope(0.05), 0.42170, epsilon);
146 EXPECT_NEAR(function.Slope(0.1), 0.69778, epsilon); 156 EXPECT_NEAR(function.Slope(0.1), 0.69778, epsilon);
147 EXPECT_NEAR(function.Slope(0.15), 0.89121, epsilon); 157 EXPECT_NEAR(function.Slope(0.15), 0.89121, epsilon);
148 EXPECT_NEAR(function.Slope(0.2), 1.03184, epsilon); 158 EXPECT_NEAR(function.Slope(0.2), 1.03184, epsilon);
149 EXPECT_NEAR(function.Slope(0.25), 1.13576, epsilon); 159 EXPECT_NEAR(function.Slope(0.25), 1.13576, epsilon);
150 EXPECT_NEAR(function.Slope(0.3), 1.21239, epsilon); 160 EXPECT_NEAR(function.Slope(0.3), 1.21239, epsilon);
151 EXPECT_NEAR(function.Slope(0.35), 1.26751, epsilon); 161 EXPECT_NEAR(function.Slope(0.35), 1.26751, epsilon);
152 EXPECT_NEAR(function.Slope(0.4), 1.30474, epsilon); 162 EXPECT_NEAR(function.Slope(0.4), 1.30474, epsilon);
153 EXPECT_NEAR(function.Slope(0.45), 1.32628, epsilon); 163 EXPECT_NEAR(function.Slope(0.45), 1.32628, epsilon);
154 EXPECT_NEAR(function.Slope(0.5), 1.33333, epsilon); 164 EXPECT_NEAR(function.Slope(0.5), 1.33333, epsilon);
155 EXPECT_NEAR(function.Slope(0.55), 1.32628, epsilon); 165 EXPECT_NEAR(function.Slope(0.55), 1.32628, epsilon);
156 EXPECT_NEAR(function.Slope(0.6), 1.30474, epsilon); 166 EXPECT_NEAR(function.Slope(0.6), 1.30474, epsilon);
157 EXPECT_NEAR(function.Slope(0.65), 1.26751, epsilon); 167 EXPECT_NEAR(function.Slope(0.65), 1.26751, epsilon);
158 EXPECT_NEAR(function.Slope(0.7), 1.21239, epsilon); 168 EXPECT_NEAR(function.Slope(0.7), 1.21239, epsilon);
159 EXPECT_NEAR(function.Slope(0.75), 1.13576, epsilon); 169 EXPECT_NEAR(function.Slope(0.75), 1.13576, epsilon);
160 EXPECT_NEAR(function.Slope(0.8), 1.03184, epsilon); 170 EXPECT_NEAR(function.Slope(0.8), 1.03184, epsilon);
161 EXPECT_NEAR(function.Slope(0.85), 0.89121, epsilon); 171 EXPECT_NEAR(function.Slope(0.85), 0.89121, epsilon);
162 EXPECT_NEAR(function.Slope(0.9), 0.69778, epsilon); 172 EXPECT_NEAR(function.Slope(0.9), 0.69778, epsilon);
163 EXPECT_NEAR(function.Slope(0.95), 0.42170, epsilon); 173 EXPECT_NEAR(function.Slope(0.95), 0.42170, epsilon);
164 EXPECT_NEAR(function.Slope(1), 0, epsilon); 174 EXPECT_NEAR(function.Slope(1), 0, epsilon);
175 EXPECT_NEAR(function.Slope(1.1), 0, epsilon);
165 } 176 }
166 177
167 TEST(CubicBezierTest, InputOutOfRange) { 178 TEST(CubicBezierTest, InputOutOfRange) {
168 CubicBezier simple(0.5, 1.0, 0.5, 1.0); 179 CubicBezier simple(0.5, 1.0, 0.5, 1.0);
169 EXPECT_EQ(-2.0, simple.Solve(-1.0)); 180 EXPECT_EQ(-2.0, simple.Solve(-1.0));
170 EXPECT_EQ(1.0, simple.Solve(2.0)); 181 EXPECT_EQ(1.0, simple.Solve(2.0));
171 182
172 CubicBezier coincidentEndpoints(0.0, 0.0, 1.0, 1.0); 183 CubicBezier at_edge_of_range(0.5, 1.0, 0.5, 1.0);
173 EXPECT_EQ(-1.0, coincidentEndpoints.Solve(-1.0)); 184 EXPECT_EQ(0.0, at_edge_of_range.Solve(0.0));
174 EXPECT_EQ(2.0, coincidentEndpoints.Solve(2.0)); 185 EXPECT_EQ(1.0, at_edge_of_range.Solve(1.0));
175 186
176 CubicBezier verticalGradient(0.0, 1.0, 1.0, 0.0); 187 CubicBezier large_epsilon(0.5, 1.0, 0.5, 1.0);
177 EXPECT_EQ(0.0, verticalGradient.Solve(-1.0)); 188 EXPECT_EQ(-2.0, large_epsilon.SolveWithEpsilon(-1.0, 1.0));
178 EXPECT_EQ(1.0, verticalGradient.Solve(2.0)); 189 EXPECT_EQ(1.0, large_epsilon.SolveWithEpsilon(2.0, 1.0));
179 190
180 CubicBezier distinctEndpoints(0.1, 0.2, 0.8, 0.8); 191 CubicBezier coincident_endpoints(0.0, 0.0, 1.0, 1.0);
181 EXPECT_EQ(-2.0, distinctEndpoints.Solve(-1.0)); 192 EXPECT_EQ(-1.0, coincident_endpoints.Solve(-1.0));
182 EXPECT_EQ(2.0, distinctEndpoints.Solve(2.0)); 193 EXPECT_EQ(2.0, coincident_endpoints.Solve(2.0));
183 194
184 CubicBezier coincidentEndpoint(0.0, 0.0, 0.8, 0.8); 195 CubicBezier vertical_gradient(0.0, 1.0, 1.0, 0.0);
185 EXPECT_EQ(-1.0, coincidentEndpoint.Solve(-1.0)); 196 EXPECT_EQ(0.0, vertical_gradient.Solve(-1.0));
186 EXPECT_EQ(2.0, coincidentEndpoint.Solve(2.0)); 197 EXPECT_EQ(1.0, vertical_gradient.Solve(2.0));
187 198
188 CubicBezier threeCoincidentPoints(0.0, 0.0, 0.0, 0.0); 199 CubicBezier distinct_endpoints(0.1, 0.2, 0.8, 0.8);
189 EXPECT_EQ(0, threeCoincidentPoints.Solve(-1.0)); 200 EXPECT_EQ(-2.0, distinct_endpoints.Solve(-1.0));
190 EXPECT_EQ(2.0, threeCoincidentPoints.Solve(2.0)); 201 EXPECT_EQ(2.0, distinct_endpoints.Solve(2.0));
202
203 CubicBezier coincident_endpoint(0.0, 0.0, 0.8, 0.8);
204 EXPECT_EQ(-1.0, coincident_endpoint.Solve(-1.0));
205 EXPECT_EQ(2.0, coincident_endpoint.Solve(2.0));
206
207 CubicBezier three_coincident_points(0.0, 0.0, 0.0, 0.0);
208 EXPECT_EQ(0, three_coincident_points.Solve(-1.0));
209 EXPECT_EQ(2.0, three_coincident_points.Solve(2.0));
191 210
192 } 211 }
193 212
194 } // namespace 213 } // namespace
195 } // namespace gfx 214 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/geometry/cubic_bezier.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698