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/. */
9 #include "nsMathUtils.h"
10 #include "mozilla/gfx/BaseSize.h"
11 #include "mozilla/gfx/BasePoint.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
41 bool WithinEpsilonOf(const gfxPoint
& aPoint
, gfxFloat aEpsilon
) {
42 return fabs(aPoint
.x
- x
) < aEpsilon
&& fabs(aPoint
.y
- y
) < aEpsilon
;
47 operator*(const gfxPoint
& aPoint
, const gfxSize
& aSize
)
49 return gfxPoint(aPoint
.x
* aSize
.width
, aPoint
.y
* aSize
.height
);
53 operator/(const gfxPoint
& aPoint
, const gfxSize
& aSize
)
55 return gfxPoint(aPoint
.x
/ aSize
.width
, aPoint
.y
/ aSize
.height
);
59 operator/(gfxFloat aValue
, const gfxSize
& aSize
)
61 return gfxSize(aValue
/ aSize
.width
, aValue
/ aSize
.height
);
64 #endif /* GFX_POINT_H */