Wm4TRVector.inl

Go to the documentation of this file.
00001 // Wild Magic Source Code
00002 // David Eberly
00003 // http://www.geometrictools.com
00004 // Copyright (c) 1998-2007
00005 //
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Lesser General Public License as published by
00008 // the Free Software Foundation; either version 2.1 of the License, or (at
00009 // your option) any later version.  The license is available for reading at
00010 // either of the locations:
00011 //     http://www.gnu.org/copyleft/lgpl.html
00012 //     http://www.geometrictools.com/License/WildMagicLicense.pdf
00013 // The license applies to versions 0 through 4 of Wild Magic.
00014 //
00015 // Version: 4.0.0 (2006/06/28)
00016 
00017 namespace Wm4
00018 {
00019 //----------------------------------------------------------------------------
00020 template <int VSIZE, int ISIZE>
00021 TRVector<VSIZE,ISIZE>::TRVector ()
00022 {
00023     // For efficiency in construction of large arrays of vectors, the
00024     // default constructor does not initialize the vector.
00025 }
00026 //----------------------------------------------------------------------------
00027 template <int VSIZE, int ISIZE>
00028 TRVector<VSIZE,ISIZE>::TRVector (const TRVector& rkV)
00029 {
00030     for (int i = 0; i < VSIZE; i++)
00031     {
00032         m_akTuple[i] = rkV.m_akTuple[i];
00033     }
00034 }
00035 //----------------------------------------------------------------------------
00036 template <int VSIZE, int ISIZE>
00037 TRVector<VSIZE,ISIZE>::operator const TRational<ISIZE>* () const
00038 {
00039     return m_akTuple;
00040 }
00041 //----------------------------------------------------------------------------
00042 template <int VSIZE, int ISIZE>
00043 TRVector<VSIZE,ISIZE>::operator TRational<ISIZE>* ()
00044 {
00045     return m_akTuple;
00046 }
00047 //----------------------------------------------------------------------------
00048 template <int VSIZE, int ISIZE>
00049 TRational<ISIZE> TRVector<VSIZE,ISIZE>::operator[] (int i) const
00050 {
00051     assert(0 <= i && i < VSIZE);
00052     return m_akTuple[i];
00053 }
00054 //----------------------------------------------------------------------------
00055 template <int VSIZE, int ISIZE>
00056 TRational<ISIZE>& TRVector<VSIZE,ISIZE>::operator[] (int i)
00057 {
00058     assert(0 <= i && i < VSIZE);
00059     return m_akTuple[i];
00060 }
00061 //----------------------------------------------------------------------------
00062 template <int VSIZE, int ISIZE>
00063 TRVector<VSIZE,ISIZE>& TRVector<VSIZE,ISIZE>::operator= (const TRVector& rkV)
00064 {
00065     for (int i = 0; i < VSIZE; i++)
00066     {
00067         m_akTuple[i] = rkV.m_akTuple[i];
00068     }
00069     return *this;
00070 }
00071 //----------------------------------------------------------------------------
00072 template <int VSIZE, int ISIZE>
00073 bool TRVector<VSIZE,ISIZE>::operator== (const TRVector& rkV) const
00074 {
00075     for (int i = 0; i < VSIZE; i++)
00076     {
00077         if (m_akTuple[i] != rkV.m_akTuple[i])
00078         {
00079             return false;
00080         }
00081     }
00082     return true;
00083 }
00084 //----------------------------------------------------------------------------
00085 template <int VSIZE, int ISIZE>
00086 bool TRVector<VSIZE,ISIZE>::operator!= (const TRVector& rkV) const
00087 {
00088     return !operator==(rkV);
00089 }
00090 //----------------------------------------------------------------------------
00091 template <int VSIZE, int ISIZE>
00092 int TRVector<VSIZE,ISIZE>::CompareArrays (const TRVector& rkV) const
00093 {
00094     for (int i = 0; i < VSIZE; i++)
00095     {
00096         if (m_akTuple[i] < rkV.m_akTuple[i])
00097         {
00098             return -1;
00099         }
00100         if (m_akTuple[i] > rkV.m_akTuple[i])
00101         {
00102             return +1;
00103         }
00104     }
00105     return 0;
00106 }
00107 //----------------------------------------------------------------------------
00108 template <int VSIZE, int ISIZE>
00109 bool TRVector<VSIZE,ISIZE>::operator< (const TRVector& rkV) const
00110 {
00111     return CompareArrays(rkV) < 0;
00112 }
00113 //----------------------------------------------------------------------------
00114 template <int VSIZE, int ISIZE>
00115 bool TRVector<VSIZE,ISIZE>::operator<= (const TRVector& rkV) const
00116 {
00117     return CompareArrays(rkV) <= 0;
00118 }
00119 //----------------------------------------------------------------------------
00120 template <int VSIZE, int ISIZE>
00121 bool TRVector<VSIZE,ISIZE>::operator> (const TRVector& rkV) const
00122 {
00123     return CompareArrays(rkV) > 0;
00124 }
00125 //----------------------------------------------------------------------------
00126 template <int VSIZE, int ISIZE>
00127 bool TRVector<VSIZE,ISIZE>::operator>= (const TRVector& rkV) const
00128 {
00129     return CompareArrays(rkV) >= 0;
00130 }
00131 //----------------------------------------------------------------------------
00132 template <int VSIZE, int ISIZE>
00133 TRVector<VSIZE,ISIZE> TRVector<VSIZE,ISIZE>::operator+ (const TRVector& rkV)
00134     const
00135 {
00136     TRVector<VSIZE,ISIZE> kSum;
00137     for (int i = 0; i < VSIZE; i++)
00138     {
00139         kSum.m_akTuple[i] = m_akTuple[i] + rkV.m_akTuple[i];
00140     }
00141     return kSum;
00142 }
00143 //----------------------------------------------------------------------------
00144 template <int VSIZE, int ISIZE>
00145 TRVector<VSIZE,ISIZE> TRVector<VSIZE,ISIZE>::operator- (const TRVector& rkV)
00146     const
00147 {
00148     TRVector<VSIZE,ISIZE> kDiff;
00149     for (int i = 0; i < VSIZE; i++)
00150     {
00151         kDiff.m_akTuple[i] = m_akTuple[i] - rkV.m_akTuple[i];
00152     }
00153     return kDiff;
00154 }
00155 //----------------------------------------------------------------------------
00156 template <int VSIZE, int ISIZE>
00157 TRVector<VSIZE,ISIZE> TRVector<VSIZE,ISIZE>::operator*
00158     (const TRational<ISIZE>& rkR) const
00159 {
00160     TRVector<VSIZE,ISIZE> kProd;
00161     for (int i = 0; i < VSIZE; i++)
00162     {
00163         kProd.m_akTuple[i] = rkR*m_akTuple[i];
00164     }
00165     return kProd;
00166 }
00167 //----------------------------------------------------------------------------
00168 template <int VSIZE, int ISIZE>
00169 TRVector<VSIZE,ISIZE> TRVector<VSIZE,ISIZE>::operator/
00170     (const TRational<ISIZE>& rkR) const
00171 {
00172     assert(rkR != 0);
00173 
00174     TRVector<VSIZE,ISIZE> kProd;
00175     for (int i = 0; i < VSIZE; i++)
00176     {
00177         kProd.m_akTuple[i] = m_akTuple[i]/rkR;
00178     }
00179 
00180     return kProd;
00181 }
00182 //----------------------------------------------------------------------------
00183 template <int VSIZE, int ISIZE>
00184 TRVector<VSIZE,ISIZE> TRVector<VSIZE,ISIZE>::operator- () const
00185 {
00186     TRVector<VSIZE,ISIZE> kNeg;
00187     for (int i = 0; i < VSIZE; i++)
00188     {
00189         kNeg.m_akTuple[i] = -m_akTuple[i];
00190     }
00191     return kNeg;
00192 }
00193 //----------------------------------------------------------------------------
00194 template <int VSIZE, int ISIZE>
00195 TRVector<VSIZE,ISIZE> operator* (const TRational<ISIZE>& rkR,
00196     const TRVector<VSIZE,ISIZE>& rkV)
00197 {
00198     TRVector<VSIZE,ISIZE> kProd;
00199     for (int i = 0; i < VSIZE; i++)
00200     {
00201         kProd[i] = rkR*rkV[i];
00202     }
00203     return kProd;
00204 }
00205 //----------------------------------------------------------------------------
00206 template <int VSIZE, int ISIZE>
00207 TRVector<VSIZE,ISIZE>& TRVector<VSIZE,ISIZE>::operator+= (const TRVector& rkV)
00208 {
00209     for (int i = 0; i < VSIZE; i++)
00210     {
00211         m_akTuple[i] += rkV.m_akTuple[i];
00212     }
00213     return *this;
00214 }
00215 //----------------------------------------------------------------------------
00216 template <int VSIZE, int ISIZE>
00217 TRVector<VSIZE,ISIZE>& TRVector<VSIZE,ISIZE>::operator-= (const TRVector& rkV)
00218 {
00219     for (int i = 0; i < VSIZE; i++)
00220     {
00221         m_akTuple[i] -= rkV.m_akTuple[i];
00222     }
00223     return *this;
00224 }
00225 //----------------------------------------------------------------------------
00226 template <int VSIZE, int ISIZE>
00227 TRVector<VSIZE,ISIZE>& TRVector<VSIZE,ISIZE>::operator*=
00228     (const TRational<ISIZE>& rkR)
00229 {
00230     for (int i = 0; i < VSIZE; i++)
00231     {
00232         m_akTuple[i] *= rkR;
00233     }
00234     return *this;
00235 }
00236 //----------------------------------------------------------------------------
00237 template <int VSIZE, int ISIZE>
00238 TRVector<VSIZE,ISIZE>& TRVector<VSIZE,ISIZE>::operator/=
00239     (const TRational<ISIZE>& rkR)
00240 {
00241     assert(rkR != 0);
00242     for (int i = 0; i < VSIZE; i++)
00243     {
00244         m_akTuple[i] /= rkR;
00245     }
00246     return *this;
00247 }
00248 //----------------------------------------------------------------------------
00249 template <int VSIZE, int ISIZE>
00250 TRational<ISIZE> TRVector<VSIZE,ISIZE>::SquaredLength () const
00251 {
00252     TRational<ISIZE> kSqrLen = 0;
00253     for (int i = 0; i < VSIZE; i++)
00254     {
00255         kSqrLen += m_akTuple[i]*m_akTuple[i];
00256     }
00257     return kSqrLen;
00258 }
00259 //----------------------------------------------------------------------------
00260 template <int VSIZE, int ISIZE>
00261 TRational<ISIZE> TRVector<VSIZE,ISIZE>::Dot (const TRVector& rkV) const
00262 {
00263     TRational<ISIZE> kDot = 0;
00264     for (int i = 0; i < VSIZE; i++)
00265     {
00266         kDot += m_akTuple[i]*rkV.m_akTuple[i];
00267     }
00268     return kDot;
00269 }
00270 //----------------------------------------------------------------------------
00271 } //namespace Wm4

Generated on Wed Nov 23 19:01:10 2011 for FreeCAD by  doxygen 1.6.1