Phi.h

Go to the documentation of this file.
00001 //===============================================
00002 //                Phi class
00003 //===============================================
00004 //
00005 //  A utility class to implement the cyclic nature
00006 //  of the phi variable in the range  -Pi <-> Pi
00007 // 
00008 //  The constructor uses a double number, which is reduced to
00009 //  the required range by repeated addition or subtraction of 2*Pi
00010 // 
00011 //  The operation in any arithmetic expression involving Phi and
00012 //  double numbers is understood in this way:
00013 //
00014 //  - wherever any double number is used then it is implicitly converted
00015 //    to a Phi as per the constructor. The operation then proceeds exactly
00016 //    as if the expression contained only 
00017 //
00018 // -  The user can add and subtract Phi objects and the result is automatically
00019 //  kept within a cyclic range.
00020 //
00021 //  -The difference between two PHI objects always represents the smallest 
00022 //   angle between them, signed according to whether this is clockwise
00023 //   or anticlockwise.
00024 //
00025 // - Most operations are convertable to use a double arguments where sensible. 
00026 //
00027 
00028 
00029 #ifndef PHI_H
00030 #define PHI_H
00031 class Phi;
00032 class MsgStream;
00033 //output operators for the Athena MessageStream 
00034 MsgStream& operator << ( MsgStream&, const Phi& ) ;      
00035 MsgStream& operator << ( MsgStream&, const Phi* const) ; 
00036 
00041 class Phi {
00042   
00043  private:
00044   
00045   double m_val ;
00046   
00047   void reduce() {
00048     while( m_val >  s_upperLimit )  { m_val -= s_range ; }
00049     while( m_val <= s_lowerLimit  ) { m_val += s_range ; }
00050   }
00051   static const double s_upperLimit;
00052   static const double s_lowerLimit;
00053   static const double s_range;
00054   
00055   
00056   
00057  public:
00058   
00059   // Constructors:
00060   Phi() { this->m_val = 0. ;  }
00061   Phi( double init )     { this->m_val = init ; this->reduce() ; }
00062   Phi( const Phi& src )        { this->m_val = src.m_val ; } 
00063   
00064   // Arithmetic:
00065   
00066   Phi& operator= ( const Phi& rhs ) { 
00067     this->m_val = rhs.m_val; 
00068     return *this; 
00069   }
00070   
00071   Phi& operator+= ( Phi& rhs )  { 
00072     this->m_val += rhs.m_val ; 
00073     reduce() ;
00074     return *this; 
00075   }
00076   
00077   Phi& operator-= ( Phi& in )  { 
00078     this->m_val -= in.m_val;
00079     reduce() ;
00080     return *this; 
00081   }
00082   
00083   Phi operator+ ( Phi& in )  const { 
00084     Phi result( this->m_val + in.m_val ) ;
00085     return result ;
00086   }
00087   
00088   Phi operator- ( Phi& in )  const { 
00089     Phi result(this->m_val - in.m_val ) ;
00090     return result ;
00091   }
00092   
00093   // boolean 
00094   bool operator< ( Phi& in ) const { return this->m_val < in.m_val ; }
00095   bool operator> ( Phi& in ) const { return this->m_val > in.m_val ; }
00096   
00097   // Conversions
00098   operator double() const { return this->m_val ; }
00099   // debug
00100   double lowerLimit() const {return s_lowerLimit;}
00101   double upperLimit() const {return s_upperLimit;}
00102   double range     () const {return s_range;}
00103   double val()        const {return m_val;}
00104 };
00105 #endif
00106 

Generated on Fri Sep 21 13:00:09 2007 for AtlfastEvent by  doxygen 1.5.1