Page principale | Hiérarchie des classes | Liste des classes | Liste des fichiers | Membres de classe | Membres de fichier

FVector.cpp

Aller à la documentation de ce fichier.
00001 /// \file 00002 /// Implémentation de la classe FVector 00003 #include "FVector.hpp" 00004 /////////////////////////////////////////////////////////////////////////////// 00005 /// FVector 00006 /////////////////////////////////////////////////////////////////////////////// 00007 FVector::FVector(){ 00008 p = new FVector_Base(); 00009 } 00010 FVector::FVector(float x, float y, float h, float s, float v){ 00011 p = new FVector_Base(x, y, h, s, v); 00012 } 00013 FVector::FVector(const FVector& vector){ 00014 p = vector.p; 00015 ++p->use; 00016 } 00017 FVector& FVector::operator=(const FVector& rhs){ 00018 rhs.p->use++; 00019 if(--p->use == 0){ 00020 delete p; 00021 } 00022 p = rhs.p; 00023 return *this; 00024 } 00025 FVector::~FVector(){ 00026 if(--p->use == 0){ 00027 delete p; 00028 } 00029 } 00030 string FVector::toString()const{ 00031 return p->toString(); 00032 } 00033 int FVector::getX() const{ 00034 return p->getX(); 00035 } 00036 int FVector::getY() const{ 00037 return p->getY(); 00038 } 00039 float FVector::operator[](int i) const{ 00040 return p->operator[](i); 00041 } 00042 FVector& FVector::operator+=(const FVector& v){ 00043 p->operator+=(v.p); 00044 return *this; 00045 } 00046 FVector& FVector::operator/=(const float& f){ 00047 p->operator/=(f); 00048 return *this; 00049 } 00050 bool FVector::operator<(const FVector rhs)const{ 00051 return p->operator<(rhs.p); 00052 } 00053 00054 float norm(const FVector& a, const FVector& b){ 00055 return norm(*a.p, *b.p); 00056 } 00057 float normColor(const FVector& a, const FVector& b){ 00058 return normColor(*a.p, *b.p); 00059 } 00060 /////////////////////////////////////////////////////////////////////////////// 00061 /// FVector_Base 00062 /////////////////////////////////////////////////////////////////////////////// 00063 const int FVector_Base::dim = 5; 00064 FVector_Base::FVector_Base():use(1){ 00065 data = new float[dim]; 00066 for(int i = 0; i < dim; i++){ 00067 data[i] = 0.0; 00068 } 00069 } 00070 FVector_Base::FVector_Base(float x, float y, float h, float s,float v):use(1){ 00071 data = new float[dim]; 00072 data[0] = x; 00073 data[1] = y; 00074 data[2] = h; 00075 data[3] = s; 00076 data[4] = v; 00077 } 00078 FVector_Base::~FVector_Base(){ 00079 delete[] data; 00080 } 00081 00082 string FVector_Base::toString()const{ 00083 ostringstream o; 00084 o << data[0] << ":" << data[1] << ":" << data[2] << ":" << data[3] << ":" << data[4]; 00085 string ret = o.str(); 00086 return ret; 00087 00088 } 00089 int FVector_Base::getX() const{ 00090 return ((int)data[0]); 00091 } 00092 int FVector_Base::getY() const{ 00093 return ((int)data[1]); 00094 } 00095 float FVector_Base::operator[](int i)const{ 00096 return data[i]; 00097 } 00098 FVector_Base& FVector_Base::operator+=(const FVector_Base* rhs){ 00099 for(int i = 0; i < dim; i++){ 00100 data[i] += rhs->data[i]; 00101 } 00102 return *this; 00103 } 00104 FVector_Base& FVector_Base::operator/=(const float& rhs){ 00105 for(int i = 0; i < dim; i++){ 00106 data[i] /= rhs; 00107 } 00108 return *this; 00109 } 00110 bool FVector_Base::operator<(const FVector_Base* rhs) const{ 00111 vector<float> f; 00112 for(int i = 0; i < dim; i++){ 00113 float d = (data[i] - rhs->data[i]); 00114 bool stop = true; 00115 for(int j = 0; j < f.size(); j++){ 00116 stop &= (f[j] == 0); 00117 } 00118 stop &= (d < 0); 00119 if(stop){ 00120 return true; 00121 } 00122 f.push_back(d); 00123 } 00124 return false; 00125 } 00126 00127 float norm(const FVector_Base& a, const FVector_Base& b){ 00128 float ret = 0; 00129 for(int i = 0; i < FVector_Base::dim; i++){ 00130 ret += ( (a[i] - b[i]) * (a[i] - b[i]) ); 00131 } 00132 ret = sqrt(ret); 00133 return ret; 00134 } 00135 float normColor(const FVector_Base& a, const FVector_Base& b){ 00136 float ret = 0; 00137 for(int i = 2; i < 5; i++){ 00138 ret += ( (a[i] - b[i]) * (a[i] - b[i]) ); 00139 } 00140 ret = sqrt(ret); 00141 return ret; 00142 }

Généré le Sun Jun 27 15:59:32 2004 pour segment par doxygen 1.3.7