/src/mozilla-central/dom/svg/SVGPoint.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_SVGPOINT_H__ |
8 | | #define MOZILLA_SVGPOINT_H__ |
9 | | |
10 | | #include "nsDebug.h" |
11 | | #include "gfxPoint.h" |
12 | | #include "mozilla/gfx/Point.h" |
13 | | #include "mozilla/FloatingPoint.h" |
14 | | |
15 | | namespace mozilla { |
16 | | |
17 | | /** |
18 | | * This class is currently used for point list attributes. |
19 | | * |
20 | | * The DOM wrapper class for this class is DOMSVGPoint. |
21 | | */ |
22 | | class SVGPoint |
23 | | { |
24 | | typedef mozilla::gfx::Point Point; |
25 | | |
26 | | public: |
27 | | |
28 | | SVGPoint() |
29 | | : mX(0.0f) |
30 | | , mY(0.0f) |
31 | 0 | {} |
32 | | |
33 | | SVGPoint(float aX, float aY) |
34 | | : mX(aX) |
35 | | , mY(aY) |
36 | 0 | { |
37 | 0 | NS_ASSERTION(IsValid(), "Constructed an invalid SVGPoint"); |
38 | 0 | } |
39 | | |
40 | | SVGPoint(const SVGPoint &aOther) |
41 | | : mX(aOther.mX) |
42 | | , mY(aOther.mY) |
43 | 0 | {} |
44 | | |
45 | 0 | SVGPoint& operator=(const SVGPoint &rhs) { |
46 | 0 | mX = rhs.mX; |
47 | 0 | mY = rhs.mY; |
48 | 0 | return *this; |
49 | 0 | } |
50 | | |
51 | 0 | bool operator==(const SVGPoint &rhs) const { |
52 | 0 | return mX == rhs.mX && mY == rhs.mY; |
53 | 0 | } |
54 | | |
55 | 0 | SVGPoint& operator+=(const SVGPoint &rhs) { |
56 | 0 | mX += rhs.mX; |
57 | 0 | mY += rhs.mY; |
58 | 0 | return *this; |
59 | 0 | } |
60 | | |
61 | 0 | operator gfxPoint() const { |
62 | 0 | return gfxPoint(mX, mY); |
63 | 0 | } |
64 | | |
65 | 0 | operator Point() const { |
66 | 0 | return Point(mX, mY); |
67 | 0 | } |
68 | | |
69 | | #ifdef DEBUG |
70 | | bool IsValid() const { |
71 | | return IsFinite(mX) && IsFinite(mY); |
72 | | } |
73 | | #endif |
74 | | |
75 | | void SetX(float aX) |
76 | 0 | { mX = aX; } |
77 | | void SetY(float aY) |
78 | 0 | { mY = aY; } |
79 | | float GetX() const |
80 | 0 | { return mX; } |
81 | | float GetY() const |
82 | 0 | { return mY; } |
83 | | |
84 | 0 | bool operator!=(const SVGPoint &rhs) const { |
85 | 0 | return mX != rhs.mX || mY != rhs.mY; |
86 | 0 | } |
87 | | |
88 | | float mX; |
89 | | float mY; |
90 | | }; |
91 | | |
92 | | inline SVGPoint operator+(const SVGPoint& aP1, |
93 | | const SVGPoint& aP2) |
94 | 0 | { |
95 | 0 | return SVGPoint(aP1.mX + aP2.mX, aP1.mY + aP2.mY); |
96 | 0 | } |
97 | | |
98 | | inline SVGPoint operator-(const SVGPoint& aP1, |
99 | | const SVGPoint& aP2) |
100 | 0 | { |
101 | 0 | return SVGPoint(aP1.mX - aP2.mX, aP1.mY - aP2.mY); |
102 | 0 | } |
103 | | |
104 | | inline SVGPoint operator*(float aFactor, |
105 | | const SVGPoint& aPoint) |
106 | 0 | { |
107 | 0 | return SVGPoint(aFactor * aPoint.mX, aFactor * aPoint.mY); |
108 | 0 | } |
109 | | |
110 | | inline SVGPoint operator*(const SVGPoint& aPoint, |
111 | | float aFactor) |
112 | 0 | { |
113 | 0 | return SVGPoint(aFactor * aPoint.mX, aFactor * aPoint.mY); |
114 | 0 | } |
115 | | |
116 | | } // namespace mozilla |
117 | | |
118 | | #endif // MOZILLA_SVGPOINT_H__ |