diff --git a/packages/newton/lib/newton.dart b/packages/newton/lib/newton.dart index 744fe3135f..03eaa834b4 100644 --- a/packages/newton/lib/newton.dart +++ b/packages/newton/lib/newton.dart @@ -10,8 +10,8 @@ part 'src/simulation.dart'; part 'src/simulation_group.dart'; part 'src/utils.dart'; -part 'src/friction.dart'; -part 'src/gravity.dart'; -part 'src/scroll.dart'; -part 'src/spring.dart'; +part 'src/friction_simulation.dart'; +part 'src/gravity_simulation.dart'; +part 'src/scroll_simulation.dart'; +part 'src/spring_simulation.dart'; part 'src/spring_solution.dart'; diff --git a/packages/newton/lib/src/friction.dart b/packages/newton/lib/src/friction_simulation.dart similarity index 65% rename from packages/newton/lib/src/friction.dart rename to packages/newton/lib/src/friction_simulation.dart index a055ac7d03..3916456e2d 100644 --- a/packages/newton/lib/src/friction.dart +++ b/packages/newton/lib/src/friction_simulation.dart @@ -4,20 +4,20 @@ part of newton; -class Friction extends Simulation { +class FrictionSimulation extends Simulation { final double _drag; - final double _dragNaturalLog; + final double _dragLog; final double _x; final double _v; - Friction(double drag, double position, double velocity) + FrictionSimulation(double drag, double position, double velocity) : _drag = drag, - _dragNaturalLog = Math.log(drag), + _dragLog = Math.log(drag), _x = position, _v = velocity; double x(double time) => - _x + _v * Math.pow(_drag, time) / _dragNaturalLog - _v / _dragNaturalLog; + _x + _v * Math.pow(_drag, time) / _dragLog - _v / _dragLog; double dx(double time) => _v * Math.pow(_drag, time); diff --git a/packages/newton/lib/src/gravity.dart b/packages/newton/lib/src/gravity_simulation.dart similarity index 90% rename from packages/newton/lib/src/gravity.dart rename to packages/newton/lib/src/gravity_simulation.dart index 4eb11f69d4..2f002b74e0 100644 --- a/packages/newton/lib/src/gravity.dart +++ b/packages/newton/lib/src/gravity_simulation.dart @@ -4,13 +4,13 @@ part of newton; -class Gravity extends Simulation { +class GravitySimulation extends Simulation { final double _x; final double _v; final double _a; final double _end; - Gravity( + GravitySimulation( double acceleration, double distance, double endDistance, double velocity) : _a = acceleration, _x = distance, diff --git a/packages/newton/lib/src/scroll.dart b/packages/newton/lib/src/scroll_simulation.dart similarity index 76% rename from packages/newton/lib/src/scroll.dart rename to packages/newton/lib/src/scroll_simulation.dart index 4b57b9f0af..a1f7d59fb5 100644 --- a/packages/newton/lib/src/scroll.dart +++ b/packages/newton/lib/src/scroll_simulation.dart @@ -7,7 +7,7 @@ part of newton; /// Simulates kinetic scrolling behavior between a leading and trailing /// boundary. Friction is applied within the extends and a spring action applied /// at the boundaries. This simulation can only step forward. -class Scroll extends SimulationGroup { +class ScrollSimulation extends SimulationGroup { final double _leadingExtent; final double _trailingExtent; final SpringDesc _springDesc; @@ -17,8 +17,8 @@ class Scroll extends SimulationGroup { Simulation _currentSimulation; double _offset = 0.0; - Scroll(double position, double velocity, double leading, double trailing, - SpringDesc spring, double drag) + ScrollSimulation(double position, double velocity, double leading, + double trailing, SpringDesc spring, double drag) : _leadingExtent = leading, _trailingExtent = trailing, _springDesc = spring, @@ -45,20 +45,20 @@ class Scroll extends SimulationGroup { if (position > _trailingExtent) { _isSpringing = true; _offset = intervalOffset; - _currentSimulation = - new Spring(_springDesc, position, _trailingExtent, velocity); + _currentSimulation = new SpringSimulation( + _springDesc, position, _trailingExtent, velocity); return; } else if (position < _leadingExtent) { _isSpringing = true; _offset = intervalOffset; - _currentSimulation = - new Spring(_springDesc, position, _leadingExtent, velocity); + _currentSimulation = new SpringSimulation( + _springDesc, position, _leadingExtent, velocity); return; } } if (_currentSimulation == null) { - _currentSimulation = new Friction(_drag, position, velocity); + _currentSimulation = new FrictionSimulation(_drag, position, velocity); return; } } diff --git a/packages/newton/lib/src/spring.dart b/packages/newton/lib/src/spring_simulation.dart similarity index 93% rename from packages/newton/lib/src/spring.dart rename to packages/newton/lib/src/spring_simulation.dart index bda8242d20..9d80bf094d 100644 --- a/packages/newton/lib/src/spring.dart +++ b/packages/newton/lib/src/spring_simulation.dart @@ -32,14 +32,14 @@ enum SpringType { unknown, criticallyDamped, underDamped, overDamped, } /// Creates a spring simulation. Depending on the spring description, a /// critically, under or overdamped spring will be created. -class Spring extends Simulation { +class SpringSimulation extends Simulation { final double _endPosition; final _SpringSolution _solution; /// A spring description with the provided spring description, start distance, /// end distance and velocity. - Spring(SpringDesc desc, double start, double end, double velocity) + SpringSimulation(SpringDesc desc, double start, double end, double velocity) : this._endPosition = end, _solution = new _SpringSolution(desc, start - end, velocity); diff --git a/packages/newton/test/newton_test.dart b/packages/newton/test/newton_test.dart index a568848eab..275aa81ca6 100644 --- a/packages/newton/test/newton_test.dart +++ b/packages/newton/test/newton_test.dart @@ -10,7 +10,7 @@ import 'package:newton/newton.dart'; void main() { test('test_friction', () { - var friction = new Friction(0.3, 100.0, 400.0); + var friction = new FrictionSimulation(0.3, 100.0, 400.0); expect(friction.isDone(0.0), false); expect(friction.x(0.0), 100); @@ -28,7 +28,7 @@ void main() { }); test('test_gravity', () { - var gravity = new Gravity(200.0, 100.0, 600.0, 0.0); + var gravity = new GravitySimulation(200.0, 100.0, 600.0, 0.0); expect(gravity.isDone(0.0), false); expect(gravity.x(0.0), 100.0); @@ -58,25 +58,26 @@ void main() { }); test('spring_types', () { - var crit = new Spring( + var crit = new SpringSimulation( new SpringDesc.withDampingRatio(1.0, 100.0, 1.0), 0.0, 300.0, 0.0); expect(crit.type, SpringType.criticallyDamped); - var under = new Spring( + var under = new SpringSimulation( new SpringDesc.withDampingRatio(1.0, 100.0, 0.75), 0.0, 300.0, 0.0); expect(under.type, SpringType.underDamped); - var over = new Spring( + var over = new SpringSimulation( new SpringDesc.withDampingRatio(1.0, 100.0, 1.25), 0.0, 300.0, 0.0); expect(over.type, SpringType.overDamped); // Just so we don't forget how to create a desc without the ratio. - var other = new Spring(new SpringDesc(1.0, 100.0, 20.0), 0.0, 20.0, 20.0); + var other = + new SpringSimulation(new SpringDesc(1.0, 100.0, 20.0), 0.0, 20.0, 20.0); expect(other.type, SpringType.criticallyDamped); }); test('crit_spring', () { - var crit = new Spring( + var crit = new SpringSimulation( new SpringDesc.withDampingRatio(1.0, 100.0, 1.0), 0.0, 500.0, 0.0); expect(crit.type, SpringType.criticallyDamped); @@ -98,7 +99,7 @@ void main() { }); test('overdamped_spring', () { - var over = new Spring( + var over = new SpringSimulation( new SpringDesc.withDampingRatio(1.0, 100.0, 1.25), 0.0, 500.0, 0.0); expect(over.type, SpringType.overDamped); @@ -117,7 +118,7 @@ void main() { }); test('underdamped_spring', () { - var under = new Spring( + var under = new SpringSimulation( new SpringDesc.withDampingRatio(1.0, 100.0, 0.25), 0.0, 300.0, 0.0); expect(under.type, SpringType.underDamped); @@ -136,12 +137,12 @@ void main() { test('test_kinetic_scroll', () { var spring = new SpringDesc.withDampingRatio(1.0, 50.0, 0.5); - var scroll = new Scroll(100.0, 800.0, 0.0, 300.0, spring, 0.3); + var scroll = new ScrollSimulation(100.0, 800.0, 0.0, 300.0, spring, 0.3); expect(scroll.isDone(0.0), false); expect(scroll.isDone(3.5), true); - var scroll2 = new Scroll(100.0, -800.0, 0.0, 300.0, spring, 0.3); + var scroll2 = new ScrollSimulation(100.0, -800.0, 0.0, 300.0, spring, 0.3); expect(scroll2.isDone(4.5), true); }); }