tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SVGPoint.h (2064B)


      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 DOM_SVG_SVGPOINT_H_
      8 #define DOM_SVG_SVGPOINT_H_
      9 
     10 #include "gfxPoint.h"
     11 #include "mozilla/gfx/Point.h"
     12 #include "nsDebug.h"
     13 
     14 namespace mozilla {
     15 
     16 /**
     17 * This class is currently used for point list attributes.
     18 *
     19 * The DOM wrapper class for this class is DOMSVGPoint.
     20 */
     21 class SVGPoint {
     22  using Point = mozilla::gfx::Point;
     23 
     24 public:
     25  SVGPoint() : mX(0.0f), mY(0.0f) {}
     26 
     27  SVGPoint(float aX, float aY) : mX(aX), mY(aY) {
     28    NS_ASSERTION(IsValid(), "Constructed an invalid SVGPoint");
     29  }
     30 
     31  bool operator==(const SVGPoint& rhs) const {
     32    return mX == rhs.mX && mY == rhs.mY;
     33  }
     34 
     35  SVGPoint& operator+=(const SVGPoint& rhs) {
     36    mX += rhs.mX;
     37    mY += rhs.mY;
     38    return *this;
     39  }
     40 
     41  operator gfxPoint() const { return gfxPoint(mX, mY); }
     42 
     43  operator Point() const { return Point(mX, mY); }
     44 
     45 #ifdef DEBUG
     46  bool IsValid() const { return std::isfinite(mX) && std::isfinite(mY); }
     47 #endif
     48 
     49  void SetX(float aX) { mX = aX; }
     50  void SetY(float aY) { mY = aY; }
     51  float GetX() const { return mX; }
     52  float GetY() const { return mY; }
     53 
     54  bool operator!=(const SVGPoint& rhs) const {
     55    return mX != rhs.mX || mY != rhs.mY;
     56  }
     57 
     58  float mX;
     59  float mY;
     60 };
     61 
     62 inline SVGPoint operator+(const SVGPoint& aP1, const SVGPoint& aP2) {
     63  return SVGPoint(aP1.mX + aP2.mX, aP1.mY + aP2.mY);
     64 }
     65 
     66 inline SVGPoint operator-(const SVGPoint& aP1, const SVGPoint& aP2) {
     67  return SVGPoint(aP1.mX - aP2.mX, aP1.mY - aP2.mY);
     68 }
     69 
     70 inline SVGPoint operator*(float aFactor, const SVGPoint& aPoint) {
     71  return SVGPoint(aFactor * aPoint.mX, aFactor * aPoint.mY);
     72 }
     73 
     74 inline SVGPoint operator*(const SVGPoint& aPoint, float aFactor) {
     75  return SVGPoint(aFactor * aPoint.mX, aFactor * aPoint.mY);
     76 }
     77 
     78 }  // namespace mozilla
     79 
     80 #endif  // DOM_SVG_SVGPOINT_H_