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

Side by Side Diff: ui/gfx/animation/steps.cc

Issue 140253013: Define accelerated steps time function. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated patch: remove question about velocity 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 unified diff | Download patch
« no previous file with comments | « ui/gfx/animation/steps.h ('k') | ui/gfx/animation/steps_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/gfx/animation/steps.h"
6
7 #include <cmath>
8
9 #include "base/logging.h"
10
11 template <class T>
12 T clamp(T value, T min, T max) {
13 if (value < min)
14 value = min;
15 if (value > max)
16 value = max;
17 return value;
18 }
19
20 namespace gfx {
21
22 Steps::Steps(int steps, bool steps_at_start)
23 : steps_(steps), steps_at_start_(steps_at_start) {
24 }
25
26 Steps::~Steps() {
27 }
28
29 double Steps::Solve(double x) const {
30 x = clamp(x, 0.0, 1.0);
31 return std::min(1.0, (floor(steps_ * x) + steps_at_start_) / steps_);
32 }
33
34 void Steps::Range(double* min, double* max) const {
35 *min = static_cast<double>(steps_at_start_) / static_cast<double>(steps_);
36 *max = 1.0;
37 }
38
39 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/animation/steps.h ('k') | ui/gfx/animation/steps_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698