Fade2D Documentation pages v2.12
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 
32 class CLASS_DECLSPEC Vector2;
33 
34 
35 
36 
41 class Vector2
42 {
43 public:
44 
45 #if GEOM_PSEUDO3D==GEOM_TRUE
49  Vector2(const double x_,const double y_,const double z_);
50 
55  Vector2();
56 
62  Vector2(const Vector2& v_);
63 
64 #else
65 
70  Vector2(const double x_,const double y_);
82  Vector2(const Vector2& v_);
83 #endif
85  Vector2& operator=(const Vector2& other);
86 
87 
88 #if GEOM_PSEUDO3D==GEOM_TRUE
92 #endif
93 
94  Vector2 orthogonalVector() const;
95 
100  bool isDegenerate() const;
101 
102 
105  double x() const;
106 
109  double y() const;
110 
111 #if GEOM_PSEUDO3D==GEOM_TRUE
115  double z() const;
116 #endif
117 
118 #if GEOM_PSEUDO3D==GEOM_TRUE
121  void set(const double x_,const double y_,const double z_);
122 
123 #else
126  void set(const double x_,const double y_);
127 #endif
128 
131  double sqLength() const;
132 
133 
134 #if GEOM_PSEUDO3D==GEOM_TRUE
139  int getMaxIndex() const;
140 #endif
141 
145  double length() const;
146 
151 #if GEOM_PSEUDO3D==GEOM_TRUE
152 
153  double operator*(const Vector2& other) const;
154 #else
155 
156  double operator*(const Vector2& other) const;
157 #endif
158 
159 
164 #if GEOM_PSEUDO3D==GEOM_TRUE
165 
166  Vector2 operator*(double val) const;
167 #else
168 
169  Vector2 operator*(double val) const;
170 #endif
171 
176 #if GEOM_PSEUDO3D==GEOM_TRUE
177 
178  Vector2 operator/(double val) const;
179 #else
180 
181  Vector2 operator/(double val) const;
182 #endif
183 
184 
185 
186 protected:
187  double valX;
188  double valY;
189 #if GEOM_PSEUDO3D==GEOM_TRUE
190  double valZ;
191 #endif
192 };
193 
194 
195 
196 
197 // Free functions
202 //CLASS_DECLSPEC
203 inline std::ostream &operator<<(std::ostream &stream, const Vector2& vec)
204 {
205 #if GEOM_PSEUDO3D==GEOM_TRUE
206  stream << "Vector2: "<<vec.x()<<", "<<vec.y()<<", "<<vec.z();
207 #else
208  stream << "Vector2: "<<vec.x()<<", "<<vec.y();
209 #endif
210  return stream;
211 }
212 
213 #if GEOM_PSEUDO3D==GEOM_TRUE
218 //CLASS_DECLSPEC
219 inline Vector2 crossProduct(const Vector2& vec0,const Vector2& vec1)
220 {
221  double x=vec0.y() * vec1.z() - vec0.z() * vec1.y();
222  double y=vec0.z() * vec1.x() - vec0.x() * vec1.z();
223  double z=vec0.x() * vec1.y() - vec0.y() * vec1.x();
224  return Vector2(x,y,z);
225 }
226 #endif
227 
228 
229 
230 
233 //CLASS_DECLSPEC
234 inline Vector2 normalize(const Vector2& other)
235 {
236  double len(other.length());
237 #if GEOM_PSEUDO3D==GEOM_TRUE
238  if(len>0)
239  {
240  return Vector2(other.x()/len,other.y()/len,other.z()/len);
241  }
242  else
243  {
244 
245 #ifndef NDEBUG
246  std::cout<<"\n\n** warning: normalize(const Vector2& other), Null length vector!"<<std::endl;// COUTOK
248  //std::cout<<"vec="<<other<<std::endl;
249  //std::cout<<"** debug mode -> deliberate segfault, now:"<<std::endl;
250  //int* i(NULL);
251  //++*i;
252 #endif
253 
254  return Vector2(0,0,0);
255  }
256 #else
257  if(len>0)
258  {
259 
260  return Vector2(other.x()/len,other.y()/len);
261  }
262  else
263  {
264  std::cout<<"warning: normalize(const Vector2& other), Null length vector!"<<std::endl;// COUTOK
265  return Vector2(0,0);
266  }
267 #endif
268 }
274 //CLASS_DECLSPEC
275 inline Vector2 operator-(const Vector2& in)
276 {
277 #if GEOM_PSEUDO3D==GEOM_TRUE
278  return Vector2(-in.x(),-in.y(),-in.z());
279 #else
280  return Vector2(-in.x(),-in.y());
281 #endif
282 }
283 
289 //CLASS_DECLSPEC
290 inline Vector2 operator*(double d,const Vector2& vec)
291 {
292 #if GEOM_PSEUDO3D==GEOM_TRUE
293  return Vector2(d*vec.x(),d*vec.y(),d*vec.z());
294 #else
295  return Vector2(d*vec.x(),d*vec.y());
296 #endif
297 }
298 
304 //CLASS_DECLSPEC
305 inline Vector2 operator+(const Vector2& vec0,const Vector2& vec1)
306 {
307 #if GEOM_PSEUDO3D==GEOM_TRUE
308  return Vector2(vec0.x()+vec1.x(), vec0.y()+vec1.y() , vec0.z()+vec1.z());
309 #else
310  return Vector2(vec0.x()+vec1.x(), vec0.y()+vec1.y() );
311 #endif
312 }
313 
319 //CLASS_DECLSPEC
320 inline Vector2 operator-(const Vector2& vec0,const Vector2& vec1)
321 {
322 #if GEOM_PSEUDO3D==GEOM_TRUE
323  return Vector2(vec0.x()-vec1.x(), vec0.y()-vec1.y() , vec0.z()-vec1.z());
324 #else
325  return Vector2(vec0.x()-vec1.x(), vec0.y()-vec1.y() );
326 #endif
327 }
328 
329 
330 } // (namespace)
std::ostream & operator<<(std::ostream &stream, const Bbox2 &pC)
Print the box.
Definition: Bbox2.h:492
Vector2 normalize(const Vector2 &other)
Normalize a vector.
Definition: Vector2.h:234
Vector2 operator+(const Vector2 &vec0, const Vector2 &vec1)
Addition.
Definition: Vector2.h:305
Vector2 operator-(const Vector2 &in)
Opposite vector.
Definition: Vector2.h:275
Vector2 operator*(double d, const Vector2 &vec)
Multiplication with a scalar.
Definition: Vector2.h:290
Vector.
Definition: Vector2.h:42
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.