diff --git a/gfx/layers/apz/src/AsyncPanZoomController.cpp b/gfx/layers/apz/src/AsyncPanZoomController.cpp index 961b5740ae87..f7512aa223b1 100644 --- a/gfx/layers/apz/src/AsyncPanZoomController.cpp +++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp @@ -372,8 +372,8 @@ static bool IsCloseToVertical(float aAngle, float aThreshold) template static bool IsZero(const gfx::PointTyped& aPoint) { - return FuzzyEqualsMultiplicative(aPoint.x, 0.0f) - && FuzzyEqualsMultiplicative(aPoint.y, 0.0f); + return FuzzyEqualsAdditive(aPoint.x, 0.0f) + && FuzzyEqualsAdditive(aPoint.y, 0.0f); } static inline void LogRendertraceRect(const ScrollableLayerGuid& aGuid, const char* aDesc, const char* aColor, const CSSRect& aRect) diff --git a/gfx/layers/apz/src/Axis.cpp b/gfx/layers/apz/src/Axis.cpp index 8ee45cb367b9..d0c686032445 100644 --- a/gfx/layers/apz/src/Axis.cpp +++ b/gfx/layers/apz/src/Axis.cpp @@ -30,6 +30,12 @@ namespace mozilla { namespace layers { +bool FuzzyEqualsCoordinate(float aValue1, float aValue2) +{ + return FuzzyEqualsAdditive(aValue1, aValue2, COORDINATE_EPSILON) + || FuzzyEqualsMultiplicative(aValue1, aValue2); +} + extern StaticAutoPtr gVelocityCurveFunction; Axis::Axis(AsyncPanZoomController* aAsyncPanZoomController) @@ -180,8 +186,8 @@ void Axis::OverscrollBy(ParentLayerCoord aOverscroll) { aOverscroll = ApplyResistance(aOverscroll); if (aOverscroll > 0) { #ifdef DEBUG - if (!FuzzyEqualsAdditive(GetCompositionEnd().value, GetPageEnd().value, COORDINATE_EPSILON)) { - nsPrintfCString message("composition end (%f) is not within COORDINATE_EPISLON of page end (%f)\n", + if (!FuzzyEqualsCoordinate(GetCompositionEnd().value, GetPageEnd().value)) { + nsPrintfCString message("composition end (%f) is not equal (within error) to page end (%f)\n", GetCompositionEnd().value, GetPageEnd().value); NS_ASSERTION(false, message.get()); MOZ_CRASH(); @@ -190,8 +196,8 @@ void Axis::OverscrollBy(ParentLayerCoord aOverscroll) { MOZ_ASSERT(mOverscroll >= 0); } else if (aOverscroll < 0) { #ifdef DEBUG - if (!FuzzyEqualsAdditive(GetOrigin().value, GetPageStart().value, COORDINATE_EPSILON)) { - nsPrintfCString message("composition origin (%f) is not within COORDINATE_EPISLON of page origin (%f)\n", + if (!FuzzyEqualsCoordinate(GetOrigin().value, GetPageStart().value)) { + nsPrintfCString message("composition origin (%f) is not equal (within error) to page origin (%f)\n", GetOrigin().value, GetPageStart().value); NS_ASSERTION(false, message.get()); MOZ_CRASH(); diff --git a/gfx/layers/apz/src/Axis.h b/gfx/layers/apz/src/Axis.h index d566a8583baa..299eda1e3fb1 100644 --- a/gfx/layers/apz/src/Axis.h +++ b/gfx/layers/apz/src/Axis.h @@ -25,6 +25,16 @@ const float EPSILON = 0.0001f; // isn't too large. const float COORDINATE_EPSILON = 0.01f; +/** + * Compare two coordinates for equality, accounting for rounding error. + * Use both FuzzyEqualsAdditive() with COORDINATE_EPISLON, which accounts for + * things like the error introduced by rounding during a round-trip to app + * units, and FuzzyEqualsMultiplicative(), which accounts for accumulated error + * due to floating-point operations (which can be larger than COORDINATE_EPISLON + * for sufficiently large coordinate values). + */ +bool FuzzyEqualsCoordinate(float aValue1, float aValue2); + struct FrameMetrics; class AsyncPanZoomController;