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/. */
8 #include "nsMathUtils.h"
11 WithinEpsilonOfInteger(gfxFloat aX
, gfxFloat aEpsilon
)
13 return fabs(NS_round(aX
) - aX
) <= fabs(aEpsilon
);
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)
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
) {
46 if (y
> CAIRO_COORD_MAX
) {
51 if (x
< CAIRO_COORD_MIN
) {
52 width
+= x
- CAIRO_COORD_MIN
;
58 if (y
< CAIRO_COORD_MIN
) {
59 height
+= 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
;