00001 // marVector.h: interface for the marVector class. 00002 // 00004 00005 #include <iostream> 00006 #include <stddef.h> 00007 class marVector 00008 { 00009 public: 00010 /* 00011 Remarque : les (double*) sont organisés ligne par ligne 00012 */ 00013 /*==Constructeurs========================================*/ 00014 marVector(size_t s=3); 00015 marVector(double* v,size_t s); 00016 marVector(const marVector & v); 00017 /*==Destructeur========================================*/ 00018 virtual ~marVector(); 00019 00020 /*==Opérateurs========================================*/ 00021 /* Affectation */ 00022 marVector& operator=(const marVector& o); 00023 marVector& operator=(double o); 00024 marVector& operator=(double* o); 00025 00026 /* Affichage */ 00027 friend std::ostream& operator<<(std::ostream& os, const marVector& v); 00028 00029 /* Casting */ 00030 operator double*() const ; 00031 00032 /* Indexation */ 00033 double& operator()(size_t i); 00034 const double& operator()(size_t i) const; 00035 00036 /* Comparaison */ 00037 bool operator==(const marVector& o) const; 00038 bool operator!=(const marVector& o) const; 00039 00040 /* Addition */ 00041 marVector operator+(const marVector& o); 00042 marVector operator+(double o); 00043 marVector operator+(double* o); 00044 /* Addition + Affectation */ 00045 marVector& operator+=(const marVector& o); 00046 marVector& operator+=(double o); 00047 marVector& operator+=(double* o); 00048 00049 /* Soustraction */ 00050 marVector operator-(const marVector& o); 00051 marVector operator-(double o); 00052 marVector operator-(double* o); 00053 /* Soustraction + Affectation */ 00054 marVector& operator-=(const marVector& o); 00055 marVector& operator-=(double o); 00056 marVector& operator-=(double* o); 00057 00058 /* Multiplication (produit scalaire) */ 00059 marVector operator*(double o); 00060 /* Multiplication (produit scalaire) + Affectation */ 00061 marVector& operator*=(double o); 00062 00063 /* Division (division scalaire) */ 00064 marVector operator/(double o); 00065 /* Division (division scalaire) + Affectation */ 00066 marVector& operator/=(double o); 00067 00068 /*==Opérations========================================*/ 00069 /* produit scalaire */ 00070 double dot( const marVector& o ); 00071 double dot( double* o ); 00072 00073 /* produit vectoriel (3D uniquement): le resultat est renvoye */ 00074 marVector cross( const marVector& o ); 00075 marVector cross( double* o ); 00076 /* produit vectoriel (3D uniquement): le resultat est stocké dans this*/ 00077 int scross( const marVector& o ); // renvoie 0 si OK, 1 sinon 00078 int scross( double* o ); // renvoie 0 si OK, 1 sinon 00079 00080 /* norme euclidienne */ 00081 double norm2( ); 00082 00083 /* normalisation */ 00084 marVector normalize( ); // resultat renvoyé 00085 int snormalize( ); // resultat stocké dans this, renvoie 0 si OK, 1 sinon 00086 00087 /*==Méthodes========================================*/ 00088 size_t size() const; 00089 00090 /*==Attributs========================================*/ 00091 private: 00092 bool shallowCopy; // true if _data is a shallow copy of original data (pointer copy) 00093 size_t _size; 00094 double* _data; 00095 }; 00096 00097