Fade2D Documentation pages v1.90
Delaunay Features
Vector2.h
Go to the documentation of this file.
1 // Copyright (C) Geom Software e.U, Bernhard Kornberger, Graz/Austria
2 //
3 // This file is part of the Fade2D library. The student license is free
4 // of charge and covers personal non-commercial research. Licensees
5 // holding a commercial license may use this file in accordance with
6 // the Commercial License Agreement.
7 //
8 // This software is provided AS IS with NO WARRANTY OF ANY KIND,
9 // INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
10 // FOR A PARTICULAR PURPOSE.
11 //
12 // Please contact the author if any conditions of this licensing are
13 // not clear to you.
14 //
15 // Author: Bernhard Kornberger, bkorn (at) geom.at
16 // http://www.geom.at
17 
19 
20 #pragma once
21 #include "common.h"
22 
23 #if GEOM_PSEUDO3D==GEOM_TRUE
24  namespace GEOM_FADE25D {
25 #elif GEOM_PSEUDO3D==GEOM_FALSE
26  namespace GEOM_FADE2D {
27 #else
28  #error GEOM_PSEUDO3D is not defined
29 #endif
30 
31 class CLASS_DECLSPEC Vector2;
32 
37 class Vector2
38 {
39 public:
40 
41 #if GEOM_PSEUDO3D==GEOM_TRUE
45  Vector2(const double x_,const double y_,const double z_);
46 
51  Vector2();
52 
58  Vector2(const Vector2& v_);
59 
60 #else
61 
66  Vector2(const double x_,const double y_);
78  Vector2(const Vector2& v_);
79 #endif
81  Vector2& operator=(const Vector2& other);
82 
83 
84 #if GEOM_PSEUDO3D==GEOM_TRUE
88 #endif
89 
90  Vector2 orthogonalVector() const;
91 
96  bool isDegenerate() const;
97 
98 
101  double x() const;
102 
105  double y() const;
106 
107 #if GEOM_PSEUDO3D==GEOM_TRUE
111  double z() const;
112 #endif
113 
114 #if GEOM_PSEUDO3D==GEOM_TRUE
117  void set(const double x_,const double y_,const double z_);
118 
119 #else
122  void set(const double x_,const double y_);
123 #endif
124 
127  double sqLength() const;
128 
129 
130 #if GEOM_PSEUDO3D==GEOM_TRUE
135  int getMaxIndex() const;
136 #endif
137 
141  double length() const;
142 
147 #if GEOM_PSEUDO3D==GEOM_TRUE
148 
149  double operator*(const Vector2& other) const;
150 #else
151 
152  double operator*(const Vector2& other) const;
153 #endif
154 
155 
160 #if GEOM_PSEUDO3D==GEOM_TRUE
161 
162  Vector2 operator*(double val) const;
163 #else
164 
165  Vector2 operator*(double val) const;
166 #endif
167 
172 #if GEOM_PSEUDO3D==GEOM_TRUE
173 
174  Vector2 operator/(double val) const;
175 #else
176 
177  Vector2 operator/(double val) const;
178 #endif
179 
180 
181 
182 protected:
183  double valX;
184  double valY;
185 #if GEOM_PSEUDO3D==GEOM_TRUE
186  double valZ;
187 #endif
188 };
189 
190 
191 
192 
193 // Free functions
198 CLASS_DECLSPEC
199 inline std::ostream &operator<<(std::ostream &stream, const Vector2& vec)
200 {
201 #if GEOM_PSEUDO3D==GEOM_TRUE
202  stream << "Vector2: "<<vec.x()<<", "<<vec.y()<<", "<<vec.z();
203 #else
204  stream << "Vector2: "<<vec.x()<<", "<<vec.y();
205 #endif
206  return stream;
207 }
208 
209 #if GEOM_PSEUDO3D==GEOM_TRUE
214 CLASS_DECLSPEC
215 inline Vector2 crossProduct(const Vector2& vec0,const Vector2& vec1)
216 {
217  double x=vec0.y() * vec1.z() - vec0.z() * vec1.y();
218  double y=vec0.z() * vec1.x() - vec0.x() * vec1.z();
219  double z=vec0.x() * vec1.y() - vec0.y() * vec1.x();
220  return Vector2(x,y,z);
221 }
222 #endif
223 
224 
225 
226 
229 CLASS_DECLSPEC
230 inline Vector2 normalize(const Vector2& other)
231 {
232  double len(other.length());
233 #if GEOM_PSEUDO3D==GEOM_TRUE
234  if(len>0)
235  {
236  return Vector2(other.x()/len,other.y()/len,other.z()/len);
237  }
238  else
239  {
240 
241 #ifndef NDEBUG
242  std::cout<<"\n\n** warning: normalize(const Vector2& other), Null length vector!"<<std::endl;// COUTOK
244  //std::cout<<"vec="<<other<<std::endl;
245  //std::cout<<"** debug mode -> deliberate segfault, now:"<<std::endl;
246  //int* i(NULL);
247  //++*i;
248 #endif
249 
250  return Vector2(0,0,0);
251  }
252 #else
253  if(len>0)
254  {
255 
256  return Vector2(other.x()/len,other.y()/len);
257  }
258  else
259  {
260  std::cout<<"warning: normalize(const Vector2& other), Null length vector!"<<std::endl;// COUTOK
261  return Vector2(0,0);
262  }
263 #endif
264 }
270 CLASS_DECLSPEC
271 inline Vector2 operator-(const Vector2& in)
272 {
273 #if GEOM_PSEUDO3D==GEOM_TRUE
274  return Vector2(-in.x(),-in.y(),-in.z());
275 #else
276  return Vector2(-in.x(),-in.y());
277 #endif
278 }
279 
285 CLASS_DECLSPEC
286 inline Vector2 operator*(double d,const Vector2& vec)
287 {
288 #if GEOM_PSEUDO3D==GEOM_TRUE
289  return Vector2(d*vec.x(),d*vec.y(),d*vec.z());
290 #else
291  return Vector2(d*vec.x(),d*vec.y());
292 #endif
293 }
294 
300 CLASS_DECLSPEC
301 inline Vector2 operator+(const Vector2& vec0,const Vector2& vec1)
302 {
303 #if GEOM_PSEUDO3D==GEOM_TRUE
304  return Vector2(vec0.x()+vec1.x(), vec0.y()+vec1.y() , vec0.z()+vec1.z());
305 #else
306  return Vector2(vec0.x()+vec1.x(), vec0.y()+vec1.y() );
307 #endif
308 }
309 
315 CLASS_DECLSPEC
316 inline Vector2 operator-(const Vector2& vec0,const Vector2& vec1)
317 {
318 #if GEOM_PSEUDO3D==GEOM_TRUE
319  return Vector2(vec0.x()-vec1.x(), vec0.y()-vec1.y() , vec0.z()-vec1.z());
320 #else
321  return Vector2(vec0.x()-vec1.x(), vec0.y()-vec1.y() );
322 #endif
323 }
324 
325 
326 } // (namespace)
std::ostream & operator<<(std::ostream &stream, const Bbox2 &pC)
Print the box.
Definition: Bbox2.h:436
Vector2 normalize(const Vector2 &other)
Normalize a vector.
Definition: Vector2.h:230
Vector2 operator+(const Vector2 &vec0, const Vector2 &vec1)
Addition.
Definition: Vector2.h:301
Vector2 operator-(const Vector2 &in)
Opposite vector.
Definition: Vector2.h:271
Vector2 operator*(double d, const Vector2 &vec)
Multiplication with a scalar.
Definition: Vector2.h:286
Vector.
Definition: Vector2.h:38
double sqLength() const
Get the squared length of the vector.
Vector2(const Vector2 &v_)
Copy constructor.
Vector2()
Default constructor.
void set(const double x_, const double y_)
Set the values.
bool isDegenerate() const
isDegenerate
Vector2 operator*(double val) const
Multiplication.
double y() const
Get the y-value.
double operator*(const Vector2 &other) const
Scalar product.
Vector2 & operator=(const Vector2 &other)
Assignment operator.
double length() const
Get the length of the vector.
Vector2(const double x_, const double y_)
Constructor.
double x() const
Get the x-value.
Vector2 operator/(double val) const
Division.