00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
00066
00067
00068
00069
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
00087 }
00088
00089 template <typename T>
00090 tPolynomialWithBase<T>::tPolynomialWithBase(REAL value)
00091 : tPolynomial<T>(value),
00092 unadjustableOffset(0.0)
00093 {
00094
00095 }
00096
00097
00098 template <typename T>
00099 tPolynomialWithBase<T>::tPolynomialWithBase(REAL coefs_[])
00100 : tPolynomial<T>(coefs_),
00101 unadjustableOffset(0.0)
00102 {
00103
00104 }
00105
00106 template <typename T>
00107 tPolynomialWithBase<T>::tPolynomialWithBase(const tPolynomialWithBase<T> &tf)
00108 : tPolynomial<T>(tf),
00109 unadjustableOffset(tf.unadjustableOffset)
00110 {
00111
00112 }
00113
00114 template <typename T>
00115 tPolynomialWithBase<T>::tPolynomialWithBase(const tPolynomial<T> &tf)
00116 : tPolynomial<T>(tf),
00117 unadjustableOffset(0.0)
00118 {
00119
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
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
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
00166 m >> unadjustableOffset;
00167
00168 return m;
00169 }
00170
00171 #endif
00172