Go to the documentation of this file.00001 #ifndef GeometryVector_Geom_Phi_h
00002 #define GeometryVector_Geom_Phi_h
00003
00004 #include "DataFormats/GeometryVector/interface/Pi.h"
00005 #include <cmath>
00006
00007 namespace Geom {
00008
00019 template <class T>
00020 class Phi {
00021 public:
00022
00024 Phi() {}
00025
00029 explicit Phi( const T& val) : theValue(val) { normalize();}
00030
00032 operator T() const { return theValue;}
00033
00035 template <class T1> operator Phi<T1>() { return Phi<T1>(theValue);}
00036
00038 T value() const { return theValue;}
00039
00040
00041 T phi() const { return theValue;}
00042
00044 Phi& operator+=(const T& a) {theValue+=a; normalize(); return *this;}
00045 Phi& operator+=(const Phi& a) {return operator+=(a.value());}
00046
00047 Phi& operator-=(const T& a) {theValue-=a; normalize(); return *this;}
00048 Phi& operator-=(const Phi& a) {return operator-=(a.value());}
00049
00050 Phi& operator*=(const T& a) {theValue*=a; normalize(); return *this;}
00051
00052 Phi& operator/=(const T& a) {theValue/=a; normalize(); return *this;}
00053
00054 T degrees() const { return theValue*180./pi();}
00055
00056 private:
00057
00058 T theValue;
00059
00060 void normalize() {
00061 if( theValue > twoPi() || theValue < -twoPi()) {
00062 theValue = fmod( theValue, (T) twoPi());
00063 }
00064 if (theValue <= -pi()) theValue += twoPi();
00065 if (theValue > pi()) theValue -= twoPi();
00066 }
00067
00068 };
00069
00071 template <class T>
00072 inline Phi<T> operator-(const Phi<T>& a) {return Phi<T>(-a.value());}
00073
00074
00076 template <class T>
00077 inline Phi<T> operator+(const Phi<T>& a, const Phi<T>& b) {
00078 return Phi<T>(a) += b;
00079 }
00081 template <class T, class Scalar>
00082 inline Phi<T> operator+(const Phi<T>& a, const Scalar& b) {
00083 return Phi<T>(a) += b;
00084 }
00086 template <class T, class Scalar>
00087 inline Phi<T> operator+(const Scalar& a, const Phi<T>& b) {
00088 return Phi<T>(b) += a;
00089 }
00090
00091
00093 template <class T>
00094 inline Phi<T> operator-(const Phi<T>& a, const Phi<T>& b) {
00095 return Phi<T>(a) -= b;
00096 }
00098 template <class T, class Scalar>
00099 inline Phi<T> operator-(const Phi<T>& a, const Scalar& b) {
00100 return Phi<T>(a) -= b;
00101 }
00103 template <class T, class Scalar>
00104 inline Phi<T> operator-(const Scalar& a, const Phi<T>& b) {
00105 return Phi<T>(a - b.value());
00106 }
00107
00108
00110 template <class T, class Scalar>
00111 inline Phi<T> operator*(const Phi<T>& a, const Scalar& b) {
00112 return Phi<T>(a) *= b;
00113 }
00115 template <class T>
00116 inline Phi<T> operator*(double a, const Phi<T>& b) {
00117 return Phi<T>(b) *= a;
00118 }
00119
00120
00122 template <class T>
00123 inline T operator/(const Phi<T>& a, const Phi<T>& b) {
00124 return a.value() / b.value();
00125 }
00127 template <class T>
00128 inline Phi<T> operator/(const Phi<T>& a, double b) {
00129 return Phi<T>(a) /= b;
00130 }
00131
00132
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 #endif
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174