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

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

Issue 833093002: CC: Allow cubic-bezier timing inputs outside the range [0, 1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0
Patch Set: Trigger CQ build Created 5 years, 11 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.h ('k') | ui/gfx/geometry/cubic_bezier_unittest.cc » ('j') | 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 return t; 64 return t;
65 } 65 }
66 66
67 } // namespace 67 } // namespace
68 68
69 CubicBezier::CubicBezier(double x1, double y1, double x2, double y2) 69 CubicBezier::CubicBezier(double x1, double y1, double x2, double y2)
70 : x1_(x1), 70 : x1_(x1),
71 y1_(y1), 71 y1_(y1),
72 x2_(x2), 72 x2_(x2),
73 y2_(y2) { 73 y2_(y2) {
74 InitGradients();
74 } 75 }
75 76
76 CubicBezier::~CubicBezier() { 77 CubicBezier::~CubicBezier() {
77 } 78 }
78 79
80 void CubicBezier::InitGradients() {
81 if (x1_ > 0)
82 start_gradient_ = y1_ / x1_;
83 else if (!y1_ && x2_ > 0)
84 start_gradient_ = y2_ / x2_;
85 else
86 start_gradient_ = 0;
87
88 if (x2_ < 1)
89 end_gradient_ = (y2_ - 1) / (x2_ - 1);
90 else if (x2_ == 1 && x1_ < 1)
91 end_gradient_ = (y1_ - 1) / (x1_ - 1);
92 else
93 end_gradient_ = 0;
94 }
95
79 double CubicBezier::Solve(double x) const { 96 double CubicBezier::Solve(double x) const {
97 if (x < 0)
98 return start_gradient_ * x;
99 if (x > 1)
100 return 1.0 + end_gradient_ * (x - 1.0);
101
80 return eval_bezier(y1_, y2_, bezier_interp(x1_, x2_, x)); 102 return eval_bezier(y1_, y2_, bezier_interp(x1_, x2_, x));
81 } 103 }
82 104
83 double CubicBezier::Slope(double x) const { 105 double CubicBezier::Slope(double x) const {
84 double t = bezier_interp(x1_, x2_, x); 106 double t = bezier_interp(x1_, x2_, x);
85 double dx_dt = eval_bezier_derivative(x1_, x2_, t); 107 double dx_dt = eval_bezier_derivative(x1_, x2_, t);
86 double dy_dt = eval_bezier_derivative(y1_, y2_, t); 108 double dy_dt = eval_bezier_derivative(y1_, y2_, t);
87 return dy_dt / dx_dt; 109 return dy_dt / dx_dt;
88 } 110 }
89 111
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 sol_1 = eval_bezier(y1_, y2_, t_1); 152 sol_1 = eval_bezier(y1_, y2_, t_1);
131 153
132 if (0 < t_2 && t_2 < 1) 154 if (0 < t_2 && t_2 < 1)
133 sol_2 = eval_bezier(y1_, y2_, t_2); 155 sol_2 = eval_bezier(y1_, y2_, t_2);
134 156
135 *min = std::min(std::min(*min, sol_1), sol_2); 157 *min = std::min(std::min(*min, sol_1), sol_2);
136 *max = std::max(std::max(*max, sol_1), sol_2); 158 *max = std::max(std::max(*max, sol_1), sol_2);
137 } 159 }
138 160
139 } // namespace gfx 161 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/geometry/cubic_bezier.h ('k') | ui/gfx/geometry/cubic_bezier_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698