Fade2D Documentation pages v1.86
Delaunay Features
Vector2.h
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 #pragma once
18 #include "common.h"
19 
20 #if GEOM_PSEUDO3D==GEOM_TRUE
21  namespace GEOM_FADE25D {
22 #elif GEOM_PSEUDO3D==GEOM_FALSE
23  namespace GEOM_FADE2D {
24 #else
25  #error GEOM_PSEUDO3D is not defined
26 #endif
27 
28 class CLASS_DECLSPEC Vector2;
29 
34 class Vector2
35 {
36 public:
37 
38 #if GEOM_PSEUDO3D==GEOM_TRUE
39 
42  Vector2(const double x_,const double y_,const double z_);
43 
48  Vector2();
49 
55  Vector2(const Vector2& v_);
56 
57 #else
58 
63  Vector2(const double x_,const double y_);
69  Vector2();
75  Vector2(const Vector2& v_);
76 #endif
77  Vector2& operator=(const Vector2& other);
79 
80 
81 #if GEOM_PSEUDO3D==GEOM_TRUE
82 
85 #endif
86 
87  Vector2 orthogonalVector() const;
88 
93  bool isDegenerate() const;
94 
95 
98  double x() const;
99 
102  double y() const;
103 
104 #if GEOM_PSEUDO3D==GEOM_TRUE
105 
108  double z() const;
109 #endif
110 
111 #if GEOM_PSEUDO3D==GEOM_TRUE
112 
114  void set(const double x_,const double y_,const double z_);
115 
116 #else
117 
119  void set(const double x_,const double y_);
120 #endif
121 
124  double sqLength() const;
125 
126 
127 #if GEOM_PSEUDO3D==GEOM_TRUE
128 
132  int getMaxIndex() const;
133 #endif
134 
138  double length() const;
139 
142 #if GEOM_PSEUDO3D==GEOM_TRUE
143 
144  double operator*(const Vector2& other) const;
145 #else
146 
147  double operator*(const Vector2& other) const;
148 #endif
149 
150 
153 #if GEOM_PSEUDO3D==GEOM_TRUE
154 
155  Vector2 operator*(double val) const;
156 #else
157 
158  Vector2 operator*(double val) const;
159 #endif
160 
163 #if GEOM_PSEUDO3D==GEOM_TRUE
164 
165  Vector2 operator/(double val) const;
166 #else
167 
168  Vector2 operator/(double val) const;
169 #endif
170 
171 
172 
173 protected:
174  double valX;
175  double valY;
176 #if GEOM_PSEUDO3D==GEOM_TRUE
177  double valZ;
178 #endif
179 };
180 
181 
182 
183 
184 // Free functions
185 
186 CLASS_DECLSPEC
187 inline std::ostream &operator<<(std::ostream &stream, const Vector2& vec)
188 {
189 #if GEOM_PSEUDO3D==GEOM_TRUE
190  stream << "Vector2: "<<vec.x()<<", "<<vec.y()<<", "<<vec.z();
191 #else
192  stream << "Vector2: "<<vec.x()<<", "<<vec.y();
193 #endif
194  return stream;
195 }
196 
197 #if GEOM_PSEUDO3D==GEOM_TRUE
198 
200 CLASS_DECLSPEC
201 inline Vector2 crossProduct(const Vector2& vec0,const Vector2& vec1)
202 {
203  double x=vec0.y() * vec1.z() - vec0.z() * vec1.y();
204  double y=vec0.z() * vec1.x() - vec0.x() * vec1.z();
205  double z=vec0.x() * vec1.y() - vec0.y() * vec1.x();
206  return Vector2(x,y,z);
207 }
208 #endif
209 
210 
211 
212 
215 CLASS_DECLSPEC
216 inline Vector2 normalize(const Vector2& other)
217 {
218  double len(other.length());
219 #if GEOM_PSEUDO3D==GEOM_TRUE
220  if(len>0)
221  {
222  return Vector2(other.x()/len,other.y()/len,other.z()/len);
223  }
224  else
225  {
226 
227 #ifndef NDEBUG
228  std::cout<<"\n\n** warning: normalize(const Vector2& other), Null length vector!"<<std::endl;// COUTOK
230  //std::cout<<"vec="<<other<<std::endl;
231  //std::cout<<"** debug mode -> deliberate segfault, now:"<<std::endl;
232  //int* i(NULL);
233  //++*i;
234 #endif
235 
236  return Vector2(0,0,0);
237  }
238 #else
239  if(len>0)
240  {
241 
242  return Vector2(other.x()/len,other.y()/len);
243  }
244  else
245  {
246  std::cout<<"warning: normalize(const Vector2& other), Null length vector!"<<std::endl;// COUTOK
247  return Vector2(0,0);
248  }
249 #endif
250 }
251 
252 CLASS_DECLSPEC
253 inline Vector2 operator-(const Vector2& in)
254 {
255 #if GEOM_PSEUDO3D==GEOM_TRUE
256  return Vector2(-in.x(),-in.y(),-in.z());
257 #else
258  return Vector2(-in.x(),-in.y());
259 #endif
260 }
261 
262 CLASS_DECLSPEC
263 inline Vector2 operator*(double d,const Vector2& vec)
264 {
265 #if GEOM_PSEUDO3D==GEOM_TRUE
266  return Vector2(d*vec.x(),d*vec.y(),d*vec.z());
267 #else
268  return Vector2(d*vec.x(),d*vec.y());
269 #endif
270 }
271 
272 CLASS_DECLSPEC
273 inline Vector2 operator+(const Vector2& vec0,const Vector2& vec1)
274 {
275 #if GEOM_PSEUDO3D==GEOM_TRUE
276  return Vector2(vec0.x()+vec1.x(), vec0.y()+vec1.y() , vec0.z()+vec1.z());
277 #else
278  return Vector2(vec0.x()+vec1.x(), vec0.y()+vec1.y() );
279 #endif
280 }
281 
282 CLASS_DECLSPEC
283 inline Vector2 operator-(const Vector2& vec0,const Vector2& vec1)
284 {
285 #if GEOM_PSEUDO3D==GEOM_TRUE
286  return Vector2(vec0.x()-vec1.x(), vec0.y()-vec1.y() , vec0.z()-vec1.z());
287 #else
288  return Vector2(vec0.x()-vec1.x(), vec0.y()-vec1.y() );
289 #endif
290 }
291 
292 
293 } // (namespace)
GEOM_FADE2D::Vector2
Vector.
Definition: Vector2.h:34
GEOM_FADE2D::Vector2::y
double y() const
Get the y-value.
GEOM_FADE2D::Vector2::x
double x() const
Get the x-value.