OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 import "dart:math" as math; | 5 import "dart:math" as math; |
6 | 6 |
7 const double _kDefaultAlpha = -5707.62; | 7 const double _kDefaultAlpha = -5707.62; |
8 const double _kDefaultBeta = 172.0; | 8 const double _kDefaultBeta = 172.0; |
9 const double _kDefaultGamma = 3.7; | 9 const double _kDefaultGamma = 3.7; |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 class FlingCurve { | 30 class FlingCurve { |
31 double _timeOffset; | 31 double _timeOffset; |
32 double _positionOffset; | 32 double _positionOffset; |
33 double _startTime; | 33 double _startTime; |
34 double _previousPosition; | 34 double _previousPosition; |
35 double _direction; | 35 double _direction; |
36 | 36 |
37 FlingCurve(double velocity, double startTime) { | 37 FlingCurve(double velocity, double startTime) { |
38 double startingVelocity = math.min(_kMaxVelocity, velocity.abs()); | 38 double startingVelocity = math.min(_kMaxVelocity, velocity.abs()); |
39 _timeOffset = _velocityAtTime(startingVelocity); | 39 _timeOffset = _timeAtVelocity(startingVelocity); |
40 _positionOffset = _positionAtTime(_timeOffset); | 40 _positionOffset = _positionAtTime(_timeOffset); |
41 _startTime = startTime / 1000.0; | 41 _startTime = startTime / 1000.0; |
42 _previousPosition = 0.0; | 42 _previousPosition = 0.0; |
43 _direction = velocity.sign; | 43 _direction = velocity.sign; |
44 } | 44 } |
45 | 45 |
46 double update(double timeStamp) { | 46 double update(double timeStamp) { |
47 double t = timeStamp / 1000.0 - _startTime + _timeOffset; | 47 double t = timeStamp / 1000.0 - _startTime + _timeOffset; |
48 if (t >= _kCurveDuration) | 48 if (t >= _kCurveDuration) |
49 return 0.0; | 49 return 0.0; |
50 double position = _positionAtTime(t) - _positionOffset; | 50 double position = _positionAtTime(t) - _positionOffset; |
51 double positionDelta = position - _previousPosition; | 51 double positionDelta = position - _previousPosition; |
52 _previousPosition = position; | 52 _previousPosition = position; |
53 return _direction * math.max(0.0, positionDelta); | 53 return _direction * math.max(0.0, positionDelta); |
54 } | 54 } |
55 } | 55 } |
OLD | NEW |