Vector2.h
Go to the documentation of this file.
1 /*
2  This file is part of the VRender library.
3  Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
4  Version 1.0.0, released on June 27, 2005.
5 
6  http://artis.imag.fr/Members/Cyril.Soler/VRender
7 
8  VRender is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  VRender is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with VRender; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
23 /****************************************************************************
24 
25  Copyright (C) 2002-2014 Gilles Debunne. All rights reserved.
26 
27  This file is part of the QGLViewer library version 2.6.3.
28 
29  http://www.libqglviewer.com - contact@libqglviewer.com
30 
31  This file may be used under the terms of the GNU General Public License
32  versions 2.0 or 3.0 as published by the Free Software Foundation and
33  appearing in the LICENSE file included in the packaging of this file.
34  In addition, as a special exception, Gilles Debunne gives you certain
35  additional rights, described in the file GPL_EXCEPTION in this package.
36 
37  libQGLViewer uses dual licensing. Commercial/proprietary software must
38  purchase a libQGLViewer Commercial License.
39 
40  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 
43 *****************************************************************************/
44 
45 #ifndef _VRENDER_VECTOR2_H
46 #define _VRENDER_VECTOR2_H
47 
48 #include <stdexcept>
49 #include <iostream>
50 
51 namespace vrender
52 {
53  class Vector3;
54 
55  class Vector2
56  {
57  public:
58  // ---------------------------------------------------------------------------
60 
61  static const Vector2 inf;
63 
64  // ---------------------------------------------------------------------------
66 
67  Vector2 ();
68  ~Vector2 ();
69  Vector2 (const Vector2&);
70  Vector2 (const Vector3& u);
71  Vector2 (double,double);
73 
74  // ---------------------------------------------------------------------------
76 
77  inline double x() const { return _xyz[0]; }
78  inline double y() const { return _xyz[1]; }
79  inline void setX(double r) { _xyz[0] = r; }
80  inline void setY(double r) { _xyz[1] = r; }
81  inline void setXY (double x,double y) { _xyz[0] = x; _xyz[1] = y; }
83 
84  // ---------------------------------------------------------------------------
86 
87  inline Vector2& operator= (const Vector2& u) { _xyz[0] = u._xyz[0]; _xyz[1] = u._xyz[1]; return *this; }
89 
90  // ---------------------------------------------------------------------------
92 
93  friend bool operator== (const Vector2&,const Vector2&);
94  friend bool operator!= (const Vector2&,const Vector2&);
96 
97  // ---------------------------------------------------------------------------
99 
100  inline Vector2& operator+= (const Vector2& v)
101  {
102  _xyz[0] += v._xyz[0];
103  _xyz[1] += v._xyz[1];
104  return *this;
105  }
106 
107  inline Vector2& operator-= (const Vector2& v)
108  {
109  _xyz[0] -= v._xyz[0];
110  _xyz[1] -= v._xyz[1];
111  return *this;
112  }
113 
114  inline Vector2& operator*= (double f) { _xyz[0] *= f; _xyz[1] *= f; return *this;}
115  inline Vector2& operator/= (double f) { _xyz[0] /= f; _xyz[1] /= f; return *this;}
116 
117  friend Vector2 operator- (const Vector2&);
118  static Vector2 mini(const Vector2&,const Vector2&) ;
119  static Vector2 maxi(const Vector2&,const Vector2&) ;
120 
121  inline Vector2 operator+(const Vector2& u) const
122  {
123  return Vector2(_xyz[0]+u._xyz[0],_xyz[1]+u._xyz[1]);
124  }
125  inline Vector2 operator-(const Vector2& u) const
126  {
127  return Vector2(_xyz[0]-u._xyz[0],_xyz[1]-u._xyz[1]);
128  }
129 
130  inline double operator*(const Vector2& u) const
131  {
132  return _xyz[0]*u._xyz[0] + _xyz[1]*u._xyz[1] ;
133  }
134 
135  inline double operator^(const Vector2& v) const
136  {
137  return _xyz[0]*v._xyz[1] - _xyz[1]*v._xyz[0] ;
138  }
139 
140  Vector2 operator/ (double v) { return Vector2(_xyz[0]/v,_xyz[1]/v); }
141  Vector2 operator* (double v) { return Vector2(_xyz[0]*v,_xyz[1]*v); }
142 
143  friend Vector2 operator* (double,const Vector2&);
145 
146  // ---------------------------------------------------------------------------
148 
149  double norm () const;
150  double squareNorm () const;
151  double infNorm () const;
152 
153  // ---------------------------------------------------------------------------
155 
156  friend std::ostream& operator<< (std::ostream&,const Vector2&);
158 
159  double operator[] (int i) const
160  {
161  if((i < 0)||(i > 1))
162  throw std::runtime_error("Out of bounds in Vector2::operator[]") ;
163 
164  return _xyz[i];
165  }
166 
167  double& operator[] (int i)
168  {
169  if((i < 0)||(i > 1))
170  throw std::runtime_error("Out of bounds in Vector2::operator[]") ;
171 
172  return _xyz[i];
173  }
174 
175  private:
176  double _xyz[2];
177 
178  }; // interface of Vector2
179 }
180 
181 #endif // _VECTOR2_H
double operator^(const Vector2 &v) const
Definition: Vector2.h:135
double operator[](int i) const
Definition: Vector2.h:159
friend bool operator!=(const Vector2 &, const Vector2 &)
Vector2 & operator=(const Vector2 &u)
Definition: Vector2.h:87
double y() const
Definition: Vector2.h:78
Vector2 operator-(const Vector2 &u) const
Definition: Vector2.h:125
Vector2 & operator/=(double f)
Definition: Vector2.h:115
friend Vector2 operator-(const Vector2 &)
~Vector2()
Default destructor.
Definition: Vector2.cpp:68
Vector2 operator+(const Vector2 &u) const
Definition: Vector2.h:121
void setX(double r)
Definition: Vector2.h:79
double _xyz[2]
The 3 vector components.
Definition: Vector2.h:176
Vector2 & operator-=(const Vector2 &v)
Definition: Vector2.h:107
double norm() const
Norm.
Definition: Vector2.cpp:110
double infNorm() const
Infinite norm.
Definition: Vector2.cpp:124
Vector2()
Default constructor.
Definition: Vector2.cpp:60
static Vector2 maxi(const Vector2 &, const Vector2 &)
Definition: Vector2.cpp:143
static Vector2 mini(const Vector2 &, const Vector2 &)
Definition: Vector2.cpp:138
static const Vector2 inf
Definition: Vector2.h:61
Vector2 & operator+=(const Vector2 &v)
Definition: Vector2.h:100
Vector2 operator/(double v)
Definition: Vector2.h:140
double operator*(const Vector2 &u) const
Definition: Vector2.h:130
friend bool operator==(const Vector2 &, const Vector2 &)
Vector2 & operator*=(double f)
Definition: Vector2.h:114
double squareNorm() const
Square norm (self dot product)
Definition: Vector2.cpp:117
void setXY(double x, double y)
Definition: Vector2.h:81
double x() const
Definition: Vector2.h:77
void setY(double r)
Definition: Vector2.h:80
friend std::ostream & operator<<(std::ostream &, const Vector2 &)
Out stream override: prints the 3 vector components.
Definition: Vector2.cpp:132


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Wed Jun 5 2019 19:26:39