Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

vec.inl

Go to the documentation of this file.
00001 /* --------------------------------------------------------------- *\
00002 
00003    file: vec.inl
00004    date: 030825 22:16:28
00005 
00006    author:
00007 
00008       mathias gumz <gumz at cs.uni-magdeburg.de>
00009 
00010    license:
00011 
00012       see LICENSE.txt
00013 
00014    about:
00015 
00016       generic vector class
00017 
00018 \* --------------------------------------------------------------- */
00019 
00020 
00021 /* --------------------------------------------------------------- *\
00022     definitions of Vec
00023 \* --------------------------------------------------------------- */
00024 template<typename T, int S> inline
00025 typename Vec<T, S>::VecType& Vec<T, S>::operator=(typename Vec<T, S>::ConstValType& scalar)
00026 {
00027   return vector::assign(*this, scalar);
00028 }
00029 
00030 template<typename T, int S> inline
00031 typename Vec<T, S>::VecType& Vec<T, S>::operator=(typename Vec<T, S>::ConstValTypePtr valptr)
00032 {
00033   return vector::assign(*this, valptr);
00034 }
00035 
00036 template<typename T, int S> inline
00037 typename Vec<T, S>::VecType& Vec<T, S>::operator=(typename Vec<T, S>::ConstVecType& vec)
00038 {
00039    return vector::assign(*this, vec);
00040 }
00041 
00042 
00043 
00044 
00045 
00046 template<typename T, int S> inline
00047 typename Vec<T, S>::VecType& Vec<T, S>::operator+=(typename Vec<T, S>::ConstVecType& vec)
00048 {
00049   return vector::addOnSpot(*this, vec);
00050 }
00051 
00052 template<typename T, int S> inline
00053 typename Vec<T, S>::VecType& Vec<T, S>::operator-=(typename Vec<T, S>::ConstVecType& vec)
00054 {
00055   return vector::subOnSpot(*this, vec);
00056 }
00057 
00058 
00059 template<typename T, int S> inline
00060 typename Vec<T, S>::VecType& Vec<T, S>::operator*=(typename Vec<T, S>::ConstValType& scalar)
00061 {
00062   return vector::multOnSpot(*this,scalar);
00063 }
00064 
00065 template<typename T, int S> inline
00066 typename Vec<T, S>::VecType& Vec<T, S>::operator/=(typename Vec<T, S>::ConstValType& scalar)
00067 {
00068   return vector::divideOnSpot(*this, scalar);
00069 }
00070 
00071 template<typename T, int S> inline
00072 typename Vec<T, S>::VecType Vec<T, S>::operator+(typename Vec<T, S>::ConstVecType& vec) const
00073 {
00074   return vector::add(*this, vec);
00075 }
00076 
00077 template<typename T, int S> inline
00078 typename Vec<T, S>::VecType Vec<T, S>::operator-(typename Vec<T, S>::ConstVecType& vec) const
00079 {
00080   return vector::sub(*this, vec);
00081 }
00082 
00083 template<typename T, int S> inline
00084 typename Vec<T, S>::VecType Vec<T, S>::operator*(typename Vec<T, S>::ConstValType& scalar) const
00085 {
00086   return vector::mult(*this, scalar);
00087 }
00088 
00089 template<typename T, int S> inline
00090 typename Vec<T, S>::VecType Vec<T, S>::operator/(typename Vec<T, S>::ConstValType& scalar) const
00091 {
00092   return vector::divide(*this, scalar);
00093 }
00094 
00095 
00096 template<typename T, int S> inline
00097 T Vec<T, S>::norm2() const
00098 {
00099   T n= Vec<T, S>::ValTrait::zero();
00100   for(typename Vec<T, S>::ConstValTypePtr pv= begin(); pv != end(); pv++)
00101       n+= *pv * *pv;
00102   return n;
00103 }
00104 
00105 template<typename T, int S> inline
00106 T Vec<T, S>::norm() const
00107 {
00108   return sqrt(norm2());
00109 }
00110 
00111 template<typename T, int S> inline
00112 typename Vec<T, S>::VecType& Vec<T, S>::normalize()
00113 {
00114   return operator*=(Vec<T, S>::ValTrait::one()/norm());
00115 }
00116 
00117 
00118 /* --------------------------------------------------------------- *\
00119     special stuff only valid for vec3
00120 \* --------------------------------------------------------------- */
00121 
00122 template<typename T, int S>
00123 Vec<T, S>::Vec(ConstValType& x, ConstValType& y, ConstValType& z)
00124 {
00125   STATIC_CHECK(S == 3, Constructor_Is_Only_Valid_For_Vec3);
00126   val[0]= x; val[1]= y; val[2]= z;
00127 }
00128 
00129 /* --------------------------------------------------------------- *\
00130     functions for vector::
00131 \* --------------------------------------------------------------- */
00132 template<typename T, int S> inline
00133 Vec<T, S>& vector::assign(Vec<T, S>& v, const T& scalar)
00134 {
00135   for(T* i= v.begin(); i != v.end(); )
00136     *i++= scalar;
00137   return v;
00138 }
00139 
00140 template<typename T, int S> inline
00141 Vec<T, S>& vector::assign(Vec<T, S>& v, const T* valptr)
00142 {
00143   for(T* i= v.begin(); i != v.end(); )
00144     *i++= *valptr++;
00145   return v;
00146 }
00147 
00148 template<typename T, int S> inline
00149 Vec<T, S>& vector::assign(Vec<T, S>& v, const Vec<T, S>& vec)
00150 {
00151   const T* valptr= vec.begin();
00152   for(T* i= v.begin(); i != v.end(); )
00153     *i++= *valptr++;
00154   return v;
00155 }
00156 
00157 
00158 
00159 
00160 
00161 template<typename T, int S> inline
00162 Vec<T, S> vector::add(const Vec<T, S>& v, const Vec<T, S>& vec)
00163 {
00164   Vec<T, S> r(v);
00165   return vector::addOnSpot(r, vec);
00166 }
00167 
00168 template<typename T, int S> inline
00169 Vec<T, S>& vector::addOnSpot(Vec<T, S>& v, const Vec<T, S>& vec)
00170 {
00171   const T* valptr= vec.begin();
00172   for(T* i= v.begin(); i != v.end(); )
00173     *i++ += *valptr++;
00174   return v;
00175 }
00176 
00177 template<typename T, int S> inline
00178 Vec<T, S> vector::sub(const Vec<T, S>& v, const Vec<T, S>& vec)
00179 {
00180   Vec<T, S> r(v);
00181   return vector::subOnSpot(r, vec);
00182 }
00183 
00184 template<typename T, int S> inline
00185 Vec<T, S>& vector::subOnSpot(Vec<T, S>& v, const Vec<T, S>& vec)
00186 {
00187   const T* valptr= vec.begin();
00188   for(T* i= v.begin(); i != v.end(); )
00189     *i++ -= *valptr++;
00190   return v;
00191 }
00192 
00193 
00194 template<typename T, int S> inline
00195 Vec<T, S> vector::mult(const Vec<T, S>& v, const T& scalar)
00196 {
00197   Vec<T, S> r(v);
00198   return vector::multOnSpot(r, scalar);
00199 }
00200 
00201 template<typename T, int S> inline
00202 Vec<T, S>& vector::multOnSpot(Vec<T, S>& v, const T& scalar)
00203 {
00204   for(T* i= v.begin(); i != v.end(); )
00205     *i++ *= scalar;
00206   return v;
00207 }
00208 template<typename T, int S> inline
00209 Vec<T, S> vector::divide(const Vec<T, S>& v, const T& scalar)
00210 {
00211   Vec<T, S> r(v);
00212   return vector::multOnSpot(r, scalar);
00213 }
00214 
00215 template<typename T, int S> inline
00216 Vec<T, S>& vector::divideOnSpot(Vec<T, S>& v, const T& scalar)
00217 {
00218   for(T* i= v.begin(); i != v.end(); )
00219     *i++ /= scalar;
00220   return v;
00221 }
00222 
00223 
00224 
00225 /* --------------------------------------------------------------- *\
00226 \* --------------------------------------------------------------- */
00227 
00228 /* -- emacs - settings ------------------------------------------- *\
00229    ;;; Local Variables: ***
00230    ;;; mode:C++ ***
00231    ;;; c-basic-offset:2 ***
00232    ;;; End: ***
00233 \* --------------------------------------------------------------- */
00234 /* -- vim - settings --------------------------------------------- *\
00235   vim:set ft=cpp ts=2 ss=2:
00236 \* --------------------------------------------------------------- */
00237 

Generated on Tue Sep 2 11:33:27 2003 for math by doxygen 1.3.2