Merge m-c to inbound.
[gecko.git] / gfx / thebes / gfxPoint.h
blobd311c7f64209b25820337f612435946f9a260562
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/. */
6 #ifndef GFX_POINT_H
7 #define GFX_POINT_H
9 #include "nsMathUtils.h"
10 #include "mozilla/gfx/BaseSize.h"
11 #include "mozilla/gfx/BasePoint.h"
12 #include "nsSize.h"
13 #include "nsPoint.h"
15 #include "gfxTypes.h"
17 struct gfxSize : public mozilla::gfx::BaseSize<gfxFloat, gfxSize> {
18 typedef mozilla::gfx::BaseSize<gfxFloat, gfxSize> Super;
20 gfxSize() : Super() {}
21 gfxSize(gfxFloat aWidth, gfxFloat aHeight) : Super(aWidth, aHeight) {}
22 gfxSize(const nsIntSize& aSize) : Super(aSize.width, aSize.height) {}
25 struct gfxPoint : public mozilla::gfx::BasePoint<gfxFloat, gfxPoint> {
26 typedef mozilla::gfx::BasePoint<gfxFloat, gfxPoint> Super;
28 gfxPoint() : Super() {}
29 gfxPoint(gfxFloat aX, gfxFloat aY) : Super(aX, aY) {}
30 gfxPoint(const nsIntPoint& aPoint) : Super(aPoint.x, aPoint.y) {}
32 // Round() is *not* rounding to nearest integer if the values are negative.
33 // They are always rounding as floor(n + 0.5).
34 // See https://bugzilla.mozilla.org/show_bug.cgi?id=410748#c14
35 gfxPoint& Round() {
36 x = floor(x + 0.5);
37 y = floor(y + 0.5);
38 return *this;
41 bool WithinEpsilonOf(const gfxPoint& aPoint, gfxFloat aEpsilon) {
42 return fabs(aPoint.x - x) < aEpsilon && fabs(aPoint.y - y) < aEpsilon;
46 inline gfxPoint
47 operator*(const gfxPoint& aPoint, const gfxSize& aSize)
49 return gfxPoint(aPoint.x * aSize.width, aPoint.y * aSize.height);
52 inline gfxPoint
53 operator/(const gfxPoint& aPoint, const gfxSize& aSize)
55 return gfxPoint(aPoint.x / aSize.width, aPoint.y / aSize.height);
58 inline gfxSize
59 operator/(gfxFloat aValue, const gfxSize& aSize)
61 return gfxSize(aValue / aSize.width, aValue / aSize.height);
64 #endif /* GFX_POINT_H */