PolarTmplDec.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 #ifndef _PolarTmplDec_
00024 #define _PolarTmplDec_
00025 
00026 #include <iosfwd>
00027 #include "CLAM_Math.hxx"
00028 
00029 namespace CLAM
00030 {
00031 
00032         template <class T>
00033         class PolarTmpl
00034         {
00035         private:
00036                 T mMag, mAng;
00037 
00038         public:
00039                 PolarTmpl(T mag = 0.0,T ang = 0.0)// constructor
00040                 {
00041                         mMag = mag;
00042                         mAng = ang;
00043                 };
00044 
00045                 const T Mag(void) const {return mMag;}; // accessor 
00046                 const T Ang(void) const {return mAng;}; // accessor 
00047 
00048                 void SetMag(const T& mag) { mMag = mag;}; // accesor
00049                 void SetAng(const T& ang) { mAng = ang;}; // accesor
00050 
00051                 // returns real part
00052                 const T Real (void) const
00053                 {
00054                         return fabs(mMag) * CLAM_cos(mAng);
00055                 }
00056 
00057                 // returns imaginary part
00058                 const T Imag (void) const
00059                 {
00060                         return fabs(mMag) * CLAM_sin(mAng); 
00061                 }
00062 
00063                 // friend function to handle cartesian coordinates
00064                 friend PolarTmpl<T> ToComplex(const T& real, const T& imag)
00065                 {
00066                         return PolarTmpl<T> (CLAM_sqrt (real*real + imag*imag),CLAM_atan2 (imag,real));
00067                 };
00068 
00069                 // ------   member operators ... ------
00070                 //  complex '=' operator  (float)
00071                 const PolarTmpl<T>& operator = (const float mag)
00072                 {
00073                         mMag = mag;
00074                         mAng = 0;
00075                         return *this;
00076                 }
00077 
00078                 // complex '=' operator           
00079                 const PolarTmpl<T>& operator = (const PolarTmpl<T>& a) 
00080                 {
00081                         mMag = a.mMag;
00082                         mAng = a.mAng;
00083                         return *this;
00084 
00085                 }
00086 
00087                 // complex '+=' operator
00088                 const PolarTmpl<T>& operator += (const PolarTmpl<T>& a);
00089 
00090                 //  complex '-=' operator 
00091                 const PolarTmpl<T>& operator -= (const PolarTmpl<T>& a);
00092 
00093                 // polar '-' operator 
00094                 PolarTmpl<T> operator - (const PolarTmpl<T>& b) const;
00095 
00096                 // polar '+' operator 
00097                 PolarTmpl<T> operator + (const PolarTmpl<T>& b) const;
00098 
00099                 // complex '*' operator
00100                 PolarTmpl<T> operator * (const PolarTmpl<T>& b) const
00101                 {
00102                         PolarTmpl<T> ret(mMag * b.mMag,mAng + b.mAng);
00103                         return ret;  
00104                 }
00105 
00106                 // complex '/' operator 
00107                 PolarTmpl<T> operator / (const PolarTmpl<T>& b) const
00108                 {
00109                         PolarTmpl<T> ret(mMag / b.mMag,mAng - b.mAng);
00110                         return ret;  
00111                 }
00112 
00113                 // complex '==' operator
00114                 bool operator == (const PolarTmpl<T>& b) const
00115                 {       
00116                         if ((mMag == b.mMag)&&(mAng == b.mAng)) return true;
00117                         else return false;
00118                 }
00119 
00120                 // polar '!=' operator
00121                 bool operator != (const PolarTmpl<T>& b) const
00122                 {       
00123                         if ((mMag == b.mMag)&&(mAng == b.mAng)) return false;
00124                         else return true;
00125                 }
00126 
00127         };
00128 
00129         template <class T>
00130         std::istream& operator >> (std::istream & stream, PolarTmpl<T> & a);
00131         
00132         template <class T>
00133         std::ostream& operator << (std::ostream & stream, const PolarTmpl<T> & a);
00134         
00135 } // namespace CLAM
00136 
00137 #endif // _PolarTmplDec_
00138 
Generated by  doxygen 1.6.3