mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Merge pull request #3 from HansMuller/add-bounded-friction-simulation
Added BoundedFrictionSimulation
This commit is contained in:
commit
7c8bf7e05e
@ -24,3 +24,25 @@ class FrictionSimulation extends Simulation {
|
||||
@override
|
||||
bool isDone(double time) => dx(time).abs() < this.tolerance.velocity;
|
||||
}
|
||||
|
||||
class BoundedFrictionSimulation extends FrictionSimulation {
|
||||
BoundedFrictionSimulation(
|
||||
double drag,
|
||||
double position,
|
||||
double velocity,
|
||||
double this._minX,
|
||||
double this._maxX) : super(drag, position, velocity);
|
||||
|
||||
final double _minX;
|
||||
final double _maxX;
|
||||
|
||||
double x(double time) {
|
||||
return super.x(time).clamp(_minX, _maxX);
|
||||
}
|
||||
|
||||
bool isDone(double time) {
|
||||
return super.isDone(time) ||
|
||||
(x(time) - _minX).abs() < tolerance.distance ||
|
||||
(x(time) - _maxX).abs() < tolerance.distance;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user