Vector2.cpp
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-2013 Gilles Debunne. All rights reserved.
26 
27  This file is part of the QGLViewer library version 2.4.0.
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 #include "Vector2.h"
46 #include "Vector3.h"
47 #include <math.h>
48 
49 #ifdef WIN32
50 # include <windows.h>
51 #endif
52 
53 using namespace vrender;
54 using namespace std;
55 
57 
60 {
61  _xyz[0] = 0.0;
62  _xyz[1] = 0.0;
63 }
64 
65 // -----------------------------------------------------------------------------
68 {
69 }
70 
71 // -----------------------------------------------------------------------------
74 {
75  setXY(u[0],u[1]);
76 }
77 
78 // -----------------------------------------------------------------------------
80 Vector2::Vector2 (double x,double y)
81 {
82  setXY(x,y);
83 }
84 
86 {
87  _xyz[0] = u[0];
88  _xyz[1] = u[1];
89 }
90 
91 // -----------------------------------------------------------------------------
93 Vector2 vrender::operator- (const Vector2& u)
94 {
95  return Vector2(-u[0], -u[1]) ;
96 }
97 
98 
99 // -----------------------------------------------------------------------------
101 Vector2 operator* (double r,const Vector2& u)
102 {
103  return Vector2(r*u[0], r*u[1]) ;
104 }
105 
106 
107 // -----------------------------------------------------------------------------
109 double Vector2::norm () const
110 {
111  return sqrt( _xyz[0]*_xyz[0] + _xyz[1]*_xyz[1] );
112 }
113 
114 // -----------------------------------------------------------------------------
116 double Vector2::squareNorm () const
117 {
118  return _xyz[0]*_xyz[0] + _xyz[1]*_xyz[1] ;
119 }
120 
121 // -----------------------------------------------------------------------------
123 double Vector2::infNorm() const
124 {
125  return max(fabs(_xyz[0]),fabs(_xyz[1])) ;
126 }
127 
128 
129 // -----------------------------------------------------------------------------
131 std::ostream& operator<< (std::ostream& out,const Vector2& u)
132 {
133  out << u[0] << " " << u[1] ;
134  return ( out );
135 }
136 
137 Vector2 Vector2::mini(const Vector2& v1,const Vector2& v2)
138 {
139  return Vector2(min(v1[0],v2[0]),min(v1[1],v2[1])) ;
140 }
141 
142 Vector2 Vector2::maxi(const Vector2& v1,const Vector2& v2)
143 {
144  return Vector2(max(v1[0],v2[0]),max(v1[1],v2[1])) ;
145 }
146 
#define FLT_MAX
Definition: Vector3.h:51
~Vector2()
Default destructor.
Definition: Vector2.cpp:67
double norm() const
Norm.
Definition: Vector2.cpp:109
double infNorm() const
Infinite norm.
Definition: Vector2.cpp:123
Vector2()
Default constructor.
Definition: Vector2.cpp:59
Vector2 operator*(double r, const Vector2 &u)
Left multiplication by a real value.
Definition: Vector2.cpp:101
static Vector2 maxi(const Vector2 &, const Vector2 &)
Definition: Vector2.cpp:142
static Vector2 mini(const Vector2 &, const Vector2 &)
Definition: Vector2.cpp:137
static const Vector2 inf
Definition: Vector2.h:61
std::ostream & operator<<(std::ostream &out, const Vector2 &u)
Out stream override: prints the 3 vector components.
Definition: Vector2.cpp:131
double squareNorm() const
Square norm (self dot product)
Definition: Vector2.cpp:116


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Mon Jun 10 2019 14:00:25