Bug 702412 - Fix float comparisons to use an epsilon [r=pcwalton]

This commit is contained in:
Kartikaya Gupta 2011-11-17 14:43:28 -05:00
parent f3c449c527
commit 2be53983e3

View File

@ -335,6 +335,11 @@ public class PanZoomController
return 1.0f - excess / (viewportLength * SNAP_LIMIT);
}
private static boolean floatsApproxEqual(float a, float b) {
// account for floating point rounding errors
return Math.abs(a - b) < 1e-6;
}
// Physics information for one axis (X or Y).
private static class Axis {
public enum FlingStates {
@ -408,7 +413,7 @@ public class PanZoomController
}
float excess = getExcess();
if (excess == 0.0f)
if (floatsApproxEqual(excess, 0.0f))
mFlingState = FlingStates.STOPPED;
else
mFlingState = FlingStates.WAITING_TO_SNAP;
@ -433,7 +438,7 @@ public class PanZoomController
private void scroll() {
// If we aren't overscrolled, just apply friction.
float excess = getExcess();
if (excess == 0.0f) {
if (floatsApproxEqual(excess, 0.0f)) {
velocity *= FRICTION;
if (Math.abs(velocity) < 0.1f) {
velocity = 0.0f;