| Index: ui/gfx/geometry/cubic_bezier.cc
|
| diff --git a/cc/animation/timing_function.cc b/ui/gfx/geometry/cubic_bezier.cc
|
| similarity index 51%
|
| copy from cc/animation/timing_function.cc
|
| copy to ui/gfx/geometry/cubic_bezier.cc
|
| index 7fdb37fed962a48fa68a3e9b58252b694c50f4ca..3d7e8fe930349eb3ec743aeec2b6311b99c66108 100644
|
| --- a/cc/animation/timing_function.cc
|
| +++ b/ui/gfx/geometry/cubic_bezier.cc
|
| @@ -1,14 +1,15 @@
|
| -// Copyright 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "ui/gfx/geometry/cubic_bezier.h"
|
| +
|
| #include <algorithm>
|
| #include <cmath>
|
|
|
| #include "base/logging.h"
|
| -#include "cc/animation/timing_function.h"
|
|
|
| -namespace cc {
|
| +namespace gfx {
|
|
|
| namespace {
|
|
|
| @@ -63,46 +64,30 @@ static double bezier_interp(double x1,
|
|
|
| } // namespace
|
|
|
| -TimingFunction::TimingFunction() {}
|
| -
|
| -TimingFunction::~TimingFunction() {}
|
| -
|
| -double TimingFunction::Duration() const {
|
| - return 1.0;
|
| -}
|
| -
|
| -scoped_ptr<CubicBezierTimingFunction> CubicBezierTimingFunction::Create(
|
| - double x1, double y1, double x2, double y2) {
|
| - return make_scoped_ptr(new CubicBezierTimingFunction(x1, y1, x2, y2));
|
| +CubicBezier::CubicBezier(double x1, double y1, double x2, double y2)
|
| + : x1_(x1),
|
| + y1_(y1),
|
| + x2_(x2),
|
| + y2_(y2) {
|
| }
|
|
|
| -CubicBezierTimingFunction::CubicBezierTimingFunction(double x1,
|
| - double y1,
|
| - double x2,
|
| - double y2)
|
| - : x1_(x1), y1_(y1), x2_(x2), y2_(y2) {}
|
| -
|
| -CubicBezierTimingFunction::~CubicBezierTimingFunction() {}
|
| -
|
| -float CubicBezierTimingFunction::GetValue(double x) const {
|
| - return static_cast<float>(bezier_interp(x1_, y1_, x2_, y2_, x));
|
| +CubicBezier::~CubicBezier() {
|
| }
|
|
|
| -scoped_ptr<AnimationCurve> CubicBezierTimingFunction::Clone() const {
|
| - return make_scoped_ptr(
|
| - new CubicBezierTimingFunction(*this)).PassAs<AnimationCurve>();
|
| +double CubicBezier::Solve(double x) const {
|
| + return bezier_interp(x1_, y1_, x2_, y2_, x);
|
| }
|
|
|
| -void CubicBezierTimingFunction::Range(float* min, float* max) const {
|
| - *min = 0.f;
|
| - *max = 1.f;
|
| - if (0.f <= y1_ && y1_ < 1.f && 0.f <= y2_ && y2_ <= 1.f)
|
| +void CubicBezier::Range(double* min, double* max) const {
|
| + *min = 0;
|
| + *max = 1;
|
| + if (0 <= y1_ && y1_ < 1 && 0 <= y2_ && y2_ <= 1)
|
| return;
|
|
|
| // Represent the function's derivative in the form at^2 + bt + c.
|
| - float a = 3.f * (y1_ - y2_) + 1.f;
|
| - float b = 2.f * (y2_ - 2.f * y1_);
|
| - float c = y1_;
|
| + double a = 3 * (y1_ - y2_) + 1;
|
| + double b = 2 * (y2_ - 2 * y1_);
|
| + double c = y1_;
|
|
|
| // Check if the derivative is constant.
|
| if (std::abs(a) < kBezierEpsilon &&
|
| @@ -110,8 +95,8 @@ void CubicBezierTimingFunction::Range(float* min, float* max) const {
|
| return;
|
|
|
| // Zeros of the function's derivative.
|
| - float t_1 = 0.f;
|
| - float t_2 = 0.f;
|
| + double t_1 = 0;
|
| + double t_2 = 0;
|
|
|
| if (std::abs(a) < kBezierEpsilon) {
|
| // The function's derivative is linear.
|
| @@ -119,47 +104,25 @@ void CubicBezierTimingFunction::Range(float* min, float* max) const {
|
| } else {
|
| // The function's derivative is a quadratic. We find the zeros of this
|
| // quadratic using the quadratic formula.
|
| - float discriminant = b * b - 4 * a * c;
|
| - if (discriminant < 0.f)
|
| + double discriminant = b * b - 4 * a * c;
|
| + if (discriminant < 0)
|
| return;
|
| - float discriminant_sqrt = sqrt(discriminant);
|
| - t_1 = (-b + discriminant_sqrt) / (2.f * a);
|
| - t_2 = (-b - discriminant_sqrt) / (2.f * a);
|
| + double discriminant_sqrt = sqrt(discriminant);
|
| + t_1 = (-b + discriminant_sqrt) / (2 * a);
|
| + t_2 = (-b - discriminant_sqrt) / (2 * a);
|
| }
|
|
|
| - float sol_1 = 0.f;
|
| - float sol_2 = 0.f;
|
| + double sol_1 = 0;
|
| + double sol_2 = 0;
|
|
|
| - if (0.f < t_1 && t_1 < 1.f)
|
| + if (0 < t_1 && t_1 < 1)
|
| sol_1 = eval_bezier(y1_, y2_, t_1);
|
|
|
| - if (0.f < t_2 && t_2 < 1.f)
|
| + if (0 < t_2 && t_2 < 1)
|
| sol_2 = eval_bezier(y1_, y2_, t_2);
|
|
|
| *min = std::min(std::min(*min, sol_1), sol_2);
|
| *max = std::max(std::max(*max, sol_1), sol_2);
|
| }
|
|
|
| -// These numbers come from
|
| -// http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag.
|
| -scoped_ptr<TimingFunction> EaseTimingFunction::Create() {
|
| - return CubicBezierTimingFunction::Create(
|
| - 0.25, 0.1, 0.25, 1.0).PassAs<TimingFunction>();
|
| -}
|
| -
|
| -scoped_ptr<TimingFunction> EaseInTimingFunction::Create() {
|
| - return CubicBezierTimingFunction::Create(
|
| - 0.42, 0.0, 1.0, 1.0).PassAs<TimingFunction>();
|
| -}
|
| -
|
| -scoped_ptr<TimingFunction> EaseOutTimingFunction::Create() {
|
| - return CubicBezierTimingFunction::Create(
|
| - 0.0, 0.0, 0.58, 1.0).PassAs<TimingFunction>();
|
| -}
|
| -
|
| -scoped_ptr<TimingFunction> EaseInOutTimingFunction::Create() {
|
| - return CubicBezierTimingFunction::Create(
|
| - 0.42, 0.0, 0.58, 1).PassAs<TimingFunction>();
|
| -}
|
| -
|
| -} // namespace cc
|
| +} // namespace gfx
|
|
|