glc_vector2d.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  Version 2.0.0 Beta 1, packaged on April 2010.
00006 
00007  http://glc-lib.sourceforge.net
00008 
00009  GLC-lib is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU General Public License as published by
00011  the Free Software Foundation; either version 2 of the License, or
00012  (at your option) any later version.
00013 
00014  GLC-lib is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU General Public License for more details.
00018 
00019  You should have received a copy of the GNU General Public License
00020  along with GLC-lib; if not, write to the Free Software
00021  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 *****************************************************************************/
00024 
00026 
00027 #ifndef GLC_VECTOR2D_H_
00028 #define GLC_VECTOR2D_H_
00029 
00030 #include <QString>
00031 #include "glc_utils_maths.h"
00032 #include "glc_vector2df.h"
00033 
00034 #include "glc_config.h"
00035 
00037 // definition global
00039 
00042 
00046 
00047 
00048 class GLC_LIB_EXPORT GLC_Vector2d
00049 {
00050         friend class GLC_Vector4d;
00051         friend class GLC_Vector3d;
00052 
00054         inline friend GLC_Vector2d operator - (const GLC_Vector2d &Vect)
00055         {
00056                 return GLC_Vector2d(-Vect.dVecteur[0], -Vect.dVecteur[1]);
00057         }
00058 
00059 
00061 
00063 
00064 public:
00070         inline GLC_Vector2d()
00071         {
00072                 dVecteur[0]= 0.0;
00073                 dVecteur[1]= 0.0;
00074         }
00075 
00077         inline GLC_Vector2d(const double &dX, const double &dY)
00078         {
00079                 dVecteur[0]= dX;
00080                 dVecteur[1]= dY;
00081         }
00082 
00089         inline GLC_Vector2d(const GLC_Vector2d &Vect)
00090         {
00091                 dVecteur[0]= Vect.dVecteur[0];
00092                 dVecteur[1]= Vect.dVecteur[1];
00093         }
00095 
00096 
00098 
00099 public:
00100 
00102         inline GLC_Vector2d operator + (const GLC_Vector2d &Vect) const
00103         {
00104                 GLC_Vector2d VectResult(dVecteur[0] + Vect.dVecteur[0], dVecteur[1] + Vect.dVecteur[1]);
00105 
00106                 return VectResult;
00107         }
00108 
00110         inline GLC_Vector2d& operator = (const GLC_Vector2d &Vect)
00111         {
00112                 dVecteur[0]= Vect.dVecteur[0];
00113                 dVecteur[1]= Vect.dVecteur[1];
00114 
00115                 return *this;
00116         }
00117 
00119         inline GLC_Vector2d& operator = (const GLC_Vector2df &Vect)
00120         {
00121                 dVecteur[0]= static_cast<double>(Vect.vector[0]);
00122                 dVecteur[1]= static_cast<double>(Vect.vector[1]);
00123 
00124                 return *this;
00125         }
00126 
00127 
00129         inline GLC_Vector2d* operator += (const GLC_Vector2d &Vect)
00130         {
00131                 *this= *this + Vect;
00132                 return this;
00133         }
00134 
00135 
00137         inline GLC_Vector2d operator - (const GLC_Vector2d &Vect) const
00138         {
00139                 GLC_Vector2d VectResult(dVecteur[0] - Vect.dVecteur[0], dVecteur[1] - Vect.dVecteur[1]);
00140 
00141                 return VectResult;
00142         }
00143 
00145         inline GLC_Vector2d* operator -= (const GLC_Vector2d &Vect)
00146         {
00147                 *this= *this - Vect;
00148                 return this;
00149         }
00150 
00152         inline double operator ^ (const GLC_Vector2d &Vect) const
00153         {
00154                 return dVecteur[0] * Vect.dVecteur[1] - dVecteur[1] * Vect.dVecteur[0];
00155         }
00156 
00158         inline double operator * (const GLC_Vector2d &Vect) const
00159         {
00160                 return dVecteur[0] * Vect.dVecteur[0] + dVecteur[1] * Vect.dVecteur[1];
00161         }
00162 
00164         inline GLC_Vector2d operator * (double Scalaire) const
00165         {
00166                 return GLC_Vector2d(dVecteur[0] * Scalaire, dVecteur[1] * Scalaire);;
00167         }
00168 
00169 
00171         inline bool operator == (const GLC_Vector2d &Vect) const
00172         {
00173                 bool bResult= qFuzzyCompare(dVecteur[0], Vect.dVecteur[0]);
00174                 bResult= bResult && qFuzzyCompare(dVecteur[1], Vect.dVecteur[1]);
00175 
00176                 return bResult;
00177         }
00178 
00180         inline bool operator != (const GLC_Vector2d &Vect) const
00181         {
00182                 return !(*this == Vect);
00183         }
00184 
00186 
00188 
00190 
00191 public:
00193         inline GLC_Vector2d& setX(const double &dX)
00194         {
00195                 dVecteur[0]= dX;
00196                 return *this;
00197         }
00198 
00200         inline GLC_Vector2d& setY(const double &dY)
00201         {
00202                 dVecteur[1]= dY;
00203                 return *this;
00204         }
00205 
00207         inline GLC_Vector2d& setVect(const double &dX, const double &dY)
00208         {
00209                 dVecteur[0]= dX;
00210                 dVecteur[1]= dY;
00211                 return *this;
00212         }
00213 
00215         inline GLC_Vector2d& setVect(const GLC_Vector2d &Vect)
00216         {
00217                 dVecteur[0]= Vect.dVecteur[0];
00218                 dVecteur[1]= Vect.dVecteur[1];
00219                 return *this;
00220         }
00221 
00223 
00225 
00227 
00228 public:
00230         inline double getX(void) const
00231         {
00232                 return dVecteur[0];
00233         }
00235         inline double getY(void) const
00236         {
00237                 return dVecteur[1];
00238         }
00240         inline const double *return_dVect(void) const
00241         {
00242                 return dVecteur;
00243         }
00245         inline bool isNull(void) const
00246         {
00247                 return qFuzzyCompare(dVecteur[0], 0.0) && qFuzzyCompare(dVecteur[1], 0.0);
00248         }
00250         inline QString toString() const
00251         {
00252                 return QString("[") + QString::number(dVecteur[0]) + QString(" , ") + QString::number(dVecteur[1]) + QString("]");
00253         }
00255         inline GLC_Vector2d perp() const
00256         {
00257                 return GLC_Vector2d(-dVecteur[1], dVecteur[0]);
00258         }
00260 
00262 //name Private attributes
00264 private:
00269         double dVecteur[2];
00270 
00271 }; //class GLC_Vector2d
00272 
00274 typedef GLC_Vector2d GLC_Point2d;
00275 
00276 #endif /*GLC_VECTOR2D_H_*/

SourceForge.net Logo

©2005 Laurent Ribon