| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "platform/animation/TimingFunction.h" | 5 #include "platform/animation/TimingFunction.h" |
| 6 | 6 |
| 7 #include "platform/animation/CubicBezierControlPoints.h" | 7 #include "platform/animation/CubicBezierControlPoints.h" |
| 8 #include "wtf/MathExtras.h" | 8 #include "wtf/MathExtras.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 default: | 47 default: |
| 48 ASSERT_NOT_REACHED(); | 48 ASSERT_NOT_REACHED(); |
| 49 } | 49 } |
| 50 return ""; | 50 return ""; |
| 51 } | 51 } |
| 52 | 52 |
| 53 double CubicBezierTimingFunction::evaluate(double fraction, double accuracy) con
st | 53 double CubicBezierTimingFunction::evaluate(double fraction, double accuracy) con
st |
| 54 { | 54 { |
| 55 if (!m_bezier) | 55 if (!m_bezier) |
| 56 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); | 56 m_bezier = adoptPtr(new UnitBezier(m_x1, m_y1, m_x2, m_y2)); |
| 57 return m_bezier->solve(fraction, accuracy); | 57 return m_bezier->solveWithEpsilon(fraction, accuracy); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // This works by taking taking the derivative of the cubic bezier, on the y | 60 // This works by taking taking the derivative of the cubic bezier, on the y |
| 61 // axis. We can then solve for where the derivative is zero to find the min | 61 // axis. We can then solve for where the derivative is zero to find the min |
| 62 // and max distace along the line. We the have to solve those in terms of time | 62 // and max distace along the line. We the have to solve those in terms of time |
| 63 // rather than distance on the x-axis | 63 // rather than distance on the x-axis |
| 64 void CubicBezierTimingFunction::range(double* minValue, double* maxValue) const | 64 void CubicBezierTimingFunction::range(double* minValue, double* maxValue) const |
| 65 { | 65 { |
| 66 if (0 <= m_y1 && m_y2 < 1 && 0 <= m_y2 && m_y2 <= 1) { | 66 if (0 <= m_y1 && m_y2 < 1 && 0 <= m_y2 && m_y2 <= 1) { |
| 67 return; | 67 return; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // actually evaluated in [0,1]. After that we take the tangent at that point | 102 // actually evaluated in [0,1]. After that we take the tangent at that point |
| 103 // and linearly project it out. | 103 // and linearly project it out. |
| 104 if (0 < t1 && t1 < 1) | 104 if (0 < t1 && t1 < 1) |
| 105 solution1 = m_bezier->sampleCurveY(t1); | 105 solution1 = m_bezier->sampleCurveY(t1); |
| 106 | 106 |
| 107 if (0 < t2 && t2 < 1) | 107 if (0 < t2 && t2 < 1) |
| 108 solution2 = m_bezier->sampleCurveY(t2); | 108 solution2 = m_bezier->sampleCurveY(t2); |
| 109 | 109 |
| 110 // Since our input values can be out of the range 0->1 so we must also | 110 // Since our input values can be out of the range 0->1 so we must also |
| 111 // consider the minimum and maximum points. | 111 // consider the minimum and maximum points. |
| 112 double solutionMin = m_bezier->solve(*minValue, std::numeric_limits<double>:
:epsilon()); | 112 double solutionMin = m_bezier->solveWithEpsilon(*minValue, std::numeric_limi
ts<double>::epsilon()); |
| 113 double solutionMax = m_bezier->solve(*maxValue, std::numeric_limits<double>:
:epsilon()); | 113 double solutionMax = m_bezier->solveWithEpsilon(*maxValue, std::numeric_limi
ts<double>::epsilon()); |
| 114 *minValue = std::min(std::min(solutionMin, solutionMax), 0.0); | 114 *minValue = std::min(std::min(solutionMin, solutionMax), 0.0); |
| 115 *maxValue = std::max(std::max(solutionMin, solutionMax), 1.0); | 115 *maxValue = std::max(std::max(solutionMin, solutionMax), 1.0); |
| 116 *minValue = std::min(std::min(*minValue, solution1), solution2); | 116 *minValue = std::min(std::min(*minValue, solution1), solution2); |
| 117 *maxValue = std::max(std::max(*maxValue, solution1), solution2); | 117 *maxValue = std::max(std::max(*maxValue, solution1), solution2); |
| 118 } | 118 } |
| 119 | 119 |
| 120 size_t CubicBezierTimingFunction::findIntersections(double intersectionY, double
& solution1, double& solution2, double& solution3) const | 120 size_t CubicBezierTimingFunction::findIntersections(double intersectionY, double
& solution1, double& solution2, double& solution3) const |
| 121 { | 121 { |
| 122 size_t numberOfIntersections = 0; | 122 size_t numberOfIntersections = 0; |
| 123 | 123 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 return false; | 394 return false; |
| 395 } | 395 } |
| 396 | 396 |
| 397 // No need to define specific operator!= as they can all come via this function. | 397 // No need to define specific operator!= as they can all come via this function. |
| 398 bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) | 398 bool operator!=(const TimingFunction& lhs, const TimingFunction& rhs) |
| 399 { | 399 { |
| 400 return !(lhs == rhs); | 400 return !(lhs == rhs); |
| 401 } | 401 } |
| 402 | 402 |
| 403 } // namespace blink | 403 } // namespace blink |
| OLD | NEW |