2010-12-08 04:15:53 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2010-12-08 04:15:53 -08:00
|
|
|
|
|
|
|
#ifndef MOZILLA_SVGPOINT_H__
|
|
|
|
#define MOZILLA_SVGPOINT_H__
|
|
|
|
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "gfxPoint.h"
|
2013-11-02 04:10:38 -07:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2014-10-01 02:26:00 -07:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2010-12-08 04:15:53 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is currently used for point list attributes.
|
|
|
|
*
|
|
|
|
* The DOM wrapper class for this class is DOMSVGPoint.
|
|
|
|
*/
|
|
|
|
class SVGPoint
|
|
|
|
{
|
2013-11-02 04:10:38 -07:00
|
|
|
typedef mozilla::gfx::Point Point;
|
|
|
|
|
2010-12-08 04:15:53 -08:00
|
|
|
public:
|
|
|
|
|
|
|
|
SVGPoint()
|
|
|
|
: mX(0.0f)
|
|
|
|
, mY(0.0f)
|
|
|
|
{}
|
|
|
|
|
|
|
|
SVGPoint(float aX, float aY)
|
|
|
|
: mX(aX)
|
|
|
|
, mY(aY)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(IsValid(), "Constructed an invalid SVGPoint");
|
|
|
|
}
|
|
|
|
|
|
|
|
SVGPoint(const SVGPoint &aOther)
|
|
|
|
: mX(aOther.mX)
|
|
|
|
, mY(aOther.mY)
|
|
|
|
{}
|
|
|
|
|
|
|
|
SVGPoint& operator=(const SVGPoint &rhs) {
|
|
|
|
mX = rhs.mX;
|
|
|
|
mY = rhs.mY;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool operator==(const SVGPoint &rhs) const {
|
2010-12-08 04:15:53 -08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-11-02 04:10:38 -07:00
|
|
|
operator Point() const {
|
|
|
|
return Point(mX, mY);
|
|
|
|
}
|
|
|
|
|
2010-12-08 04:15:53 -08:00
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsValid() const {
|
2014-10-01 02:26:00 -07:00
|
|
|
return IsFinite(mX) && IsFinite(mY);
|
2010-12-08 04:15:53 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-16 17:35:24 -08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-12-08 04:15:53 -08:00
|
|
|
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 // MOZILLA_SVGPOINT_H__
|