1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef DOM_SVG_SVGPOINT_H_
#define DOM_SVG_SVGPOINT_H_
#include "nsDebug.h"
#include "gfxPoint.h"
#include "mozilla/gfx/Point.h"
#include "mozilla/FloatingPoint.h"
namespace mozilla {
/**
* This class is currently used for point list attributes.
*
* The DOM wrapper class for this class is DOMSVGPoint.
*/
class SVGPoint {
using Point = mozilla::gfx::Point;
public:
SVGPoint() : mX(0.0f), mY(0.0f) {}
SVGPoint(float aX, float aY) : mX(aX), mY(aY) {
NS_ASSERTION(IsValid(), "Constructed an invalid SVGPoint");
}
bool operator==(const SVGPoint& rhs) const {
return mX == rhs.mX && mY == rhs.mY;
}
SVGPoint& operator+=(const SVGPoint& rhs) {
mX += rhs.mX;
mY += rhs.mY;
return *this;
}
operator gfxPoint() const { return gfxPoint(mX, mY); }
operator Point() const { return Point(mX, mY); }
#ifdef DEBUG
bool IsValid() const { return std::isfinite(mX) && std::isfinite(mY); }
#endif
void SetX(float aX) { mX = aX; }
void SetY(float aY) { mY = aY; }
float GetX() const { return mX; }
float GetY() const { return mY; }
bool operator!=(const SVGPoint& rhs) const {
return mX != rhs.mX || mY != rhs.mY;
}
float mX;
float mY;
};
inline SVGPoint operator+(const SVGPoint& aP1, const SVGPoint& aP2) {
return SVGPoint(aP1.mX + aP2.mX, aP1.mY + aP2.mY);
}
inline SVGPoint operator-(const SVGPoint& aP1, const SVGPoint& aP2) {
return SVGPoint(aP1.mX - aP2.mX, aP1.mY - aP2.mY);
}
inline SVGPoint operator*(float aFactor, const SVGPoint& aPoint) {
return SVGPoint(aFactor * aPoint.mX, aFactor * aPoint.mY);
}
inline SVGPoint operator*(const SVGPoint& aPoint, float aFactor) {
return SVGPoint(aFactor * aPoint.mX, aFactor * aPoint.mY);
}
} // namespace mozilla
#endif // DOM_SVG_SVGPOINT_H_
|