Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(866)

Side by Side Diff: sky/framework/animation/curves.dart

Issue 942413002: Port sky-drawer to Dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/framework/animation/controller.sky ('k') | sky/framework/animation/curves.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 double _evaluateCubic(double a, double b, double m) {
6 // TODO(abarth): Would Math.pow be faster?
7 return 3 * a * (1 - m) * (1 - m) * m + 3 * b * (1 - m) * m * m + m * m * m;
8 }
9
10 const double _kCubicErrorBound = 0.001;
11
12 abstract class Curve {
13 double transform(double t);
14 }
15
16 class Linear implements Curve {
17 const Linear();
18
19 double transform(double t) {
20 return t;
21 }
22 }
23
24 class Cubic implements Curve {
25 final double a;
26 final double b;
27 final double c;
28 final double d;
29
30 const Cubic(this.a, this.b, this.c, this.d);
31
32 double transform(double t) {
33 double start = 0.0;
34 double end = 1.0;
35 while (true) {
36 double midpoint = (start + end) / 2;
37 double estimate = _evaluateCubic(a, c, midpoint);
38
39 if ((t - estimate).abs() < _kCubicErrorBound)
40 return _evaluateCubic(b, d, midpoint);
41
42 if (estimate < t)
43 start = midpoint;
44 else
45 end = midpoint;
46 }
47 }
48 }
49
50 const Linear linear = const Linear();
51 const Cubic ease = const Cubic(0.25, 0.1, 0.25, 1.0);
52 const Cubic easeIn = const Cubic(0.42, 0.0, 1.0, 1.0);
53 const Cubic easeOut = const Cubic(0.0, 0.0, 0.58, 1.0);
54 const Cubic easeInOut = const Cubic(0.42, 0.0, 0.58, 1.0);
OLDNEW
« no previous file with comments | « sky/framework/animation/controller.sky ('k') | sky/framework/animation/curves.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698