Vector2.h
Go to the documentation of this file.
00001 /*
00002  This file is part of the VRender library.
00003  Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
00004  Version 1.0.0, released on June 27, 2005.
00005 
00006  http://artis.imag.fr/Members/Cyril.Soler/VRender
00007 
00008  VRender is free software; you can redistribute it and/or modify
00009  it under the terms of the GNU General Public License as published by
00010  the Free Software Foundation; either version 2 of the License, or
00011  (at your option) any later version.
00012 
00013  VRender is distributed in the hope that it will be useful,
00014  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  GNU General Public License for more details.
00017 
00018  You should have received a copy of the GNU General Public License
00019  along with VRender; if not, write to the Free Software Foundation, Inc.,
00020  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
00021 */
00022 
00023 /****************************************************************************
00024 
00025  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
00026 
00027  This file is part of the QGLViewer library version 2.4.0.
00028 
00029  http://www.libqglviewer.com - contact@libqglviewer.com
00030 
00031  This file may be used under the terms of the GNU General Public License 
00032  versions 2.0 or 3.0 as published by the Free Software Foundation and
00033  appearing in the LICENSE file included in the packaging of this file.
00034  In addition, as a special exception, Gilles Debunne gives you certain 
00035  additional rights, described in the file GPL_EXCEPTION in this package.
00036 
00037  libQGLViewer uses dual licensing. Commercial/proprietary software must
00038  purchase a libQGLViewer Commercial License.
00039 
00040  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00041  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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         }; // interface of Vector2
00179 }
00180 
00181 #endif // _VECTOR2_H


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Aug 27 2015 14:13:26