src/tools/tPolynomialWithBase.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #ifndef ArmageTron_tPolynomialWithBase_H
00029 #define ArmageTron_tPolynomialWithBase_H
00030 
00031 #include "tPolynomial.h"
00032 
00034 template <typename T>
00035 class tPolynomialWithBase : public class tPolynomial<T>
00036 {
00037 public:
00038 
00039     tPolynomialWithBase();  
00040     tPolynomialWithBase(REAL value);  
00041     tPolynomialWithBase(REAL coefs_[]);  
00042     tPolynomialWithBase(const tPolynomialWithBase<T> &tf);  
00043     tPolynomialWithBase(const tPolynomial<T> &tf);  
00044 
00045     virtual ~tPolynomialWithBase() { 
00046       // Empty
00047     }
00048 
00049     virtual REAL evaluate( REAL argument ) const; 
00050     inline REAL operator()( REAL argument ) const; 
00051 
00052     void setUnadjustableOffset(REAL x);
00053     REAL getUnadjustableOffset();
00054 
00055     virtual T & ReadSync( T & m );
00056     virtual T & WriteSync( T & m ) const;
00057 
00058     template<typename D> 
00059     friend bool operator == (const tPolynomialWithBase<D> & left, const tPolynomialWithBase<D> & right);
00060 
00061 protected:
00062     REAL unadjustableOffset; 
00063 };
00064 
00065 //These templates are probably only useable with nMessage as parameter.
00066 //The reason they're templates is that nMessage isn't available in src/tools
00067 //and that tPolynomialWithBase might be needed to be in src/tools in the future.
00068 //Imagine a constructor for vValue that converts from a tPolynomialWithBase as an
00069 //example (or the other way, as far as possible). --wrtlprnft
00070 
00071 T & operator << ( T & m, tPolynomialWithBase<T> const & f ); 
00072 template<typename T>
00073 T & operator >> ( T & m, tPolynomialWithBase<T> & f );       
00074 template<typename T>
00075 bool operator == (const tPolynomialWithBase<T> & left, const tPolynomial<T> & right);
00076 template<typename T>
00077 bool operator == (const tPolynomialWithBase<T> & left, const tPolynomialWithBase<T> & right);
00078 
00079 
00080 
00081 template <typename T>
00082 tPolynomialWithBase<T>::tPolynomialWithBase()  
00083 : tPolynomial<T>(),
00084   unadjustableOffset(0.0)
00085 {
00086   // Empty
00087 }
00088 
00089 template <typename T>
00090 tPolynomialWithBase<T>::tPolynomialWithBase(REAL value)  
00091 : tPolynomial<T>(value),
00092   unadjustableOffset(0.0)
00093 { 
00094   // Empty
00095 }
00096 
00097 
00098 template <typename T>
00099 tPolynomialWithBase<T>::tPolynomialWithBase(REAL coefs_[])  
00100 : tPolynomial<T>(coefs_),
00101   unadjustableOffset(0.0)
00102 {
00103   // Empty
00104 }
00105 
00106 template <typename T>
00107 tPolynomialWithBase<T>::tPolynomialWithBase(const tPolynomialWithBase<T> &tf)  
00108 : tPolynomial<T>(tf),
00109   unadjustableOffset(tf.unadjustableOffset)
00110 {
00111   // Empty
00112 }
00113 
00114 template <typename T>
00115 tPolynomialWithBase<T>::tPolynomialWithBase(const tPolynomial<T> &tf)  
00116 : tPolynomial<T>(tf),
00117   unadjustableOffset(0.0)
00118 {
00119   // Empty
00120 }
00121 
00125 #define DELTA 1e-10
00126 
00127 template<typename T>
00128 bool operator == (const tPolynomialWithBase<T> & left, const tPolynomialWithBase<T> & right)
00129 {
00130     bool res = static_cast<tPolynomial<T> >(left) == static_cast<tPolynomial<T> >(right);
00131 
00132     if(true == res) {
00133       // float/double equality doesnt exist. Accept small difference as equal.
00134       res = ( fabs(left.unadjustableOffset - right.unadjustableOffset) < DELTA);
00135     }
00136     
00137     return res;
00138 }
00139 
00140 template <typename T>
00141 REAL tPolynomialWithBase<T>::evaluate( REAL argument ) const
00142 {
00143   REAL res = tPolynomial<T>::evaluate( argument );
00144 
00145   res += unadjustableOffset;
00146   return res;
00147 }
00148 
00149 template <typename T>
00150 T & tPolynomialWithBase<T>::WriteSync( T & m ) const
00151 {
00152     tPolynomial<T>::WriteSync( m );
00153 
00154     // write unadjustableOffset
00155     m << unadjustableOffset;
00156 
00157     return m;
00158 }
00159 
00160 template <typename T>
00161 T & tPolynomialWithBase<T>::ReadSync( T & m )
00162 {
00163     tPolynomial<T>::ReadSync( m );
00164 
00165     // read unadjustableOffset
00166     m >> unadjustableOffset;
00167 
00168     return m;
00169 }
00170 
00171 #endif
00172 

Generated on Sat Mar 15 22:56:01 2008 for Armagetron Advanced by  doxygen 1.5.4