#ifndef ROOT_Math_GenVector_Cartesian2D
#define ROOT_Math_GenVector_Cartesian2D 1
#ifndef ROOT_Math_GenVector_Polar2Dfwd
#include "Math/GenVector/Polar2Dfwd.h"
#endif
#ifndef ROOT_Math_Math
#include "Math/Math.h"
#endif
namespace ROOT {
namespace Math {
template <class T = double>
class Cartesian2D {
public :
typedef T Scalar;
Cartesian2D() : fX(0), fY(0) { }
Cartesian2D(Scalar xx, Scalar yy) : fX(xx), fY(yy) { }
template <class CoordSystem>
explicit Cartesian2D(const CoordSystem & v)
: fX(v.X()), fY(v.Y()) { }
Cartesian2D(const Cartesian2D & v) :
fX(v.X()), fY(v.Y()) { }
Cartesian2D & operator= (const Cartesian2D & v) {
fX = v.X();
fY = v.Y();
return *this;
}
void SetCoordinates(Scalar xx, Scalar yy) { fX=xx; fY=yy; }
void GetCoordinates(Scalar& xx, Scalar& yy ) const {xx=fX; yy=fY; }
Scalar X() const { return fX;}
Scalar Y() const { return fY;}
Scalar Mag2() const { return fX*fX + fY*fY; }
Scalar R() const { return std::sqrt( Mag2());}
Scalar Phi() const { return (fX==0 && fY==0) ? 0.0 : atan2(fY,fX);}
void SetX(Scalar a) { fX = a; }
void SetY(Scalar a) { fY = a; }
void SetXY(Scalar xx, Scalar yy ) {
fX=xx;
fY=yy;
}
void Scale(Scalar a) { fX *= a; fY *= a; }
void Negate() { fX = -fX; fY = -fY; }
void Rotate(Scalar angle) {
Scalar s = std::sin(angle);
Scalar c = std::cos(angle);
SetCoordinates( c*fX - s*fY, s*fX + c * fY );
}
template <class CoordSystem>
Cartesian2D & operator = (const CoordSystem & v) {
fX = v.x();
fY = v.y();
return *this;
}
bool operator == (const Cartesian2D & rhs) const {
return fX == rhs.fX && fY == rhs.fY;
}
bool operator != (const Cartesian2D & rhs) const {return !(operator==(rhs));}
Scalar x() const { return X();}
Scalar y() const { return Y();}
template <class T2>
explicit Cartesian2D( const Polar2D<T2> & v )
{
Scalar r = v.R();
fX = r * std::cos(v.Phi());
fY = r * std::sin(v.Phi());
}
template <class T2>
Cartesian2D & operator = (const Polar2D<T2> & v)
{
Scalar r = v.R();
fX = r * std::cos(v.Phi());
fY = r * std::sin(v.Phi());
return *this;
}
#if defined(__MAKECINT__) || defined(G__DICTIONARY)
void SetR(Scalar r);
void SetPhi(Scalar phi);
#endif
private:
T fX;
T fY;
};
}
}
#if defined(__MAKECINT__) || defined(G__DICTIONARY)
#include "Math/GenVector/GenVector_exception.h"
#include "Math/GenVector/Polar2D.h"
namespace ROOT {
namespace Math {
template <class T>
void Cartesian2D<T>::SetR(Scalar r) {
GenVector_exception e("Cartesian2D::SetR() is not supposed to be called");
throw e;
Polar2D<Scalar> v(*this); v.SetR(r); *this = Cartesian2D<Scalar>(v);
}
template <class T>
void Cartesian2D<T>::SetPhi(Scalar phi) {
GenVector_exception e("Cartesian2D::SetPhi() is not supposed to be called");
throw e;
Polar2D<Scalar> v(*this); v.SetPhi(phi); *this = Cartesian2D<Scalar>(v);
}
}
}
#endif
#endif /* ROOT_Math_GenVector_Cartesian2D */
Last change: Wed Aug 6 08:06:12 2008
Last generated: 2008-08-06 08:06
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.