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

Unified Diff: ui/gfx/geometry/steps.cc

Issue 140253013: Define accelerated steps time function. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated patch: fixes reviewer comments + rebase against ToT Created 6 years, 3 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/steps.cc
diff --git a/ui/gfx/geometry/steps.cc b/ui/gfx/geometry/steps.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c5e9a2cc516938c6bb0d8a58eaf21026f5839ffa
--- /dev/null
+++ b/ui/gfx/geometry/steps.cc
@@ -0,0 +1,39 @@
+// 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/steps.h"
+
+#include <cmath>
+
+#include "base/logging.h"
+
+template <class T>
+T clamp(T value, T min, T max) {
+ if (value < min)
+ value = min;
+ if (value > max)
+ value = max;
+ return value;
+}
+
+namespace gfx {
+
+Steps::Steps(int steps, bool steps_at_start)
+ : steps_(steps), steps_at_start_(steps_at_start) {
+}
+
+Steps::~Steps() {
+}
+
+double Steps::Solve(double x) const {
+ x = clamp(x, 0.0, 1.0);
+ return std::min(1.0, (floor(steps_ * x) + steps_at_start_) / steps_);
+}
+
+void Steps::Range(double* min, double* max) const {
+ *min = static_cast<double>(steps_at_start_) / static_cast<double>(steps_);
+ *max = 1.0;
+}
+
+} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698