diff --git a/packages/newton/README.md b/packages/newton/README.md index 02942a74f9..ccd16eaf98 100644 --- a/packages/newton/README.md +++ b/packages/newton/README.md @@ -3,3 +3,7 @@ [![Coverage Status](https://coveralls.io/repos/domokit/newton/badge.svg?branch=master)](https://coveralls.io/r/domokit/newton?branch=master) Simple Physics Simulations for Dart. Springs, friction, gravity, etc. + +To run the tests: +pub get +dart test/newton_test.dart diff --git a/packages/newton/lib/src/scroll_simulation.dart b/packages/newton/lib/src/scroll_simulation.dart index 9dece96207..f45b6724c5 100644 --- a/packages/newton/lib/src/scroll_simulation.dart +++ b/packages/newton/lib/src/scroll_simulation.dart @@ -8,24 +8,25 @@ part of newton; /// boundary. Friction is applied within the extends and a spring action applied /// at the boundaries. This simulation can only step forward. class ScrollSimulation extends SimulationGroup { + ScrollSimulation( + double position, + double velocity, + this._leadingExtent, + this._trailingExtent, + this._spring, + this._drag) { + _chooseSimulation(position, velocity, 0.0); + } + final double _leadingExtent; final double _trailingExtent; - final SpringDescription _springDesc; + final SpringDescription _spring; final double _drag; bool _isSpringing = false; Simulation _currentSimulation; double _offset = 0.0; - ScrollSimulation(double position, double velocity, double leading, - double trailing, SpringDescription spring, double drag) - : _leadingExtent = leading, - _trailingExtent = trailing, - _springDesc = spring, - _drag = drag { - _chooseSimulation(position, velocity, 0.0); - } - @override bool step(double time) => _chooseSimulation( _currentSimulation.x(time - _offset), @@ -37,11 +38,8 @@ class ScrollSimulation extends SimulationGroup { @override double get currentIntervalOffset => _offset; - bool _chooseSimulation( - double position, double velocity, double intervalOffset) { - - if (_springDesc == null && - (position > _trailingExtent || position < _leadingExtent)) + bool _chooseSimulation(double position, double velocity, double intervalOffset) { + if (_spring == null && (position > _trailingExtent || position < _leadingExtent)) return false; /// This simulation can only step forward. @@ -49,14 +47,12 @@ class ScrollSimulation extends SimulationGroup { if (position > _trailingExtent) { _isSpringing = true; _offset = intervalOffset; - _currentSimulation = new SpringSimulation( - _springDesc, position, _trailingExtent, velocity); + _currentSimulation = new SpringSimulation(_spring, position, _trailingExtent, velocity); return true; } else if (position < _leadingExtent) { _isSpringing = true; _offset = intervalOffset; - _currentSimulation = new SpringSimulation( - _springDesc, position, _leadingExtent, velocity); + _currentSimulation = new SpringSimulation(_spring, position, _leadingExtent, velocity); return true; } } diff --git a/packages/newton/test/newton_test.dart b/packages/newton/test/newton_test.dart index 44c8050114..a70a9c7242 100644 --- a/packages/newton/test/newton_test.dart +++ b/packages/newton/test/newton_test.dart @@ -168,7 +168,6 @@ void main() { var scroll = new ScrollSimulation(100.0, 400.0, 0.0, double.INFINITY, spring, 0.3); - scroll.tolerance = const Tolerance(velocity: 1.0); expect(scroll.isDone(0.0), false);