Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 #ifndef _VRENDER_VECTOR2_H
00046 #define _VRENDER_VECTOR2_H
00047 
00048 #include <stdexcept>
00049 #include <iostream>
00050 
00051 namespace vrender
00052 {
00053   class Vector3;
00054 
00055   class Vector2
00056         {
00057                 public:
00058                         
00060 
00061                         static const Vector2 inf;
00063 
00064                         
00066 
00067                         Vector2 ();
00068                         ~Vector2 ();
00069                         Vector2 (const Vector2&);
00070                         Vector2 (const Vector3& u);
00071                         Vector2 (double,double);
00073 
00074                         
00076 
00077                         inline double  x() const { return _xyz[0]; }
00078                         inline double  y() const { return _xyz[1]; }
00079                         inline void  setX(double r) { _xyz[0] = r; }
00080                         inline void  setY(double r) { _xyz[1] = r; }
00081                         inline void  setXY (double x,double y) { _xyz[0] = x; _xyz[1] = y; }
00083 
00084                         
00086 
00087                         inline Vector2& operator= (const Vector2& u)  { _xyz[0] = u._xyz[0]; _xyz[1] = u._xyz[1]; return *this; }
00089 
00090                         
00092 
00093                         friend bool operator== (const Vector2&,const Vector2&);
00094                         friend bool operator!= (const Vector2&,const Vector2&);
00096 
00097                         
00099 
00100                         inline Vector2& operator+= (const Vector2& v)
00101                         {
00102                                 _xyz[0] += v._xyz[0];
00103                                 _xyz[1] += v._xyz[1];
00104                                 return *this;
00105                         }
00106 
00107                         inline Vector2& operator-= (const Vector2& v)
00108                         {
00109                                 _xyz[0] -= v._xyz[0];
00110                                 _xyz[1] -= v._xyz[1];
00111                                 return *this;
00112                         }
00113 
00114                         inline Vector2& operator*= (double f) { _xyz[0] *= f; _xyz[1] *= f; return *this;}
00115                         inline Vector2& operator/= (double f) { _xyz[0] /= f; _xyz[1] /= f; return *this;}
00116 
00117                         friend Vector2 operator- (const Vector2&);
00118                         static Vector2 mini(const Vector2&,const Vector2&) ;
00119                         static Vector2 maxi(const Vector2&,const Vector2&) ;
00120 
00121                         inline Vector2 operator+(const Vector2& u) const
00122                         {
00123                                 return Vector2(_xyz[0]+u._xyz[0],_xyz[1]+u._xyz[1]);
00124                         }
00125                         inline Vector2 operator-(const Vector2& u) const
00126                         {
00127                                 return Vector2(_xyz[0]-u._xyz[0],_xyz[1]-u._xyz[1]);
00128                         }
00129 
00130                         inline double    operator*(const Vector2& u) const
00131                         {
00132                                 return _xyz[0]*u._xyz[0] + _xyz[1]*u._xyz[1] ;
00133                         }
00134 
00135                         inline double operator^(const Vector2& v) const
00136                         {
00137                                 return _xyz[0]*v._xyz[1] - _xyz[1]*v._xyz[0] ;
00138                         }
00139 
00140                         Vector2 operator/ (double v) { return Vector2(_xyz[0]/v,_xyz[1]/v); }
00141                         Vector2 operator* (double v) { return Vector2(_xyz[0]*v,_xyz[1]*v); }
00142 
00143                         friend Vector2 operator* (double,const Vector2&);
00145 
00146                         
00148 
00149                         double norm       () const;
00150                         double squareNorm () const;
00151                         double infNorm    () const; 
00152 
00153                         
00155 
00156                         friend std::ostream& operator<< (std::ostream&,const Vector2&);
00158 
00159                         double  operator[] (int i) const
00160                         {
00161                                 if((i < 0)||(i > 1))
00162                                         throw std::runtime_error("Out of bounds in Vector2::operator[]") ;
00163 
00164                                 return _xyz[i];
00165                         }
00166 
00167                         double& operator[] (int i)
00168                         {
00169                                 if((i < 0)||(i > 1))
00170                                         throw std::runtime_error("Out of bounds in Vector2::operator[]") ;
00171 
00172                                 return _xyz[i];
00173                         }
00174 
00175                 private:
00176                         double _xyz[2];  
00177 
00178         }; 
00179 }
00180 
00181 #endif // _VECTOR2_H