summaryrefslogtreecommitdiffstats
path: root/cc/animation/timing_function_unittest.cc
diff options
context:
space:
mode:
authorvollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-29 02:52:25 +0000
committervollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-29 02:52:25 +0000
commit6b1d558a80d80528df4f86d75b2a43a26f3e2487 (patch)
treea8ed97f25c16f946a9d969ac70340d2c03bae267 /cc/animation/timing_function_unittest.cc
parentc40df01c49515eea3e9ee37bc82b644c778ee25e (diff)
downloadchromium_src-6b1d558a80d80528df4f86d75b2a43a26f3e2487.zip
chromium_src-6b1d558a80d80528df4f86d75b2a43a26f3e2487.tar.gz
chromium_src-6b1d558a80d80528df4f86d75b2a43a26f3e2487.tar.bz2
Do not clamp y values on internal knots of timing function bezier curves
Cubic bezier timing functions are based on two knots (x1, y1) and (x2, y2) (the other knots are assumed to be (0, 0) and (1, 1)). We require that x1, x2 lie within (0, 1) (so that the bezier does not 'fold back' on itself), but y1, and y2 should have no such constraint. They currently do. This CL reimplements bezier interpolation without this restriction. This interpolation has two steps: 1) Find the t corresponding to the desired x. 2) Interpolate y's at the t computed in step 1. Step 1 is an iterative minimization. Here I do bisection for simplicity, but I could take Newton steps if this turns out to be a bottleneck. R=ajuma@chromium.org BUG=178070 Review URL: https://chromiumcodereview.appspot.com/16112002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202755 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/animation/timing_function_unittest.cc')
-rw-r--r--cc/animation/timing_function_unittest.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/cc/animation/timing_function_unittest.cc b/cc/animation/timing_function_unittest.cc
index c076d52..2caa12d 100644
--- a/cc/animation/timing_function_unittest.cc
+++ b/cc/animation/timing_function_unittest.cc
@@ -37,5 +37,35 @@ TEST(TimingFunctionTest, CubicBezierTimingFunction) {
EXPECT_NEAR(function->GetValue(1), 1, epsilon);
}
+// Tests that the bezier timing function works with knots with y not in (0, 1).
+TEST(TimingFunctionTest, CubicBezierTimingFunctionUnclampedYValues) {
+ scoped_ptr<CubicBezierTimingFunction> function =
+ CubicBezierTimingFunction::Create(0.5, -1.0, 0.5, 2.0);
+
+ double epsilon = 0.00015;
+
+ EXPECT_NEAR(function->GetValue(0.0), 0.0, epsilon);
+ EXPECT_NEAR(function->GetValue(0.05), -0.08954, epsilon);
+ EXPECT_NEAR(function->GetValue(0.1), -0.15613, epsilon);
+ EXPECT_NEAR(function->GetValue(0.15), -0.19641, epsilon);
+ EXPECT_NEAR(function->GetValue(0.2), -0.20651, epsilon);
+ EXPECT_NEAR(function->GetValue(0.25), -0.18232, epsilon);
+ EXPECT_NEAR(function->GetValue(0.3), -0.11992, epsilon);
+ EXPECT_NEAR(function->GetValue(0.35), -0.01672, epsilon);
+ EXPECT_NEAR(function->GetValue(0.4), 0.12660, epsilon);
+ EXPECT_NEAR(function->GetValue(0.45), 0.30349, epsilon);
+ EXPECT_NEAR(function->GetValue(0.5), 0.50000, epsilon);
+ EXPECT_NEAR(function->GetValue(0.55), 0.69651, epsilon);
+ EXPECT_NEAR(function->GetValue(0.6), 0.87340, epsilon);
+ EXPECT_NEAR(function->GetValue(0.65), 1.01672, epsilon);
+ EXPECT_NEAR(function->GetValue(0.7), 1.11992, epsilon);
+ EXPECT_NEAR(function->GetValue(0.75), 1.18232, epsilon);
+ EXPECT_NEAR(function->GetValue(0.8), 1.20651, epsilon);
+ EXPECT_NEAR(function->GetValue(0.85), 1.19641, epsilon);
+ EXPECT_NEAR(function->GetValue(0.9), 1.15613, epsilon);
+ EXPECT_NEAR(function->GetValue(0.95), 1.08954, epsilon);
+ EXPECT_NEAR(function->GetValue(1.0), 1.0, epsilon);
+}
+
} // namespace
} // namespace cc