gfx/thebes/gfxRect.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxRect.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "gfxRect.h"
    1.10 +
    1.11 +#include "nsMathUtils.h"
    1.12 +
    1.13 +static bool
    1.14 +WithinEpsilonOfInteger(gfxFloat aX, gfxFloat aEpsilon)
    1.15 +{
    1.16 +    return fabs(NS_round(aX) - aX) <= fabs(aEpsilon);
    1.17 +}
    1.18 +
    1.19 +bool
    1.20 +gfxRect::WithinEpsilonOfIntegerPixels(gfxFloat aEpsilon) const
    1.21 +{
    1.22 +    NS_ASSERTION(-0.5 < aEpsilon && aEpsilon < 0.5, "Nonsense epsilon value");
    1.23 +    return (WithinEpsilonOfInteger(x, aEpsilon) &&
    1.24 +            WithinEpsilonOfInteger(y, aEpsilon) &&
    1.25 +            WithinEpsilonOfInteger(width, aEpsilon) &&
    1.26 +            WithinEpsilonOfInteger(height, aEpsilon));
    1.27 +}
    1.28 +
    1.29 +/* Clamp r to CAIRO_COORD_MIN .. CAIRO_COORD_MAX
    1.30 + * these are to be device coordinates.
    1.31 + *
    1.32 + * Cairo is currently using 24.8 fixed point,
    1.33 + * so -2^24 .. 2^24-1 is our valid
    1.34 + */
    1.35 +
    1.36 +#define CAIRO_COORD_MAX (16777215.0)
    1.37 +#define CAIRO_COORD_MIN (-16777216.0)
    1.38 +
    1.39 +void
    1.40 +gfxRect::Condition()
    1.41 +{
    1.42 +    // if either x or y is way out of bounds;
    1.43 +    // note that we don't handle negative w/h here
    1.44 +    if (x > CAIRO_COORD_MAX) {
    1.45 +        x = CAIRO_COORD_MAX;
    1.46 +        width = 0.0;
    1.47 +    } 
    1.48 +
    1.49 +    if (y > CAIRO_COORD_MAX) {
    1.50 +        y = CAIRO_COORD_MAX;
    1.51 +        height = 0.0;
    1.52 +    }
    1.53 +
    1.54 +    if (x < CAIRO_COORD_MIN) {
    1.55 +        width += x - CAIRO_COORD_MIN;
    1.56 +        if (width < 0.0)
    1.57 +            width = 0.0;
    1.58 +        x = CAIRO_COORD_MIN;
    1.59 +    }
    1.60 +
    1.61 +    if (y < CAIRO_COORD_MIN) {
    1.62 +        height += y - CAIRO_COORD_MIN;
    1.63 +        if (height < 0.0)
    1.64 +            height = 0.0;
    1.65 +        y = CAIRO_COORD_MIN;
    1.66 +    }
    1.67 +
    1.68 +    if (x + width > CAIRO_COORD_MAX) {
    1.69 +        width = CAIRO_COORD_MAX - x;
    1.70 +    }
    1.71 +
    1.72 +    if (y + height > CAIRO_COORD_MAX) {
    1.73 +        height = CAIRO_COORD_MAX - y;
    1.74 +    }
    1.75 +}
    1.76 +

mercurial