OLD | NEW |
(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 |
OLD | NEW |