00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef StAngle_hh
00021 #define StAngle_hh
00022
00023 #include <cmath>
00024 #include <float.h>
00025
00026 class StAngle {
00027 public:
00028 StAngle();
00029 StAngle(const StAngle& val);
00030 StAngle(double);
00031
00032 double degree();
00033
00034 operator double() const { return phi; }
00035
00036 StAngle operator= (double);
00037 StAngle operator+= (StAngle);
00038 StAngle operator-= (StAngle);
00039 StAngle operator*= (double);
00040 StAngle operator/= (double);
00041 int operator== (const StAngle&) const;
00042
00043 friend StAngle operator+ (StAngle, StAngle);
00044 friend StAngle operator- (StAngle, StAngle);
00045 friend StAngle operator* (StAngle, double);
00046 friend StAngle operator/ (StAngle, double);
00047
00048 friend StAngle average(StAngle, StAngle);
00049
00050 private:
00051 double phi;
00052 };
00053
00054
00055
00056
00057
00058 inline StAngle::StAngle()
00059 {
00060 phi = 0.;
00061 }
00062
00063 inline StAngle::StAngle(const StAngle& val)
00064 {
00065 phi = val.phi;
00066 }
00067
00068 inline StAngle::StAngle(double val)
00069 {
00070 phi = val;
00071 if (fabs(phi) > M_PI) phi = atan2(sin(phi), cos(phi));
00072 }
00073
00074
00075
00076
00077
00078 inline StAngle StAngle::operator= (double val)
00079 {
00080 phi = val;
00081 if (fabs(phi) > M_PI) phi = atan2(sin(phi), cos(phi));
00082 return *this;
00083 }
00084
00085 inline StAngle StAngle::operator+= (StAngle val)
00086 {
00087 phi += val.phi;
00088 if (fabs(phi) > M_PI) phi = atan2(sin(phi), cos(phi));
00089 return *this;
00090 }
00091
00092 inline StAngle StAngle::operator-= (StAngle val)
00093 {
00094 phi -= val.phi;
00095 if (fabs(phi) > M_PI) phi = atan2(sin(phi), cos(phi));
00096 return *this;
00097 }
00098
00099 inline StAngle StAngle::operator*= (double val)
00100 {
00101 phi *= val;
00102 if (fabs(phi) > M_PI) phi = atan2(sin(phi), cos(phi));
00103 return *this;
00104 }
00105
00106 inline StAngle StAngle::operator/= (double val)
00107 {
00108 phi /= val;
00109 if (fabs(phi) > M_PI) phi = atan2(sin(phi), cos(phi));
00110 return *this;
00111 }
00112
00113 inline int StAngle::operator== (const StAngle& a) const
00114 {
00115 return (fabs(StAngle(phi-a.phi)) < FLT_EPSILON);
00116 }
00117
00118
00119
00120
00121
00122 inline StAngle operator+ (StAngle angle, StAngle val)
00123 {
00124 double res = angle.phi + val.phi;
00125 if (fabs(res) > M_PI) res = atan2(sin(res), cos(res));
00126 return res;
00127 }
00128
00129 inline StAngle operator- (StAngle angle, StAngle val)
00130 {
00131 double res = angle.phi - val.phi;
00132 if (fabs(res) > M_PI) res = atan2(sin(res), cos(res));
00133 return res;
00134 }
00135
00136 inline StAngle operator* (StAngle angle, double val)
00137 {
00138 double res = angle.phi * val;
00139 if (fabs(res) > M_PI) res = atan2(sin(res), cos(res));
00140 return res;
00141 }
00142
00143 inline StAngle operator/ (StAngle angle, double val)
00144 {
00145 double res = angle.phi / val;
00146 if (fabs(res) > M_PI) res = atan2(sin(res), cos(res));
00147 return res;
00148 }
00149
00150 inline StAngle average(StAngle a, StAngle b)
00151 {
00152 return a+(b-a)/2.;
00153 }
00154
00155
00156
00157
00158
00159 inline double StAngle::degree()
00160 {
00161 double val = phi*180./M_PI;
00162 return (val < 0) ? val += 360 : val;
00163 }
00164
00165
00166 #endif