Bug 1145345 - Account for a greater variety of rounding errors when comparing coordinates. r=kats

--HG--
extra : source : af3b6caa84116a5f95783ed9262326f4917b6b90
This commit is contained in:
Botond Ballo 2015-03-20 14:02:07 -04:00
Родитель 3b412c43dd
Коммит 9bef23d187
3 изменённых файлов: 22 добавлений и 6 удалений

Просмотреть файл

@ -372,8 +372,8 @@ static bool IsCloseToVertical(float aAngle, float aThreshold)
template <typename Units>
static bool IsZero(const gfx::PointTyped<Units>& 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)

Просмотреть файл

@ -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<ComputedTimingFunction> 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();

Просмотреть файл

@ -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;