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

Side by Side Diff: sky/examples/fn/widgets/flingcurve.dart

Issue 976363003: Remove duplicate copy of fling-curve.dart in fn (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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 | « no previous file | sky/examples/fn/widgets/widgets.dart » ('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 part of widgets;
2
3 // Copyright 2015 The Chromium Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
6
7 const double _kDefaultAlpha = -5707.62;
8 const double _kDefaultBeta = 172.0;
9 const double _kDefaultGamma = 3.7;
10
11 double _positionAtTime(double t) {
12 return _kDefaultAlpha * math.exp(-_kDefaultGamma * t)
13 - _kDefaultBeta * t
14 - _kDefaultAlpha;
15 }
16
17 double _velocityAtTime(double t) {
18 return -_kDefaultAlpha * _kDefaultGamma * math.exp(-_kDefaultGamma * t)
19 - _kDefaultBeta;
20 }
21
22 double _timeAtVelocity(double v) {
23 return -math.log((v + _kDefaultBeta) / (-_kDefaultAlpha * _kDefaultGamma))
24 / _kDefaultGamma;
25 }
26
27 final double _kMaxVelocity = _velocityAtTime(0.0);
28 final double _kCurveDuration = _timeAtVelocity(0.0);
29
30 class FlingCurve {
31 double _timeOffset;
32 double _positionOffset;
33 double _startTime;
34 double _previousPosition;
35 double _direction;
36
37 FlingCurve(double velocity, double startTime) {
38 double startingVelocity = math.min(_kMaxVelocity, velocity.abs());
39 _timeOffset = _timeAtVelocity(startingVelocity);
40 _positionOffset = _positionAtTime(_timeOffset);
41 _startTime = startTime / 1000.0;
42 _previousPosition = 0.0;
43 _direction = velocity.sign;
44 }
45
46 double update(double timeStamp) {
47 double t = timeStamp / 1000.0 - _startTime + _timeOffset;
48 if (t >= _kCurveDuration)
49 return 0.0;
50 double position = _positionAtTime(t) - _positionOffset;
51 double positionDelta = position - _previousPosition;
52 _previousPosition = position;
53 return _direction * math.max(0.0, positionDelta);
54 }
55 }
OLDNEW
« no previous file with comments | « no previous file | sky/examples/fn/widgets/widgets.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698