gfx/thebes/gfxPoint.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxPoint.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     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 +#ifndef GFX_POINT_H
    1.10 +#define GFX_POINT_H
    1.11 +
    1.12 +#include "nsMathUtils.h"
    1.13 +#include "mozilla/gfx/BaseSize.h"
    1.14 +#include "mozilla/gfx/BasePoint.h"
    1.15 +#include "nsSize.h"
    1.16 +#include "nsPoint.h"
    1.17 +
    1.18 +#include "gfxTypes.h"
    1.19 +
    1.20 +struct gfxSize : public mozilla::gfx::BaseSize<gfxFloat, gfxSize> {
    1.21 +    typedef mozilla::gfx::BaseSize<gfxFloat, gfxSize> Super;
    1.22 +
    1.23 +    gfxSize() : Super() {}
    1.24 +    gfxSize(gfxFloat aWidth, gfxFloat aHeight) : Super(aWidth, aHeight) {}
    1.25 +    gfxSize(const nsIntSize& aSize) : Super(aSize.width, aSize.height) {}
    1.26 +};
    1.27 +
    1.28 +struct gfxPoint : public mozilla::gfx::BasePoint<gfxFloat, gfxPoint> {
    1.29 +    typedef mozilla::gfx::BasePoint<gfxFloat, gfxPoint> Super;
    1.30 +
    1.31 +    gfxPoint() : Super() {}
    1.32 +    gfxPoint(gfxFloat aX, gfxFloat aY) : Super(aX, aY) {}
    1.33 +    gfxPoint(const nsIntPoint& aPoint) : Super(aPoint.x, aPoint.y) {}
    1.34 +
    1.35 +    bool WithinEpsilonOf(const gfxPoint& aPoint, gfxFloat aEpsilon) {
    1.36 +        return fabs(aPoint.x - x) < aEpsilon && fabs(aPoint.y - y) < aEpsilon;
    1.37 +    }
    1.38 +};
    1.39 +
    1.40 +inline gfxPoint
    1.41 +operator*(const gfxPoint& aPoint, const gfxSize& aSize)
    1.42 +{
    1.43 +  return gfxPoint(aPoint.x * aSize.width, aPoint.y * aSize.height);
    1.44 +}
    1.45 +
    1.46 +inline gfxPoint
    1.47 +operator/(const gfxPoint& aPoint, const gfxSize& aSize)
    1.48 +{
    1.49 +  return gfxPoint(aPoint.x / aSize.width, aPoint.y / aSize.height);
    1.50 +}
    1.51 +
    1.52 +inline gfxSize
    1.53 +operator/(gfxFloat aValue, const gfxSize& aSize)
    1.54 +{
    1.55 +  return gfxSize(aValue / aSize.width, aValue / aSize.height);
    1.56 +}
    1.57 +
    1.58 +#endif /* GFX_POINT_H */

mercurial