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 #ifndef WM4TRVECTOR_H 00018 #define WM4TRVECTOR_H 00019 00020 #include "Wm4FoundationLIB.h" 00021 #include "Wm4TRational.h" 00022 00023 namespace Wm4 00024 { 00025 00026 template <int VSIZE, int ISIZE> 00027 class TRVector 00028 { 00029 public: 00030 // construction 00031 TRVector (); 00032 TRVector (const TRVector& rkV); 00033 00034 // coordinate access 00035 operator const TRational<ISIZE>* () const; 00036 operator TRational<ISIZE>* (); 00037 TRational<ISIZE> operator[] (int i) const; 00038 TRational<ISIZE>& operator[] (int i); 00039 00040 // assignment 00041 TRVector& operator= (const TRVector& rkV); 00042 00043 // comparison 00044 bool operator== (const TRVector& rkV) const; 00045 bool operator!= (const TRVector& rkV) const; 00046 bool operator< (const TRVector& rkV) const; 00047 bool operator<= (const TRVector& rkV) const; 00048 bool operator> (const TRVector& rkV) const; 00049 bool operator>= (const TRVector& rkV) const; 00050 00051 // arithmetic operations 00052 TRVector operator+ (const TRVector& rkV) const; 00053 TRVector operator- (const TRVector& rkV) const; 00054 TRVector operator* (const TRational<ISIZE>& rkR) const; 00055 TRVector operator/ (const TRational<ISIZE>& rkR) const; 00056 TRVector operator- () const; 00057 00058 // arithmetic updates 00059 TRVector& operator+= (const TRVector& rkV); 00060 TRVector& operator-= (const TRVector& rkV); 00061 TRVector& operator*= (const TRational<ISIZE>& rkR); 00062 TRVector& operator/= (const TRational<ISIZE>& rkR); 00063 00064 // vector operations 00065 TRational<ISIZE> SquaredLength () const; 00066 TRational<ISIZE> Dot (const TRVector& rkV) const; 00067 00068 protected: 00069 // support for comparisons 00070 int CompareArrays (const TRVector& rkV) const; 00071 00072 TRational<ISIZE> m_akTuple[VSIZE]; 00073 }; 00074 00075 template <int VSIZE, int ISIZE> 00076 TRVector<VSIZE,ISIZE> operator* (const TRational<ISIZE>& rkR, 00077 const TRVector<VSIZE,ISIZE>& rkV); 00078 00079 } 00080 00081 #include "Wm4TRVector.inl" 00082 00083 #endif