OLD | NEW |
---|---|
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 Loading... | |
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 basicUse(0.5, 1.0, 0.5, 1.0); | |
danakj
2016/04/01 19:26:17
basic_use
loyso (OOO)
2016/04/04 02:25:29
Done.
| |
40 EXPECT_EQ(0.875, basicUse.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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 EXPECT_NEAR(function.Slope(0.9), 0.69778, epsilon); | 171 EXPECT_NEAR(function.Slope(0.9), 0.69778, epsilon); |
163 EXPECT_NEAR(function.Slope(0.95), 0.42170, epsilon); | 172 EXPECT_NEAR(function.Slope(0.95), 0.42170, epsilon); |
164 EXPECT_NEAR(function.Slope(1), 0, epsilon); | 173 EXPECT_NEAR(function.Slope(1), 0, epsilon); |
165 } | 174 } |
166 | 175 |
167 TEST(CubicBezierTest, InputOutOfRange) { | 176 TEST(CubicBezierTest, InputOutOfRange) { |
168 CubicBezier simple(0.5, 1.0, 0.5, 1.0); | 177 CubicBezier simple(0.5, 1.0, 0.5, 1.0); |
169 EXPECT_EQ(-2.0, simple.Solve(-1.0)); | 178 EXPECT_EQ(-2.0, simple.Solve(-1.0)); |
170 EXPECT_EQ(1.0, simple.Solve(2.0)); | 179 EXPECT_EQ(1.0, simple.Solve(2.0)); |
171 | 180 |
181 CubicBezier atEdgeOfRange(0.5, 1.0, 0.5, 1.0); | |
danakj
2016/04/01 19:26:18
at_edge_of_range
loyso (OOO)
2016/04/04 02:25:29
Done.
| |
182 EXPECT_EQ(0.0, atEdgeOfRange.Solve(0.0)); | |
183 EXPECT_EQ(1.0, atEdgeOfRange.Solve(1.0)); | |
184 | |
185 CubicBezier largeEpsilon(0.5, 1.0, 0.5, 1.0); | |
danakj
2016/04/01 19:26:17
large_epsilon
loyso (OOO)
2016/04/04 02:25:29
Done.
| |
186 EXPECT_EQ(-2.0, largeEpsilon.SolveWithEpsilon(-1.0, 1.0)); | |
187 EXPECT_EQ(1.0, largeEpsilon.SolveWithEpsilon(2.0, 1.0)); | |
188 | |
172 CubicBezier coincidentEndpoints(0.0, 0.0, 1.0, 1.0); | 189 CubicBezier coincidentEndpoints(0.0, 0.0, 1.0, 1.0); |
173 EXPECT_EQ(-1.0, coincidentEndpoints.Solve(-1.0)); | 190 EXPECT_EQ(-1.0, coincidentEndpoints.Solve(-1.0)); |
174 EXPECT_EQ(2.0, coincidentEndpoints.Solve(2.0)); | 191 EXPECT_EQ(2.0, coincidentEndpoints.Solve(2.0)); |
175 | 192 |
176 CubicBezier verticalGradient(0.0, 1.0, 1.0, 0.0); | 193 CubicBezier verticalGradient(0.0, 1.0, 1.0, 0.0); |
177 EXPECT_EQ(0.0, verticalGradient.Solve(-1.0)); | 194 EXPECT_EQ(0.0, verticalGradient.Solve(-1.0)); |
178 EXPECT_EQ(1.0, verticalGradient.Solve(2.0)); | 195 EXPECT_EQ(1.0, verticalGradient.Solve(2.0)); |
179 | 196 |
180 CubicBezier distinctEndpoints(0.1, 0.2, 0.8, 0.8); | 197 CubicBezier distinctEndpoints(0.1, 0.2, 0.8, 0.8); |
181 EXPECT_EQ(-2.0, distinctEndpoints.Solve(-1.0)); | 198 EXPECT_EQ(-2.0, distinctEndpoints.Solve(-1.0)); |
182 EXPECT_EQ(2.0, distinctEndpoints.Solve(2.0)); | 199 EXPECT_EQ(2.0, distinctEndpoints.Solve(2.0)); |
183 | 200 |
184 CubicBezier coincidentEndpoint(0.0, 0.0, 0.8, 0.8); | 201 CubicBezier coincidentEndpoint(0.0, 0.0, 0.8, 0.8); |
185 EXPECT_EQ(-1.0, coincidentEndpoint.Solve(-1.0)); | 202 EXPECT_EQ(-1.0, coincidentEndpoint.Solve(-1.0)); |
186 EXPECT_EQ(2.0, coincidentEndpoint.Solve(2.0)); | 203 EXPECT_EQ(2.0, coincidentEndpoint.Solve(2.0)); |
187 | 204 |
188 CubicBezier threeCoincidentPoints(0.0, 0.0, 0.0, 0.0); | 205 CubicBezier threeCoincidentPoints(0.0, 0.0, 0.0, 0.0); |
189 EXPECT_EQ(0, threeCoincidentPoints.Solve(-1.0)); | 206 EXPECT_EQ(0, threeCoincidentPoints.Solve(-1.0)); |
190 EXPECT_EQ(2.0, threeCoincidentPoints.Solve(2.0)); | 207 EXPECT_EQ(2.0, threeCoincidentPoints.Solve(2.0)); |
191 | 208 |
192 } | 209 } |
193 | 210 |
194 } // namespace | 211 } // namespace |
195 } // namespace gfx | 212 } // namespace gfx |
OLD | NEW |