No new functionality, just some gratuitous changes.
This commit is contained in:
@@ -3,3 +3,7 @@
|
||||
[](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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user