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

Unified 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: Created 5 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/geometry/cubic_bezier.cc
diff --git a/ui/gfx/geometry/cubic_bezier.cc b/ui/gfx/geometry/cubic_bezier.cc
index f9f786e7326105174ccff060fdb2ae0d2a186ab4..fe6dfcc7ff1af6c44033845df6dadf3232dff1db 100644
--- a/ui/gfx/geometry/cubic_bezier.cc
+++ b/ui/gfx/geometry/cubic_bezier.cc
@@ -71,12 +71,34 @@ CubicBezier::CubicBezier(double x1, double y1, double x2, double y2)
y1_(y1),
x2_(x2),
y2_(y2) {
+ InitGradients();
}
CubicBezier::~CubicBezier() {
}
+void CubicBezier::InitGradients() {
+ if (x1_ > 0)
+ start_gradient_ = y1_ / x1_;
+ else if (!y1_ && x2_ > 0)
+ start_gradient_ = y2_ / x2_;
+ else
+ start_gradient_ = 0;
+
+ if (x2_ < 1)
+ end_gradient_ = (y2_ - 1) / (x2_ - 1);
+ else if (x2_ == 1 && x1_ < 1)
+ end_gradient_ = (y1_ - 1) / (x1_ - 1);
+ else
+ end_gradient_ = 0;
+}
+
double CubicBezier::Solve(double x) const {
+ if (x < 0)
+ return start_gradient_ * x;
+ if (x > 1)
+ return 1.0 + end_gradient_ * (x - 1.0);
+
return eval_bezier(y1_, y2_, bezier_interp(x1_, x2_, x));
}

Powered by Google App Engine
This is Rietveld 408576698