Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Unified Diff: sky/framework/animation/mechanics.dart

Issue 1097373002: [Effen] Prevent scrolling past the bottom of a scrollable list. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Move the creation of the OverscrollBehavior class to FixedHeightScrollable, since we already assumeā€¦ Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/framework/animation/mechanics.dart
diff --git a/sky/framework/animation/mechanics.dart b/sky/framework/animation/mechanics.dart
index d946917248db46757a25298c97288232f63db5be..6a6cc4cad46f7f8c744afe9cd8ac06757e5ba1a8 100644
--- a/sky/framework/animation/mechanics.dart
+++ b/sky/framework/animation/mechanics.dart
@@ -25,10 +25,10 @@ class Particle extends System {
position += velocity * deltaT;
}
- double get energy => 0.5 * mass * velocity * velocity;
- set energy(double e) { // J
- assert(e >= 0.0);
- velocity = math.sqrt(2.0 * e / mass);
+ void setVelocityFromEnergy({double energy, double direction}) {
eseidel 2015/04/21 19:52:33 Why the {}? Doesn't that make them optional named
Hixie 2015/04/21 20:18:52 It makes them named, yes. (They're always "optiona
+ assert(direction == -1.0 || direction == 1.0);
+ assert(energy >= 0.0);
+ velocity = math.sqrt(2.0 * energy / mass) * direction;
}
}
@@ -174,7 +174,10 @@ class ParticleClimbingRamp extends System {
// potential energy at the top of the slope, which is g*h*m.
// If the slope's horizontal component is delta P long, then
// the height is delta P times tan theta.
- particle.energy = -kGravity * (deltaPosition * tanTheta) * particle.mass;
+ particle.setVelocityFromEnergy(
+ energy: (kGravity * (deltaPosition * tanTheta) * particle.mass).abs(),
+ direction: deltaPosition > 0.0 ? 1.0 : -1.0
+ );
box.confine(particle);
}

Powered by Google App Engine
This is Rietveld 408576698