00001 #ifndef __________animal_array_h_________________
00002 #define __________animal_array_h_________________
00003
00009 #include <iostream>
00010
00011 #include <animal/boost/array_boost.h>
00012
00013 #include <animal/linear.h>
00014 #include <animal/value.h>
00015
00016 namespace animal {
00017
00025 template<std::size_t N, class T>
00026 struct Array : public boost::array<T,N>
00027 {
00029 Array(){}
00030
00032 explicit Array( const T& t)
00033 {
00034 for( typename animal::Array<N,T>::size_type i=0; i<N; ++i )
00035 (*this)[i]=t;
00036 }
00037
00038
00040 Array( const T t[N])
00041 {
00042 for( typename animal::Array<N,T>::size_type i=0; i<N; ++i )
00043 (*this)[i]=t[i];
00044 }
00045
00047 Array( const T& x, const T& y )
00048 {
00049 assert( N==2 );
00050 (*this)[0] = x;
00051 (*this)[1] = y;
00052 }
00053
00055 Array( const T& x, const T& y, const T& z )
00056 {
00057 assert( N==3 );
00058 (*this)[0] = x;
00059 (*this)[1] = y;
00060 (*this)[2] = z;
00061 }
00062
00064 Array( const T& x, const T& y, const T& z, const T& t )
00065 {
00066 assert( N==4 );
00067 (*this)[0] = x;
00068 (*this)[1] = y;
00069 (*this)[2] = z;
00070 (*this)[3] = t;
00071 }
00072
00074 Array& operator += (const Array& v )
00075 {
00076 v_peq(*this,v);
00077 return (*this);
00078 }
00079
00081 Array& operator -= (const Array& v )
00082 {
00083 v_meq(*this,v);
00084 return (*this);
00085 }
00086
00088 Array& operator *= (const T& a )
00089 {
00090 v_teq(*this,a);
00091 return (*this);
00092 }
00093
00095 Array operator + (const Array& v ) const
00096 {
00097 Array w = (*this);
00098 w += v;
00099 return w;
00100 }
00101
00103 Array operator - (const Array& v ) const
00104 {
00105 Array w(*this);
00106 w -= v;
00107 return w;
00108 }
00109
00111 Array operator * ( const T& a ) const
00112 {
00113 Array w = (*this);
00114 v_teq(w,a);
00115 return w;
00116 }
00117
00119 friend Array operator* (const float a, const Array &u)
00120 {
00121 Array w = u;
00122 v_teq(w,a);
00123 return w;
00124 }
00125
00127 T operator * ( const Array& v ) const
00128 {
00129 return animal::v_dot(*this,v);
00130 }
00131
00133 Array operator - () const
00134 {
00135 Array w(*this);
00136 v_teq(w,-1);
00137 return w;
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 };
00150
00151
00152
00153
00155 template<class T,std::size_t N> inline
00156 Array<N,T> operator * ( const T& a, const Array<N,T>& v )
00157 {
00158 Array<N,T> w = v;
00159 v_teq(w,a);
00160 return w;
00161 }
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00173 template<class T, std::size_t N>
00174 std::ostream& operator << ( std::ostream& out, const Array<N,T>& a )
00175 {
00176 typename Array<N,T>::const_iterator i,iend;
00177 for( i=a.begin(), iend=a.end(); i!=iend; ++i )
00178 out << *i << " ";
00179 return out;
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00192 template<class T, std::size_t N>
00193 std::istream& operator >> ( std::istream& in, Array<N,T>& a )
00194 {
00195 typename Array<N,T>::iterator i,iend;
00196 for( i=a.begin(), iend=a.end(); i!=iend; ++i )
00197 in >> *i;
00198 return in;
00199 }
00200
00201
00203
00204
00205
00206
00207
00208
00209 template<typename T,std::size_t N>
00210 struct Value< Array<N,T> >
00211 {
00212 static inline animal::Array<N,T> zero(){ return animal::Array<N,T>( animal::Value<T>::zero() ); }
00213 };
00214
00215 }
00216
00218 template<class T,int N> inline
00219 animal::Array<N,T> cross( const animal::Array<N,T>& v, const animal::Array<N,T>& w )
00220 {
00221 animal::Array<N,T> u;
00222 animal::v_eq_cross(u,v,w);
00223 return u;
00224 }
00225
00227 template<class T,int N> inline
00228 T dot( const animal::Array<N,T>& v, const animal::Array<N,T>& w )
00229 {
00230 return animal::v_dot(v,w);
00231 }
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 #endif