OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/animation/timing_function.h" | 5 #include "cc/animation/timing_function.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 *min = 0.0f; | 102 *min = 0.0f; |
103 *max = 1.0f; | 103 *max = 1.0f; |
104 } | 104 } |
105 | 105 |
106 float StepsTimingFunction::Velocity(double x) const { | 106 float StepsTimingFunction::Velocity(double x) const { |
107 return 0.0f; | 107 return 0.0f; |
108 } | 108 } |
109 | 109 |
110 double StepsTimingFunction::GetPreciseValue(double t) const { | 110 double StepsTimingFunction::GetPreciseValue(double t) const { |
111 const double steps = static_cast<double>(steps_); | 111 const double steps = static_cast<double>(steps_); |
112 return MathUtil::ClampToRange( | 112 double current_step = std::floor((steps * t) + GetStepsStartOffset()); |
113 std::floor((steps * t) + GetStepsStartOffset()) / steps, 0.0, 1.0); | 113 if (t >= 0 && current_step < 0) |
| 114 current_step = 0; |
| 115 if (t <= 1 && current_step > steps) |
| 116 current_step = steps; |
| 117 return current_step / steps; |
114 } | 118 } |
115 | 119 |
116 float StepsTimingFunction::GetStepsStartOffset() const { | 120 float StepsTimingFunction::GetStepsStartOffset() const { |
117 switch (step_position_) { | 121 switch (step_position_) { |
118 case StepPosition::START: | 122 case StepPosition::START: |
119 return 1; | 123 return 1; |
120 case StepPosition::MIDDLE: | 124 case StepPosition::MIDDLE: |
121 return 0.5; | 125 return 0.5; |
122 case StepPosition::END: | 126 case StepPosition::END: |
123 return 0; | 127 return 0; |
124 default: | 128 default: |
125 NOTREACHED(); | 129 NOTREACHED(); |
126 return 1; | 130 return 1; |
127 } | 131 } |
128 } | 132 } |
129 | 133 |
130 } // namespace cc | 134 } // namespace cc |
OLD | NEW |