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-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 #include "Vector2.h"
46 #include "Vector3.h"
47 #include <math.h>
48 #include <algorithm>
49 
50 #ifdef WIN32
51 # include <windows.h>
52 #endif
53 
54 using namespace vrender;
55 using namespace std;
56 
58 
61 {
62  _xyz[0] = 0.0;
63  _xyz[1] = 0.0;
64 }
65 
66 // -----------------------------------------------------------------------------
69 {
70 }
71 
72 // -----------------------------------------------------------------------------
75 {
76  setXY(u[0],u[1]);
77 }
78 
79 // -----------------------------------------------------------------------------
81 Vector2::Vector2 (double x,double y)
82 {
83  setXY(x,y);
84 }
85 
87 {
88  _xyz[0] = u[0];
89  _xyz[1] = u[1];
90 }
91 
92 // -----------------------------------------------------------------------------
94 Vector2 vrender::operator- (const Vector2& u)
95 {
96  return Vector2(-u[0], -u[1]) ;
97 }
98 
99 
100 // -----------------------------------------------------------------------------
102 Vector2 operator* (double r,const Vector2& u)
103 {
104  return Vector2(r*u[0], r*u[1]) ;
105 }
106 
107 
108 // -----------------------------------------------------------------------------
110 double Vector2::norm () const
111 {
112  return sqrt( _xyz[0]*_xyz[0] + _xyz[1]*_xyz[1] );
113 }
114 
115 // -----------------------------------------------------------------------------
117 double Vector2::squareNorm () const
118 {
119  return _xyz[0]*_xyz[0] + _xyz[1]*_xyz[1] ;
120 }
121 
122 // -----------------------------------------------------------------------------
124 double Vector2::infNorm() const
125 {
126  return max(fabs(_xyz[0]),fabs(_xyz[1])) ;
127 }
128 
129 
130 // -----------------------------------------------------------------------------
132 std::ostream& operator<< (std::ostream& out,const Vector2& u)
133 {
134  out << u[0] << " " << u[1] ;
135  return ( out );
136 }
137 
138 Vector2 Vector2::mini(const Vector2& v1,const Vector2& v2)
139 {
140  return Vector2(std::min(v1[0],v2[0]),std::min(v1[1],v2[1])) ;
141 }
142 
143 Vector2 Vector2::maxi(const Vector2& v1,const Vector2& v2)
144 {
145  return Vector2(std::max(v1[0],v2[0]),std::max(v1[1],v2[1])) ;
146 }
147 
#define FLT_MAX
Definition: Vector3.h:51
~Vector2()
Default destructor.
Definition: Vector2.cpp:68
double norm() const
Norm.
Definition: Vector2.cpp:110
double infNorm() const
Infinite norm.
Definition: Vector2.cpp:124
Vector2()
Default constructor.
Definition: Vector2.cpp:60
Vector2 operator*(double r, const Vector2 &u)
Left multiplication by a real value.
Definition: Vector2.cpp:102
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
std::ostream & operator<<(std::ostream &out, const Vector2 &u)
Out stream override: prints the 3 vector components.
Definition: Vector2.cpp:132
double squareNorm() const
Square norm (self dot product)
Definition: Vector2.cpp:117


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