| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 3 // Use of this source code is governed by a BSD-style license that can be | |
| 4 // found in the LICENSE file. | |
| 5 --> | |
| 6 <script> | |
| 7 function evaluateCubic(a, b, m) { | |
| 8 // TODO(abarth): Would Math.pow be faster? | |
| 9 return 3 * a * (1 - m) * (1 - m) * m + 3 * b * (1 - m) * m * m + m * m * m | |
| 10 } | |
| 11 | |
| 12 const kCubicErrorBound = 0.001; | |
| 13 | |
| 14 class Linear { | |
| 15 transform(t) { | |
| 16 return t; | |
| 17 } | |
| 18 }; | |
| 19 | |
| 20 class Cubic { | |
| 21 constructor(a, b, c, d) { | |
| 22 this.a_ = a; | |
| 23 this.b_ = b; | |
| 24 this.c_ = c; | |
| 25 this.d_ = d; | |
| 26 Object.preventExtensions(this); | |
| 27 } | |
| 28 | |
| 29 transform(t) { | |
| 30 var start = 0, end = 1; | |
| 31 while (1) { | |
| 32 var midpoint = (start + end) / 2; | |
| 33 var estimate = evaluateCubic(this.a_, this.c_, midpoint); | |
| 34 | |
| 35 if (Math.abs(t - estimate) < kCubicErrorBound) | |
| 36 return evaluateCubic(this.b_, this.d_, midpoint); | |
| 37 | |
| 38 if (estimate < t) | |
| 39 start = midpoint; | |
| 40 else | |
| 41 end = midpoint; | |
| 42 } | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 module.exports = { | |
| 47 Linear: Linear, | |
| 48 Cubic: Cubic, | |
| 49 linear: new Linear(), | |
| 50 ease: new Cubic(0.25, 0.1, 0.25, 1), | |
| 51 easeIn: new Cubic(0.42, 0, 1, 1), | |
| 52 easeOut: new Cubic(0, 0, 0.58, 1), | |
| 53 easeInOut: new Cubic(0.42, 0, 0.58, 1), | |
| 54 }; | |
| 55 </script> | |
| OLD | NEW |