michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "gfxRect.h" michael@0: michael@0: #include "nsMathUtils.h" michael@0: michael@0: static bool michael@0: WithinEpsilonOfInteger(gfxFloat aX, gfxFloat aEpsilon) michael@0: { michael@0: return fabs(NS_round(aX) - aX) <= fabs(aEpsilon); michael@0: } michael@0: michael@0: bool michael@0: gfxRect::WithinEpsilonOfIntegerPixels(gfxFloat aEpsilon) const michael@0: { michael@0: NS_ASSERTION(-0.5 < aEpsilon && aEpsilon < 0.5, "Nonsense epsilon value"); michael@0: return (WithinEpsilonOfInteger(x, aEpsilon) && michael@0: WithinEpsilonOfInteger(y, aEpsilon) && michael@0: WithinEpsilonOfInteger(width, aEpsilon) && michael@0: WithinEpsilonOfInteger(height, aEpsilon)); michael@0: } michael@0: michael@0: /* Clamp r to CAIRO_COORD_MIN .. CAIRO_COORD_MAX michael@0: * these are to be device coordinates. michael@0: * michael@0: * Cairo is currently using 24.8 fixed point, michael@0: * so -2^24 .. 2^24-1 is our valid michael@0: */ michael@0: michael@0: #define CAIRO_COORD_MAX (16777215.0) michael@0: #define CAIRO_COORD_MIN (-16777216.0) michael@0: michael@0: void michael@0: gfxRect::Condition() michael@0: { michael@0: // if either x or y is way out of bounds; michael@0: // note that we don't handle negative w/h here michael@0: if (x > CAIRO_COORD_MAX) { michael@0: x = CAIRO_COORD_MAX; michael@0: width = 0.0; michael@0: } michael@0: michael@0: if (y > CAIRO_COORD_MAX) { michael@0: y = CAIRO_COORD_MAX; michael@0: height = 0.0; michael@0: } michael@0: michael@0: if (x < CAIRO_COORD_MIN) { michael@0: width += x - CAIRO_COORD_MIN; michael@0: if (width < 0.0) michael@0: width = 0.0; michael@0: x = CAIRO_COORD_MIN; michael@0: } michael@0: michael@0: if (y < CAIRO_COORD_MIN) { michael@0: height += y - CAIRO_COORD_MIN; michael@0: if (height < 0.0) michael@0: height = 0.0; michael@0: y = CAIRO_COORD_MIN; michael@0: } michael@0: michael@0: if (x + width > CAIRO_COORD_MAX) { michael@0: width = CAIRO_COORD_MAX - x; michael@0: } michael@0: michael@0: if (y + height > CAIRO_COORD_MAX) { michael@0: height = CAIRO_COORD_MAX - y; michael@0: } michael@0: } michael@0: