Fade2.5D Documentation pages v2.16.7
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 
46 class Vector2
47 {
48 public:
49 
50 #if GEOM_PSEUDO3D==GEOM_TRUE
57  Vector2(const double x_,const double y_,const double z_);
58 
64 
71  Vector2(const Vector2& v_);
72 
73 #else
74 
81  Vector2(const double x_,const double y_);
82 
87 Vector2();
88 
89 
96 Vector2(const Vector2& v_);
97 #endif
98 
106  Vector2& operator=(const Vector2& other);
107 
108 
109 
118 
125  bool isDegenerate() const;
126 
127 
132  double x() const;
133 
138  double y() const;
139 
140 #if GEOM_PSEUDO3D==GEOM_TRUE
146  double z() const;
147 #endif
148 
149 #if GEOM_PSEUDO3D==GEOM_TRUE
156  void set(const double x_,const double y_,const double z_);
157 
158 #else
165  void set(const double x_,const double y_);
166 #endif
167 
172  double sqLength() const;
173 
174 
175 #if GEOM_PSEUDO3D==GEOM_TRUE
182  int getMaxIndex() const;
183 #endif
184 
189  double length() const;
190 
198 #if GEOM_PSEUDO3D==GEOM_TRUE
199 
200  double operator*(const Vector2& other) const;
201 #else
202 
203  double operator*(const Vector2& other) const;
204 #endif
205 
206 
214 #if GEOM_PSEUDO3D==GEOM_TRUE
215 
216  Vector2 operator*(double val) const;
217 #else
218 
219  Vector2 operator*(double val) const;
220 #endif
221 
229 #if GEOM_PSEUDO3D==GEOM_TRUE
230  Vector2 operator/(double val) const;
231 #else
232 
233  Vector2 operator/(double val) const;
234 #endif
235 
236 protected:
237  double valX;
238  double valY;
239 #if GEOM_PSEUDO3D==GEOM_TRUE
240  double valZ;
241 #endif
242 };
243 
244 
245 
246 
247 // Free functions
257 inline std::ostream &operator<<(std::ostream &stream, const Vector2& vec)
258 {
259 #if GEOM_PSEUDO3D==GEOM_TRUE
260  stream << "Vector2: "<<vec.x()<<", "<<vec.y()<<", "<<vec.z();
261 #else
262  stream << "Vector2: "<<vec.x()<<", "<<vec.y();
263 #endif
264  return stream;
265 }
266 
267 #if GEOM_PSEUDO3D==GEOM_TRUE
276 inline Vector2 crossProduct(const Vector2& vec0,const Vector2& vec1)
277 {
278  double x=vec0.y() * vec1.z() - vec0.z() * vec1.y();
279  double y=vec0.z() * vec1.x() - vec0.x() * vec1.z();
280  double z=vec0.x() * vec1.y() - vec0.y() * vec1.x();
281  return Vector2(x,y,z);
282 }
283 #endif
284 
285 
292 inline Vector2 operator-(const Vector2& in)
293 {
294 #if GEOM_PSEUDO3D==GEOM_TRUE
295  return Vector2(-in.x(),-in.y(),-in.z());
296 #else
297  return Vector2(-in.x(),-in.y());
298 #endif
299 }
300 
309 inline Vector2 operator*(double d,const Vector2& vec)
310 {
311 #if GEOM_PSEUDO3D==GEOM_TRUE
312  return Vector2(d*vec.x(),d*vec.y(),d*vec.z());
313 #else
314  return Vector2(d*vec.x(),d*vec.y());
315 #endif
316 }
317 
326 inline Vector2 operator+(const Vector2& vec0,const Vector2& vec1)
327 {
328 #if GEOM_PSEUDO3D==GEOM_TRUE
329  return Vector2(vec0.x()+vec1.x(), vec0.y()+vec1.y() , vec0.z()+vec1.z());
330 #else
331  return Vector2(vec0.x()+vec1.x(), vec0.y()+vec1.y() );
332 #endif
333 }
334 
343 inline Vector2 operator-(const Vector2& vec0,const Vector2& vec1)
344 {
345 #if GEOM_PSEUDO3D==GEOM_TRUE
346  return Vector2(vec0.x()-vec1.x(), vec0.y()-vec1.y() , vec0.z()-vec1.z());
347 #else
348  return Vector2(vec0.x()-vec1.x(), vec0.y()-vec1.y() );
349 #endif
350 }
351 
352 
353 } // (namespace)
std::ostream & operator<<(std::ostream &stream, const Bbox2 &pC)
Prints the bounding box to a stream.
Definition: Bbox2.h:605
Vector2 crossProduct(const Vector2 &vec0, const Vector2 &vec1)
Cross product.
Definition: Vector2.h:276
Vector2 operator-(const Vector2 &in)
Opposite vector.
Definition: Vector2.h:292
Vector2 operator+(const Vector2 &vec0, const Vector2 &vec1)
Addition.
Definition: Vector2.h:326
Vector2 operator*(double d, const Vector2 &vec)
Multiplication with a scalar.
Definition: Vector2.h:309
Vector.
Definition: Vector2.h:47
double sqLength() const
Get the squared length of the vector.
Vector2()
Default constructor.
double x() const
Get the x-value.
bool isDegenerate() const
Check if the vector is degenerate.
double y() const
Get the y-value.
double z() const
Get the z-value.
Vector2 orthogonalVector() const
Get a normalized, orthogonal 2D vector (CCW direction)
double length() const
Get the length of the vector.
Vector2(const double x_, const double y_, const double z_)
Constructor.
Vector2 operator/(double val) const
Division by a scalar.
Vector2 operator*(double val) const
Multiplication by a scalar.
double operator*(const Vector2 &other) const
Scalar product.
void set(const double x_, const double y_, const double z_)
Set the components.
Vector2 & operator=(const Vector2 &other)
Assignment operator.
int getMaxIndex() const
Get the index of the largest absolute component.
Vector2(const Vector2 &v_)
Copy constructor.