Chromium Code Reviews| Index: sky/framework/animation/curves.sky |
| diff --git a/sky/framework/animation/curves.sky b/sky/framework/animation/curves.sky |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..382085df963099bb7f164a9820fe47b92c56f004 |
| --- /dev/null |
| +++ b/sky/framework/animation/curves.sky |
| @@ -0,0 +1,53 @@ |
| +<!-- |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +--> |
| +<script> |
| +function evaluateCubic(a, b, m) { |
| + return 3 * a * (1 - m) * (1 - m) * m + 3 * b * (1 - m) * m * m + m * m * m |
|
esprehn
2015/01/29 19:03:57
I wonder if this is faster or slow than just using
abarth-chromium
2015/01/29 19:16:45
I'll add a TODO comment with that question.
abarth-chromium
2015/01/29 19:16:45
I'll add a TODO comment with that question.
|
| +} |
| + |
| +const kCubicErrorBound = 0.001; |
| + |
| +class Linear { |
| + transform(t) { |
| + return t; |
| + } |
| +}; |
| + |
| +class Cubic { |
| + constructor(a, b, c, d) { |
| + this.a_ = a; |
| + this.b_ = b; |
| + this.c_ = c; |
| + this.d_ = d; |
| + Object.preventExtensions(this); |
| + } |
| + |
| + transform(t) { |
| + var start = 0, end = 1; |
| + while (1) { |
| + var midpoint = (start + end) / 2; |
| + var estimate = evaluateCubic(this.a_, this.c_, midpoint); |
| + |
| + if (Math.abs(t - estimate) < kCubicErrorBound) |
| + return evaluateCubic(this.b_, this.d_, midpoint); |
| + |
| + if (estimate < t) |
| + start = midpoint; |
| + else |
| + end = midpoint; |
| + } |
| + } |
| +} |
| + |
| +module.exports = { |
| + Cubic: Cubic, |
| + linear: new Linear(), |
|
esprehn
2015/01/29 19:03:57
Why expose the Cubic class not but the Linear one?
abarth-chromium
2015/01/29 19:16:45
I'll expose the Linear class. Its constructor doe
|
| + ease: new Cubic(0.25, 0.1, 0.25, 1), |
| + easeIn: new Cubic(0.42, 0, 1, 1), |
| + easeOut: new Cubic(0, 0, 0.58, 1), |
| + easeInOut: new Cubic(0.42, 0, 0.58, 1), |
| +}; |
| +</script> |