Bumping manifests a=b2g-bump
[gecko.git] / gfx / thebes / gfxRect.cpp
blobeb7993352507db4d108fccb09cf853a009b72f24
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "gfxRect.h"
8 #include "nsMathUtils.h"
10 static bool
11 WithinEpsilonOfInteger(gfxFloat aX, gfxFloat aEpsilon)
13 return fabs(NS_round(aX) - aX) <= fabs(aEpsilon);
16 bool
17 gfxRect::WithinEpsilonOfIntegerPixels(gfxFloat aEpsilon) const
19 NS_ASSERTION(-0.5 < aEpsilon && aEpsilon < 0.5, "Nonsense epsilon value");
20 return (WithinEpsilonOfInteger(x, aEpsilon) &&
21 WithinEpsilonOfInteger(y, aEpsilon) &&
22 WithinEpsilonOfInteger(width, aEpsilon) &&
23 WithinEpsilonOfInteger(height, aEpsilon));
26 /* Clamp r to CAIRO_COORD_MIN .. CAIRO_COORD_MAX
27 * these are to be device coordinates.
29 * Cairo is currently using 24.8 fixed point,
30 * so -2^24 .. 2^24-1 is our valid
33 #define CAIRO_COORD_MAX (16777215.0)
34 #define CAIRO_COORD_MIN (-16777216.0)
36 void
37 gfxRect::Condition()
39 // if either x or y is way out of bounds;
40 // note that we don't handle negative w/h here
41 if (x > CAIRO_COORD_MAX) {
42 x = CAIRO_COORD_MAX;
43 width = 0.0;
46 if (y > CAIRO_COORD_MAX) {
47 y = CAIRO_COORD_MAX;
48 height = 0.0;
51 if (x < CAIRO_COORD_MIN) {
52 width += x - CAIRO_COORD_MIN;
53 if (width < 0.0)
54 width = 0.0;
55 x = CAIRO_COORD_MIN;
58 if (y < CAIRO_COORD_MIN) {
59 height += y - CAIRO_COORD_MIN;
60 if (height < 0.0)
61 height = 0.0;
62 y = CAIRO_COORD_MIN;
65 if (x + width > CAIRO_COORD_MAX) {
66 width = CAIRO_COORD_MAX - x;
69 if (y + height > CAIRO_COORD_MAX) {
70 height = CAIRO_COORD_MAX - y;