|
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/. */ |
|
5 |
|
6 #include "gfxRect.h" |
|
7 |
|
8 #include "nsMathUtils.h" |
|
9 |
|
10 static bool |
|
11 WithinEpsilonOfInteger(gfxFloat aX, gfxFloat aEpsilon) |
|
12 { |
|
13 return fabs(NS_round(aX) - aX) <= fabs(aEpsilon); |
|
14 } |
|
15 |
|
16 bool |
|
17 gfxRect::WithinEpsilonOfIntegerPixels(gfxFloat aEpsilon) const |
|
18 { |
|
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)); |
|
24 } |
|
25 |
|
26 /* Clamp r to CAIRO_COORD_MIN .. CAIRO_COORD_MAX |
|
27 * these are to be device coordinates. |
|
28 * |
|
29 * Cairo is currently using 24.8 fixed point, |
|
30 * so -2^24 .. 2^24-1 is our valid |
|
31 */ |
|
32 |
|
33 #define CAIRO_COORD_MAX (16777215.0) |
|
34 #define CAIRO_COORD_MIN (-16777216.0) |
|
35 |
|
36 void |
|
37 gfxRect::Condition() |
|
38 { |
|
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; |
|
44 } |
|
45 |
|
46 if (y > CAIRO_COORD_MAX) { |
|
47 y = CAIRO_COORD_MAX; |
|
48 height = 0.0; |
|
49 } |
|
50 |
|
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; |
|
56 } |
|
57 |
|
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; |
|
63 } |
|
64 |
|
65 if (x + width > CAIRO_COORD_MAX) { |
|
66 width = CAIRO_COORD_MAX - x; |
|
67 } |
|
68 |
|
69 if (y + height > CAIRO_COORD_MAX) { |
|
70 height = CAIRO_COORD_MAX - y; |
|
71 } |
|
72 } |
|
73 |