shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/include/shape/ssi_fsvector.hpp
Go to the documentation of this file.
00001 #ifndef GEOM_FSVECTOR_H
00002 #define GEOM_FSVECTOR_H
00003 #include "patterns.h"
00004 //----------------------------------------------------------------------------
00005 //                          fsvector: Fixed Size Vector
00006 //----------------------------------------------------------------------------
00007 template <class K, unsigned n > 
00008 struct fsvector
00009 {
00010   typedef K               field;
00011   typedef K               value_type;
00012   typedef unsigned        size_type;
00013   typedef unsigned        index_t;
00014   static const  int dimension = n;
00015   K _data[n];
00016   public:
00017   const K  *  data() const { return _data; };
00018   const unsigned  size() const { return     n; };
00019   //                                 contructors
00020   // static const int dimension() { return n; };
00021   fsvector();
00022   fsvector( const K& k    )                     ; // coordinates are set to k 
00023   fsvector( const K * src )                     ; // values are copied from src
00024   //  fsvector( const K[n] );
00025   //                                  accessors
00026   K&       operator[]( unsigned i )            ; // read  access to coordinate i
00027   const K& operator[]( unsigned i ) const      ; // write access to coordinate i
00028   K * begin() { return &(_data[0]); };
00029 
00030   //                           vector space operations
00031   
00032   fsvector& operator+=( const fsvector& v )      ; // add       v  to vector 
00033   fsvector& operator-=( const fsvector& v )      ; // substract v  to vector
00034   fsvector& operator*=( const K& k  )           ; // multiply all coordinates by k
00035   fsvector& operator/=( const K& k  )           ; // divide   all coordinates by k
00036   fsvector& operator/=( const fsvector& v )      ; // project on v space
00037   fsvector& operator%=( const fsvector& v )      ; // project on v orthogonal space
00038   
00039   fsvector  operator-(                    ) const; // return -vector
00040   fsvector  operator+( const fsvector& v  ) const; // return vector + v
00041   fsvector  operator-( const fsvector& v  ) const; // return vector - v
00042   
00043 
00044   K        operator*( const fsvector& v  ) const; // return the dotproduct vector*v
00045   
00046   fsvector  operator^( const fsvector& v  ) const; // cross-product 
00047 
00048 };
00049 
00050 //                                     functions
00051 
00052 //                                  comparisons (lex order)
00053 
00054 template<class K, unsigned n>
00055 inline bool operator< ( const fsvector<K,n>& v0, const fsvector<K,n>& v1 )
00056 { return lexicographic_comp(v0,v1,n,n,1,1) == -1; };
00057 template<class K, unsigned n>
00058 inline bool operator<=( const fsvector<K,n>& v0, const fsvector<K,n>& v1 )
00059 { return lexicographic_comp(v0,v1,n,n,1,1) <=  0; };
00060 template<class K, unsigned n>
00061 inline bool operator> ( const fsvector<K,n>& v0, const fsvector<K,n>& v1 )
00062 { return lexicographic_comp(v0,v1,n,n,1,1) ==  1;  };
00063 template<class K, unsigned n>
00064 inline bool operator>=( const fsvector<K,n>& v0, const fsvector<K,n>& v1 )
00065 { return lexicographic_comp(v0,v1,n,n,1,1) >=  0;  };
00066 
00067 //                                    norms
00068 template<class K, unsigned n> inline K 
00069 norm_euc( const fsvector<K,n>& v )
00070 {
00071   K r;
00072   patterns::norm_euc(r,v,n,1); 
00073   return r;
00074 };
00075 
00076 template<class K,unsigned n> inline void 
00077 norm_euc( K& r, const fsvector<K,n>& v )
00078 { norm_euc( r, v, n,1  ); };
00079 template<class K,unsigned n> inline void
00080 norm_max( K& r, const fsvector<K,n>& v )
00081 { norm_max(r,v, n,1); };
00082 
00083 //                                 constructors
00084 
00085 template<class K,unsigned n>
00086 inline
00087 fsvector<K,n>::fsvector<K,n>(){};
00088 
00089 template<class K,unsigned n>
00090 inline
00091 fsvector<K,n>::fsvector<K,n>( const K& k )
00092 { 
00093   patterns::fill(*this,k,n);
00094 };
00095 
00096 template<class K,unsigned n>
00097 inline
00098 fsvector<K,n>::fsvector<K,n>( const K * src )
00099 { 
00100   patterns::copy(*this,src,n);
00101 };
00102 
00103 template<class K,unsigned n>
00104 inline K& 
00105 fsvector<K,n>::operator[]( unsigned i )
00106 {
00107   return _data[i];
00108 };
00109 
00110 template<class K,unsigned n>
00111 inline const K& 
00112 fsvector<K,n>::operator[]( unsigned i ) const
00113 {
00114   return _data[i];
00115 };
00116 
00117 //                            vector space operations
00118 
00119 template<class K,unsigned n>
00120 inline fsvector<K,n>& 
00121 fsvector<K,n>::operator+=( const fsvector& v )
00122 {
00123   patterns::padd1(*this,v,n);
00124   return (*this);
00125 };
00126 
00127 template<class K,unsigned n>
00128 inline fsvector<K,n>& 
00129 fsvector<K,n>::operator-=( const fsvector& v )
00130 {
00131   patterns::psub1(*this,v,n);
00132   return (*this);
00133 };
00134 
00135 template<class K,unsigned n>
00136 inline fsvector<K,n>& 
00137 fsvector<K,n>::operator*=( const K& k )
00138 {
00139   patterns::smul1(*this,k,n);
00140   return (*this);
00141 };
00142 
00143 template<class K,unsigned n>
00144 inline fsvector<K,n>& 
00145 fsvector<K,n>::operator/=( const K& k )
00146 {
00147   patterns::sdiv1(*this,k,n);
00148   return (*this);
00149 };
00150 
00151 template<class K,unsigned n>
00152 inline fsvector<K,n> 
00153 fsvector<K,n>::operator-() const
00154 {
00155   fsvector<K,n> temp;
00156   patterns::neg2(temp,*this,n);
00157   return temp;
00158 };
00159 
00160 template<class K,unsigned n>
00161 inline fsvector<K,n> 
00162 fsvector<K,n>::operator+( const fsvector<K,n>& v ) const
00163 {
00164   fsvector<K,n> temp;
00165   patterns::padd2(temp,*this,v,n);
00166   return temp;
00167 };
00168 
00169 template<class K,unsigned n>
00170 inline fsvector<K,n> 
00171 fsvector<K,n>::operator-( const fsvector<K,n>& v ) const
00172 {
00173   fsvector<K,n> temp;
00174   patterns::psub2(temp,*this,v,n);
00175   return temp;
00176 };
00177 
00178 template<class K,unsigned n>
00179 inline K fsvector<K,n>::operator*( const fsvector<K,n>& v ) const 
00180 {
00181   K temp;
00182   patterns::dot(temp,*this,v,n);
00183   return temp;
00184 };
00185 
00186 template<class K,unsigned n>
00187 inline void crossprod( fsvector<K,n>& res, 
00188                        const fsvector<K,n>& a, const fsvector<K,n>& b )
00189 { patterns::cross(res,a,b,n); };
00190 
00191 
00192 template<class K,unsigned n>
00193 inline fsvector<K,n> 
00194 fsvector<K,n>::operator^( const fsvector<K,n>& v ) const
00195 {
00196   fsvector<K,n> temp;
00197   crossprod(  temp, *this, v );
00198   return temp;
00199 };
00200  
00201 template<class K,unsigned n>
00202 inline fsvector<K,n> 
00203 operator*( const K& k, const fsvector<K,n>& v )
00204 {
00205   fsvector<K,n> temp;
00206   patterns::smul2(temp,v,k,n);
00207   return temp;
00208 };
00209 
00210 template<class K,unsigned n>
00211 inline fsvector<K,n> 
00212 operator*( const fsvector<K,n>& v, const K& k )
00213 {
00214   fsvector<K,n> temp;
00215   patterns::smul2(temp,v,k,n);
00216   return temp;
00217 };
00218 
00219 template<class K,unsigned n>
00220 inline fsvector<K,n> 
00221 operator/( const fsvector<K,n>& v, const K& k )
00222 {
00223   fsvector<K,n> temp;
00224   patterns::sdiv2(temp,v,k,n);
00225   return temp;
00226 };
00227 
00228 template<class K,unsigned n>
00229 inline std::ostream& 
00230 operator<<( std::ostream& out, const fsvector<K,n>& v )
00231 {
00232    out << "( ";
00233    for ( unsigned i = 0; i < n; i++ )
00234      out << v[i] << " ";
00235    out << ')';
00236    return out;
00237 };
00238 
00239 
00240 template<class K,unsigned n>
00241 inline K norm_max( const fsvector<K,n>& v )
00242 {
00243   K temp;
00244   patterns::norm_max(temp,v,n,1);
00245   return temp;
00246 };
00247 
00248 #ifndef PIPO
00249 template< class number, unsigned size >
00250 inline void 
00251 scale( fsvector< number, size >& v, const fsvector< number, size>& s )
00252 { patterns::pmul1( v.data(), s.data(), size ); };
00253 
00254 template< class number, unsigned size >
00255 inline void
00256 inv  ( fsvector< number, size >& v )
00257 { patterns::inv1( v.data(), size ); };
00258 #endif
00259 #endif
00260 
00261 
00262 
00263