Bug 1700051: part 46) Const-qualify `mozInlineSpellStatus::mAnchorRange`. r=smaug
[gecko.git] / dom / svg / SVGPoint.h
blob4043566bdea09b30664b9436e84947d3227a924e
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/. */
7 #ifndef DOM_SVG_SVGPOINT_H_
8 #define DOM_SVG_SVGPOINT_H_
10 #include "nsDebug.h"
11 #include "gfxPoint.h"
12 #include "mozilla/gfx/Point.h"
13 #include "mozilla/FloatingPoint.h"
15 namespace mozilla {
17 /**
18 * This class is currently used for point list attributes.
20 * The DOM wrapper class for this class is DOMSVGPoint.
22 class SVGPoint {
23 using Point = mozilla::gfx::Point;
25 public:
26 SVGPoint() : mX(0.0f), mY(0.0f) {}
28 SVGPoint(float aX, float aY) : mX(aX), mY(aY) {
29 NS_ASSERTION(IsValid(), "Constructed an invalid SVGPoint");
32 bool operator==(const SVGPoint& rhs) const {
33 return mX == rhs.mX && mY == rhs.mY;
36 SVGPoint& operator+=(const SVGPoint& rhs) {
37 mX += rhs.mX;
38 mY += rhs.mY;
39 return *this;
42 operator gfxPoint() const { return gfxPoint(mX, mY); }
44 operator Point() const { return Point(mX, mY); }
46 #ifdef DEBUG
47 bool IsValid() const { return IsFinite(mX) && IsFinite(mY); }
48 #endif
50 void SetX(float aX) { mX = aX; }
51 void SetY(float aY) { mY = aY; }
52 float GetX() const { return mX; }
53 float GetY() const { return mY; }
55 bool operator!=(const SVGPoint& rhs) const {
56 return mX != rhs.mX || mY != rhs.mY;
59 float mX;
60 float mY;
63 inline SVGPoint operator+(const SVGPoint& aP1, const SVGPoint& aP2) {
64 return SVGPoint(aP1.mX + aP2.mX, aP1.mY + aP2.mY);
67 inline SVGPoint operator-(const SVGPoint& aP1, const SVGPoint& aP2) {
68 return SVGPoint(aP1.mX - aP2.mX, aP1.mY - aP2.mY);
71 inline SVGPoint operator*(float aFactor, const SVGPoint& aPoint) {
72 return SVGPoint(aFactor * aPoint.mX, aFactor * aPoint.mY);
75 inline SVGPoint operator*(const SVGPoint& aPoint, float aFactor) {
76 return SVGPoint(aFactor * aPoint.mX, aFactor * aPoint.mY);
79 } // namespace mozilla
81 #endif // DOM_SVG_SVGPOINT_H_