Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

CTB2vec.icc

Go to the documentation of this file.
00001 
00006 /*----------------------------------------------------------------------------*/
00007 /* C Tool Box: Designed and implemented by:                                   */
00008 /*    Walter F.J. Mueller   Gesellschaft fuer Schwerionenforschung (GSI)      */
00009 /*                          Planckstrasse 1, D-64291 Darmstadt, Germany       */
00010 /*                  Email:  W.F.J.Mueller@gsi.de                              */
00011 /*                  WWW:    http://www-kp3.gsi.de/www/kp3/people/mueller.html */
00012 /*------------------------------------------+---------------------------------*/
00013 
00014 #include "CTBnum.hxx"
00015 #include "CTBmath.hxx"
00016 
00054 //------------------------------------------+-----------------------------------
00056 
00057 template <class T>
00058 inline CTB2vec<T>::CTB2vec()
00059 {
00060   m_data[0] = 0;
00061   m_data[1] = 0;
00062 }
00063 
00064 //------------------------------------------+-----------------------------------
00066 
00067 template <class T>
00068 inline CTB2vec<T>::CTB2vec(T rhs)
00069 {
00070   operator=(rhs);
00071 }
00072 
00073 //------------------------------------------+-----------------------------------
00075 
00076 template <class T>
00077 inline CTB2vec<T>::CTB2vec(T x, T y)
00078 {
00079   m_data[0] = x;
00080   m_data[1] = y;
00081 }
00082 
00083 //------------------------------------------+-----------------------------------
00085 
00086 template <class T>
00087 inline CTB2vec<T>::CTB2vec(const CTB2vec<T>& rhs)
00088 {
00089   operator=(rhs);
00090 }
00091 
00092 //------------------------------------------+-----------------------------------
00094 
00095 template <class T>
00096 inline T& CTB2vec<T>::X()
00097 {
00098   return m_data[0];
00099 }
00100 
00101 //------------------------------------------+-----------------------------------
00103 
00104 template <class T>
00105 inline const T& CTB2vec<T>::X() const
00106 {
00107   return m_data[0];
00108 }
00109 
00110 //------------------------------------------+-----------------------------------
00112 
00113 template <class T>
00114 inline T& CTB2vec<T>::Y()
00115 {
00116   return m_data[1];
00117 }
00118 
00119 //------------------------------------------+-----------------------------------
00121 
00122 template <class T>
00123 inline const T& CTB2vec<T>::Y() const
00124 {
00125   return m_data[1];
00126 }
00127 
00128 //------------------------------------------+-----------------------------------
00130 
00131 template <class T>
00132 inline void CTB2vec<T>::X(T x)
00133 {
00134   m_data[0] = x;
00135   return;
00136 }
00137 
00138 //------------------------------------------+-----------------------------------
00140 template <class T>
00141 inline void CTB2vec<T>::Y(T y)
00142 {
00143   m_data[1] = y;
00144   return;
00145 }
00146 
00147 //------------------------------------------+-----------------------------------
00149 
00150 template <class T>
00151 inline T CTB2vec<T>::Length() const
00152 {
00153   return CTBsqrt(CTBabs2(m_data[0]) + CTBabs2(m_data[1]));
00154 }
00155 
00156 //------------------------------------------+-----------------------------------
00158 
00159 template <class T>
00160 inline T CTB2vec<T>::Dot(const CTB2vec<T>& rhs) const
00161 {
00162   return m_data[0]*rhs.m_data[0] +
00163          m_data[1]*rhs.m_data[1];
00164 }
00165 
00166 //------------------------------------------+-----------------------------------
00168 
00169 template <class T>
00170 inline CTB2vec<T> CTB2vec<T>::Project(const CTB2vec<T>& x,
00171                                       const CTB2vec<T>& y) const
00172 {
00173   return CTB2vec<T>(Dot(x),Dot(y));
00174 }
00175 
00176 //------------------------------------------+-----------------------------------
00178 
00179 template <class T>
00180 inline CTB2vec<T> CTB2vec<T>::UnProject(const CTB2vec<T>& x,
00181                                         const CTB2vec<T>& y) const
00182 {
00183   return CTB2vec<T>(m_data[0]*x[0] + m_data[1]*y[0],
00184                     m_data[0]*x[1] + m_data[1]*y[1]);
00185 }
00186 
00187 //------------------------------------------+-----------------------------------
00189 
00190 template <class T>
00191 inline T& CTB2vec<T>::operator[](CTBint i_ind)
00192 {
00193   return m_data[i_ind];
00194 }
00195 
00196 //------------------------------------------+-----------------------------------
00198 
00199 template <class T>
00200 inline const T& CTB2vec<T>::operator[](CTBint i_ind) const
00201 {
00202   return m_data[i_ind];
00203 }
00204 
00205 //------------------------------------------+-----------------------------------
00207 
00208 template <class T>
00209 inline CTB2vec<T>::operator T*()
00210 {
00211   return m_data;
00212 }
00213 
00214 //------------------------------------------+-----------------------------------
00216 
00217 template <class T>
00218 inline CTB2vec<T>::operator const T*() const
00219 {
00220   return m_data;
00221 }
00222 
00223 //------------------------------------------+-----------------------------------
00225 
00226 template <class T>
00227 inline CTB2vec<T> CTB2vec<T>::operator-() const
00228 {
00229   return CTB2vec<T>(-m_data[0],-m_data[1]);
00230 }
00231 
00232 //------------------------------------------+-----------------------------------
00234 
00235 template <class T>
00236 inline CTB2vec<T>& CTB2vec<T>::operator+=(const CTB2vec<T>& rhs)
00237 {
00238   m_data[0] += rhs.m_data[0];
00239   m_data[1] += rhs.m_data[1];
00240   return *this;
00241 }
00242 
00243 //------------------------------------------+-----------------------------------
00245 
00246 template <class T>
00247 inline CTB2vec<T>& CTB2vec<T>::operator-=(const CTB2vec<T>& rhs)
00248 {
00249   m_data[0] -= rhs.m_data[0];
00250   m_data[1] -= rhs.m_data[1];
00251   return *this;
00252 }
00253 
00254 //------------------------------------------+-----------------------------------
00256 
00257 template <class T>
00258 inline CTB2vec<T>& CTB2vec<T>::operator*=(T rhs)
00259 {
00260   m_data[0] *= rhs;
00261   m_data[1] *= rhs;
00262   return *this;
00263 }
00264 
00265 //------------------------------------------+-----------------------------------
00267 
00268 template <class T>
00269 inline CTB2vec<T>& CTB2vec<T>::operator/=(T rhs)
00270 {
00271   T rhs_inv  = 1./rhs;
00272   m_data[0] *= rhs_inv;
00273   m_data[1] *= rhs_inv;
00274   return *this;
00275 }
00276 
00277 //------------------------------------------+-----------------------------------
00279 
00280 template <class T>
00281 inline CTB2vec<T>& CTB2vec<T>::operator=(T rhs)
00282 {
00283   m_data[0] = rhs;
00284   m_data[1] = rhs;
00285   return *this;
00286 }
00287 
00288 //------------------------------------------+-----------------------------------
00290 
00291 template <class T>
00292 inline CTB2vec<T>& CTB2vec<T>::operator=(const CTB2vec<T>& rhs)
00293 {
00294   m_data[0] = rhs.m_data[0];
00295   m_data[1] = rhs.m_data[1];
00296   return *this;
00297 }
00298 
00299 //------------------------------------------+-----------------------------------
00305 template <class T>
00306 inline CTB2vec<T> operator+(const CTB2vec<T>& lhs, const CTB2vec<T>& rhs)
00307 {
00308   return CTB2vec<T>(lhs[0]+rhs[0], lhs[1]+rhs[1]);
00309 }
00310 
00311 //------------------------------------------+-----------------------------------
00317 template <class T>
00318 inline CTB2vec<T> operator+(const CTB2vec<T>& lhs, T f_rhs)
00319 {
00320   return CTB2vec<T>(lhs[0]+f_rhs, lhs[1]+f_rhs);
00321 }
00322 
00323 //------------------------------------------+-----------------------------------
00329 template <class T>
00330   inline CTB2vec<T> operator+(T f_lhs, const CTB2vec<T>& rhs)
00331 {
00332   return CTB2vec<T>(f_lhs+rhs[0], f_lhs+rhs[1]);
00333 }
00334 
00335 //------------------------------------------+-----------------------------------
00341 template <class T>
00342 inline CTB2vec<T> operator-(const CTB2vec<T>& lhs, const CTB2vec<T>& rhs)
00343 {
00344   return CTB2vec<T>(lhs[0]-rhs[0], lhs[1]-rhs[1]);
00345 }
00346 
00347 //------------------------------------------+-----------------------------------
00353 template <class T>
00354 inline CTB2vec<T> operator-(const CTB2vec<T>& lhs, T f_rhs)
00355 {
00356   return CTB2vec<T>(lhs[0]-f_rhs, lhs[1]-f_rhs);
00357 }
00358 
00359 //------------------------------------------+-----------------------------------
00365 template <class T>
00366   inline CTB2vec<T> operator-(T f_lhs, const CTB2vec<T>& rhs)
00367 {
00368   return CTB2vec<T>(f_lhs-rhs[0], f_lhs-rhs[1]);
00369 }
00370 
00371 //------------------------------------------+-----------------------------------
00377 template <class T>
00378 inline T operator*(const CTB2vec<T>& lhs, const CTB2vec<T>& rhs)
00379 {
00380   return lhs[0]*rhs[0] + lhs[1]*rhs[1];
00381 }
00382 
00383 //------------------------------------------+-----------------------------------
00389 template <class T>
00390 inline CTB2vec<T> operator*(const CTB2vec<T>& lhs, T f_rhs)
00391 {
00392   return CTB2vec<T>(lhs[0]*f_rhs, lhs[1]*f_rhs);
00393 }
00394 
00395 //------------------------------------------+-----------------------------------
00401 template <class T>
00402   inline CTB2vec<T> operator*(T f_lhs, const CTB2vec<T>& rhs)
00403 {
00404   return CTB2vec<T>(f_lhs*rhs[0], f_lhs*rhs[1]);
00405 }
00406 
00407 //------------------------------------------+-----------------------------------
00413 template <class T>
00414 inline CTB2vec<T> operator/(const CTB2vec<T>& lhs, T f_rhs)
00415 {
00416   return CTB2vec<T>(lhs[0]/f_rhs, lhs[1]/f_rhs);
00417 }
00418 
00419 //------------------------------------------+-----------------------------------
00425 template <class T>
00426 inline bool operator==(const CTB2vec<T>& lhs, const CTB2vec<T>& rhs)
00427 {
00428   return lhs[0] == rhs[0] && lhs[1] == rhs[1];
00429 }
00430 
00431 //------------------------------------------+-----------------------------------
00437 template <class T>
00438 inline bool operator==(const CTB2vec<T>& lhs, T f_rhs)
00439 {
00440   return lhs[0] == f_rhs && lhs[1] == f_rhs;
00441 }
00442 
00443 //------------------------------------------+-----------------------------------
00449 template <class T>
00450 inline bool operator==(T f_lhs, const CTB2vec<T>& rhs)
00451 {
00452   return f_lhs == rhs[0] && f_lhs == rhs[1];
00453 }
00454 
00455 //------------------------------------------+-----------------------------------
00461 template <class T>
00462 ostream& operator<<(ostream& os, const CTB2vec<T>& obj)
00463 {
00464   int i_width = os.width();
00465   os << setw(0) 
00466      << "{" << setw(i_width) << obj[0] 
00467      << "," << setw(i_width) << obj[1] << "}";
00468   return os;
00469 }
00470 
00471 //------------------------------------------+-----------------------------------
00477 template <class T>
00478 T CTBabs(const CTB2vec<T>& vec)
00479 {
00480   return vec.Length();
00481 }
00482 

Generated at Fri Oct 24 18:11:26 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001