|
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/. */ |
|
5 |
|
6 #ifndef GFX_POINT_H |
|
7 #define GFX_POINT_H |
|
8 |
|
9 #include "nsMathUtils.h" |
|
10 #include "mozilla/gfx/BaseSize.h" |
|
11 #include "mozilla/gfx/BasePoint.h" |
|
12 #include "nsSize.h" |
|
13 #include "nsPoint.h" |
|
14 |
|
15 #include "gfxTypes.h" |
|
16 |
|
17 struct gfxSize : public mozilla::gfx::BaseSize<gfxFloat, gfxSize> { |
|
18 typedef mozilla::gfx::BaseSize<gfxFloat, gfxSize> Super; |
|
19 |
|
20 gfxSize() : Super() {} |
|
21 gfxSize(gfxFloat aWidth, gfxFloat aHeight) : Super(aWidth, aHeight) {} |
|
22 gfxSize(const nsIntSize& aSize) : Super(aSize.width, aSize.height) {} |
|
23 }; |
|
24 |
|
25 struct gfxPoint : public mozilla::gfx::BasePoint<gfxFloat, gfxPoint> { |
|
26 typedef mozilla::gfx::BasePoint<gfxFloat, gfxPoint> Super; |
|
27 |
|
28 gfxPoint() : Super() {} |
|
29 gfxPoint(gfxFloat aX, gfxFloat aY) : Super(aX, aY) {} |
|
30 gfxPoint(const nsIntPoint& aPoint) : Super(aPoint.x, aPoint.y) {} |
|
31 |
|
32 bool WithinEpsilonOf(const gfxPoint& aPoint, gfxFloat aEpsilon) { |
|
33 return fabs(aPoint.x - x) < aEpsilon && fabs(aPoint.y - y) < aEpsilon; |
|
34 } |
|
35 }; |
|
36 |
|
37 inline gfxPoint |
|
38 operator*(const gfxPoint& aPoint, const gfxSize& aSize) |
|
39 { |
|
40 return gfxPoint(aPoint.x * aSize.width, aPoint.y * aSize.height); |
|
41 } |
|
42 |
|
43 inline gfxPoint |
|
44 operator/(const gfxPoint& aPoint, const gfxSize& aSize) |
|
45 { |
|
46 return gfxPoint(aPoint.x / aSize.width, aPoint.y / aSize.height); |
|
47 } |
|
48 |
|
49 inline gfxSize |
|
50 operator/(gfxFloat aValue, const gfxSize& aSize) |
|
51 { |
|
52 return gfxSize(aValue / aSize.width, aValue / aSize.height); |
|
53 } |
|
54 |
|
55 #endif /* GFX_POINT_H */ |