1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Novell code.
16 : *
17 : * The Initial Developer of the Original Code is Novell Corporation.
18 : * Portions created by the Initial Developer are Copyright (C) 2006
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Robert O'Callahan (rocallahan@novell.com)
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "gfxRect.h"
39 :
40 : #include "nsMathUtils.h"
41 :
42 : static bool
43 0 : WithinEpsilonOfInteger(gfxFloat aX, gfxFloat aEpsilon)
44 : {
45 0 : return fabs(NS_round(aX) - aX) <= fabs(aEpsilon);
46 : }
47 :
48 : bool
49 0 : gfxRect::WithinEpsilonOfIntegerPixels(gfxFloat aEpsilon) const
50 : {
51 0 : NS_ASSERTION(-0.5 < aEpsilon && aEpsilon < 0.5, "Nonsense epsilon value");
52 0 : return (WithinEpsilonOfInteger(x, aEpsilon) &&
53 0 : WithinEpsilonOfInteger(y, aEpsilon) &&
54 0 : WithinEpsilonOfInteger(width, aEpsilon) &&
55 0 : WithinEpsilonOfInteger(height, aEpsilon));
56 : }
57 :
58 : /* Clamp r to CAIRO_COORD_MIN .. CAIRO_COORD_MAX
59 : * these are to be device coordinates.
60 : *
61 : * Cairo is currently using 24.8 fixed point,
62 : * so -2^24 .. 2^24-1 is our valid
63 : */
64 :
65 : #define CAIRO_COORD_MAX (16777215.0)
66 : #define CAIRO_COORD_MIN (-16777216.0)
67 :
68 : void
69 0 : gfxRect::Condition()
70 : {
71 : // if either x or y is way out of bounds;
72 : // note that we don't handle negative w/h here
73 0 : if (x > CAIRO_COORD_MAX) {
74 0 : x = CAIRO_COORD_MAX;
75 0 : width = 0.0;
76 : }
77 :
78 0 : if (y > CAIRO_COORD_MAX) {
79 0 : y = CAIRO_COORD_MAX;
80 0 : height = 0.0;
81 : }
82 :
83 0 : if (x < CAIRO_COORD_MIN) {
84 0 : width += x - CAIRO_COORD_MIN;
85 0 : if (width < 0.0)
86 0 : width = 0.0;
87 0 : x = CAIRO_COORD_MIN;
88 : }
89 :
90 0 : if (y < CAIRO_COORD_MIN) {
91 0 : height += y - CAIRO_COORD_MIN;
92 0 : if (height < 0.0)
93 0 : height = 0.0;
94 0 : y = CAIRO_COORD_MIN;
95 : }
96 :
97 0 : if (x + width > CAIRO_COORD_MAX) {
98 0 : width = CAIRO_COORD_MAX - x;
99 : }
100 :
101 0 : if (y + height > CAIRO_COORD_MAX) {
102 0 : height = CAIRO_COORD_MAX - y;
103 : }
104 0 : }
|