Commit eaa72f6e authored by Hans Muller's avatar Hans Muller

No new functionality, just some gratuitous changes.

parent 32ff3e59
...@@ -3,3 +3,7 @@ ...@@ -3,3 +3,7 @@
[![Coverage Status](https://coveralls.io/repos/domokit/newton/badge.svg?branch=master)](https://coveralls.io/r/domokit/newton?branch=master) [![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. Simple Physics Simulations for Dart. Springs, friction, gravity, etc.
To run the tests:
pub get
dart test/newton_test.dart
...@@ -8,24 +8,25 @@ part of newton; ...@@ -8,24 +8,25 @@ part of newton;
/// boundary. Friction is applied within the extends and a spring action applied /// boundary. Friction is applied within the extends and a spring action applied
/// at the boundaries. This simulation can only step forward. /// at the boundaries. This simulation can only step forward.
class ScrollSimulation extends SimulationGroup { 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 _leadingExtent;
final double _trailingExtent; final double _trailingExtent;
final SpringDescription _springDesc; final SpringDescription _spring;
final double _drag; final double _drag;
bool _isSpringing = false; bool _isSpringing = false;
Simulation _currentSimulation; Simulation _currentSimulation;
double _offset = 0.0; 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 @override
bool step(double time) => _chooseSimulation( bool step(double time) => _chooseSimulation(
_currentSimulation.x(time - _offset), _currentSimulation.x(time - _offset),
...@@ -37,11 +38,8 @@ class ScrollSimulation extends SimulationGroup { ...@@ -37,11 +38,8 @@ class ScrollSimulation extends SimulationGroup {
@override @override
double get currentIntervalOffset => _offset; double get currentIntervalOffset => _offset;
bool _chooseSimulation( bool _chooseSimulation(double position, double velocity, double intervalOffset) {
double position, double velocity, double intervalOffset) { if (_spring == null && (position > _trailingExtent || position < _leadingExtent))
if (_springDesc == null &&
(position > _trailingExtent || position < _leadingExtent))
return false; return false;
/// This simulation can only step forward. /// This simulation can only step forward.
...@@ -49,14 +47,12 @@ class ScrollSimulation extends SimulationGroup { ...@@ -49,14 +47,12 @@ class ScrollSimulation extends SimulationGroup {
if (position > _trailingExtent) { if (position > _trailingExtent) {
_isSpringing = true; _isSpringing = true;
_offset = intervalOffset; _offset = intervalOffset;
_currentSimulation = new SpringSimulation( _currentSimulation = new SpringSimulation(_spring, position, _trailingExtent, velocity);
_springDesc, position, _trailingExtent, velocity);
return true; return true;
} else if (position < _leadingExtent) { } else if (position < _leadingExtent) {
_isSpringing = true; _isSpringing = true;
_offset = intervalOffset; _offset = intervalOffset;
_currentSimulation = new SpringSimulation( _currentSimulation = new SpringSimulation(_spring, position, _leadingExtent, velocity);
_springDesc, position, _leadingExtent, velocity);
return true; return true;
} }
} }
......
...@@ -168,7 +168,6 @@ void main() { ...@@ -168,7 +168,6 @@ void main() {
var scroll = var scroll =
new ScrollSimulation(100.0, 400.0, 0.0, double.INFINITY, spring, 0.3); new ScrollSimulation(100.0, 400.0, 0.0, double.INFINITY, spring, 0.3);
scroll.tolerance = const Tolerance(velocity: 1.0); scroll.tolerance = const Tolerance(velocity: 1.0);
expect(scroll.isDone(0.0), false); expect(scroll.isDone(0.0), false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment