Fade2.5D Documentation pages v2.07
Delaunay Features
Point2.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 
22 #include "common.h"
23 #include "Vector2.h"
24 
25 #if GEOM_PSEUDO3D==GEOM_TRUE
26  namespace GEOM_FADE25D {
27 #elif GEOM_PSEUDO3D==GEOM_FALSE
28  namespace GEOM_FADE2D {
29 #else
30  #error GEOM_PSEUDO3D is not defined
31 #endif
32 
33 
34 class Triangle2; // FWD
35 
36 
42 class CLASS_DECLSPEC Point2
43 {
44 #ifdef GEOM_DBG
45  int getSeqNum()
46  {
47  static int seqNum(0);
48  return seqNum++;
49  }
50 #endif
51 
52 public:
53 
54 #if GEOM_PSEUDO3D==GEOM_TRUE
61  Point2(const double x_,const double y_,const double z_):
62  coordX(x_),
63  coordY(y_),
64  coordZ(z_),
65  pAssociatedTriangle(NULL),
66  customIndex(-1)
67  {
68 #ifdef GEOM_DBG
69  customIndex=getSeqNum();
70 #endif
71  }
72 
73 
77  Point2():coordX(-DBL_MAX),coordY(-DBL_MAX),coordZ(-DBL_MAX),pAssociatedTriangle(NULL),customIndex(-1)
78  {
79 #ifdef GEOM_DBG
80  customIndex=getSeqNum();
81 #endif
82  }
87  Point2(const Point2& p_):
88  coordX(p_.x()),
89  coordY(p_.y()),
90  coordZ(p_.z()),
91  pAssociatedTriangle(NULL),
92  customIndex(p_.customIndex)
93  {
94  }
95 
96  Point2 &operator=(const Point2& other)
97  {
98  coordX=other.x();
99  coordY=other.y();
100  coordZ=other.z();
101  pAssociatedTriangle=NULL;
102  customIndex=other.customIndex;
103  return *this;
104  }
105 
106 
107 // Deprecated, use setHeight() instead. Kept for backward compatibility
110  void setZ(double z)
111  {
112  setHeight(z);
113  }
114 
115 
118  void print()
119  {
120  std::cout<<coordX<<" "<<coordY<<" "<<coordZ<<std::endl;
121  }
122 
123 
124 
125 #else
126 
127 
133  Point2(const double x_,const double y_):
134  coordX(x_),
135  coordY(y_),
136  pAssociatedTriangle(NULL),
137  customIndex(-1)
138  {
139  //BC("Point2 Constructor default");
140  }
145  Point2():
146  coordX(-DBL_MAX),
147  coordY(-DBL_MAX),
148  pAssociatedTriangle(NULL),
149  customIndex(-1)
150  {
151  }
156  Point2(const Point2& p_):
157  coordX(p_.x()),
158  coordY(p_.y()),
159  pAssociatedTriangle(NULL),
160  customIndex(p_.customIndex)
161  {
162  }
163 
164  Point2 &operator=(const Point2& other)
165  {
166  coordX=other.x();
167  coordY=other.y();
168  pAssociatedTriangle=NULL;
169  customIndex=other.customIndex;
170  return *this;
171  }
172 
175  void print()
176  {
177  std::cout<<coordX<<" "<<coordY<<std::endl;
178  }
179 
180 #endif
181 
182 
183 
184 
185 
186  ~Point2()
187  {
188  }
189 
195  double x() const
196  {
197  return coordX;
198  }
204  double y() const
205  {
206  return coordY;
207  }
208 
209 #if GEOM_PSEUDO3D==GEOM_TRUE
215  double z() const
216  {
217  return coordZ;
218  }
219 #endif
220 
221 #if GEOM_PSEUDO3D==GEOM_TRUE
230  void xyz(double& x_,double& y_,double& z_) const
231  {
232  x_=coordX;
233  y_=coordY;
234  z_=coordZ;
235  }
236 #endif
237 
245  void xy(double& x_,double& y_) const
246  {
247  x_=coordX;
248  y_=coordY;
249  }
250 
251 
252 #if GEOM_PSEUDO3D==GEOM_TRUE
258  void setHeight(double z)
259  {
260  coordZ=z;
261  }
262 #endif
263 
264 
265 
266 
271  double getMaxAbs() const
272  {
273  double a(fabs(coordX));
274  double b(fabs(coordY));
275  return (std::max)(a,b);
276  }
277 
278 
279 
280 
281 
282 
290  bool operator<(const Point2& p) const
291  {
292  if(coordX<p.coordX) return true;
293  if(coordX>p.coordX) return false;
294  if(coordY<p.coordY) return true;
295  return false;
296  }
304  bool operator>(const Point2& p) const
305  {
306  if(coordX>p.coordX) return true;
307  if(coordX<p.coordX) return false;
308  if(coordY>p.coordY) return true;
309  return false;
310  }
318  bool operator==(const Point2& p) const
319  {
320  return (coordX==p.coordX && coordY==p.coordY);
321  }
322 #if GEOM_PSEUDO3D==GEOM_TRUE
328  bool samePoint(const Point2& p) const
329  {
330  return(coordX==p.coordX && coordY==p.coordY && coordZ==p.coordZ);
331  }
332 #endif
339  bool operator!=(const Point2& p) const
340  {
341  if(coordX!=p.coordX || coordY!=p.coordY) return true;
342  return false;
343  }
349  {
350  return pAssociatedTriangle;
351  }
352 
353 
354 #if GEOM_PSEUDO3D==GEOM_TRUE
365  void setCoords(const double x_,const double y_,const double z_)
366  {
367  coordX=x_;
368  coordY=y_;
369  coordZ=z_;
370  }
381  void set(const double x_,const double y_,const double z_,int customIndex_)
382  {
383  coordX=x_;
384  coordY=y_;
385  coordZ=z_;
386  pAssociatedTriangle=NULL;
387  customIndex=customIndex_;
388 #ifdef GEOM_DBG
389  customIndex=getSeqNum();
390 #endif
391  }
392 #else
401  void set(const double x_,const double y_,int customIndex_)
402  {
403  coordX=x_;
404  coordY=y_;
405  pAssociatedTriangle=NULL;
406  customIndex=customIndex_;
407 #ifdef GEOM_DBG
408  customIndex=getSeqNum();
409 #endif
410  }
411  void change(const double x_,const double y_)
412  {
413  coordX=x_;
414  coordY=y_;
415  }
416 #endif
417 
422 #if GEOM_PSEUDO3D==GEOM_TRUE
423  void set(const Point2& pnt)
424  {
425  coordX=pnt.x();
426  coordY=pnt.y();
427  coordZ=pnt.z();
428  pAssociatedTriangle=NULL;
429  this->customIndex=pnt.customIndex;
430  }
431 #else
432  void set(const Point2& pnt)
433  {
434  coordX=pnt.x();
435  coordY=pnt.y();
436  pAssociatedTriangle=NULL;
437  this->customIndex=pnt.customIndex;
438  }
439 #endif
440 
441 
442 
458  void setCustomIndex(int customIndex_)
459  {
460  customIndex=customIndex_;
461  }
475  int getCustomIndex() const
476  {
477  return customIndex;
478  }
479 
485  {
486  pAssociatedTriangle=pT;
487  }
488 
491 Vector2 operator-(const Point2& other) const
492 {
493 #if GEOM_PSEUDO3D==GEOM_TRUE
494  double xdiff(x()-other.x());
495  double ydiff(y()-other.y());
496  double zdiff(z()-other.z());
497  return Vector2(xdiff,ydiff,zdiff);
498 #else
499  double xdiff(x()-other.x());
500  double ydiff(y()-other.y());
501  return Vector2(xdiff,ydiff);
502 #endif
503 
504 
505 }
506 
509 Point2 operator+(const Vector2& vec) const
510 {
511 #if GEOM_PSEUDO3D==GEOM_TRUE
512  return Point2(x()+vec.x(),y()+vec.y(),z()+vec.z());
513 #else
514  return Point2(x()+vec.x(),y()+vec.y());
515 #endif
516 }
517 
520 Point2 operator-(const Vector2& vec) const
521 {
522 #if GEOM_PSEUDO3D==GEOM_TRUE
523  return Point2(x()-vec.x(),y()-vec.y(),z()-vec.z());
524 #else
525  return Point2(x()-vec.x(),y()-vec.y());
526 #endif
527 }
528 
529 
530  friend std::ostream &operator<<(std::ostream &stream, const Point2& pnt);
531  friend std::istream &operator>>(std::istream &stream, Point2& pnt);
532 
533 
534 protected:
535 friend class Dt2;
536  double coordX;
537  double coordY;
538 #if GEOM_PSEUDO3D==GEOM_TRUE
539  double coordZ;
540 #endif
541  Triangle2* pAssociatedTriangle;
542  int customIndex;
543 }; // End of class
544 
546 inline std::ostream &operator<<(std::ostream &stream, const Point2& pnt)
547 {
548 #if GEOM_PSEUDO3D==GEOM_TRUE
549  stream << "Point2 ("<<&pnt<<","<<pnt.customIndex<<"): "<<pnt.x()<<", "<<pnt.y()<<", "<<pnt.z();
550  //#ifndef NDEBUG
551  //stream<<", anyT="<<pnt.getIncidentTriangle();
552  //#endif
553 #else
554  stream << "Point2 ("<<&pnt<<","<<pnt.customIndex<<"): "<<pnt.x()<<", "<<pnt.y();
555 #endif
556 
557 
558  return stream;
559 }
560 
562 inline std::istream &operator>>(std::istream &stream, Point2& pnt)
563 {
564 #if GEOM_PSEUDO3D==GEOM_TRUE
565  stream >> pnt.coordX >> pnt.coordY >> pnt.coordZ;
566 #else
567  stream >> pnt.coordX >> pnt.coordY;
568 #endif
569  return stream;
570 }
571 
572 // Free functions
573 
580 inline
581 double sqDistance2D(const Point2& p0,const Point2& p1)
582 {
583  double deltaX=p1.x()-p0.x();
584  double deltaY=p1.y()-p0.y();
585  return (deltaX*deltaX+deltaY*deltaY);
586 }
587 
588 
595 inline
596 double sqDistance2D(const double x0,const double y0,const Point2& p1)
597 {
598  double deltaX=p1.x()-x0;
599  double deltaY=p1.y()-y0;
600  return (deltaX*deltaX+deltaY*deltaY);
601 }
602 
603 #if GEOM_PSEUDO3D==GEOM_TRUE
604 
609 inline
610 double sqDistance25D(const Point2& p0,const Point2& p1)
611 {
612  double deltaX=p1.x()-p0.x();
613  double deltaY=p1.y()-p0.y();
614  double deltaZ=p1.z()-p0.z();
615  double result(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
616 
617  if(result!=result)
618  {
619  std::cerr<<"warning, sqDistance25D, nan value, no distance"<<std::endl;
620  std::cerr<<"p0="<<p0<<std::endl;
621  std::cerr<<"p1="<<p1<<std::endl;
622  }
623 
624  return result;
625 }
626 
627 
632 inline
633 double sqDistance25D(const double x0,const double y0,const double z0,const Point2& p1)
634 {
635  double deltaX=p1.x()-x0;
636  double deltaY=p1.y()-y0;
637  double deltaZ=p1.z()-z0;
638  double result(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
639 
640  if(result!=result)
641  {
642  std::cerr<<"warning, sqDistance25D, nan value, no distance"<<std::endl;
643  std::cerr<<"x0="<<x0<<", y0="<<y0<<", z0="<<z0<<std::endl;
644  std::cerr<<"p1="<<p1<<std::endl;
645  }
646 
647  return result;
648 
649 }
650 
651 
652 #endif
653 
654 
655 
662 inline
663 Point2 center(const Point2& p0,const Point2& p1)
664 {
665 #if GEOM_PSEUDO3D==GEOM_TRUE
666  Point2 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0,(p0.z()+p1.z())/2.0);
667 
668 #else
669  Point2 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0);
670 #endif
671  return center;
672 }
673 
685 CLASS_DECLSPEC
686 Point2 centerWithShift(const Point2& p0,const Point2& p1);
687 
688 #if GEOM_PSEUDO3D==GEOM_TRUE
690 struct CLASS_DECLSPEC Func_ltPointXYZ
691 {
692  bool operator()(const Point2& p0,const Point2& p1) const
693  {
694  if(p0.x()<p1.x()) return true;
695  if(p0.x()>p1.x()) return false;
696  if(p0.y()<p1.y()) return true;
697  if(p0.y()>p1.y()) return false;
698  if(p0.z()<p1.z()) return true;
699  return false;
700  }
701 };
702 
703 #endif
704 
705 } // (namespace)
std::ostream & operator<<(std::ostream &stream, const Bbox2 &pC)
Print the box.
Definition: Bbox2.h:492
double sqDistance25D(const Point2 &p0, const Point2 &p1)
Get the squared distance between two points.
Definition: Point2.h:610
std::istream & operator>>(std::istream &stream, Point2 &pnt)
Stream-to-Point.
Definition: Point2.h:562
double sqDistance2D(const Point2 &p0, const Point2 &p1)
Get the squared distance between two points in 2D.
Definition: Point2.h:581
Point2 center(const Point2 &p0, const Point2 &p1)
Compute the midpoint of p0 and p1.
Definition: Point2.h:663
Point2 centerWithShift(const Point2 &p0, const Point2 &p1)
Compute the midpoint of p0 and p1 and adapt it.
Point.
Definition: Point2.h:43
double getMaxAbs() const
Get max(abs(x),abs(y))
Definition: Point2.h:271
double z() const
Get the z-coordinate.
Definition: Point2.h:215
bool operator!=(const Point2 &p) const
Inequality operator.
Definition: Point2.h:339
void xy(double &x_, double &y_) const
Get the x- and y-coordinate.
Definition: Point2.h:245
bool operator==(const Point2 &p) const
Equality operator.
Definition: Point2.h:318
Point2 operator+(const Vector2 &vec) const
Add vector and point.
Definition: Point2.h:509
void setCoords(const double x_, const double y_, const double z_)
Set the coordinates.
Definition: Point2.h:365
void setIncidentTriangle(Triangle2 *pT)
Associate a triangle with the point.
Definition: Point2.h:484
int getCustomIndex() const
Get the custom index.
Definition: Point2.h:475
void setCustomIndex(int customIndex_)
Set a custom index.
Definition: Point2.h:458
double y() const
Get the y-coordinate.
Definition: Point2.h:204
bool operator>(const Point2 &p) const
Greater than operator.
Definition: Point2.h:304
Point2()
Default constructor.
Definition: Point2.h:77
void set(const double x_, const double y_, const double z_, int customIndex_)
Set the coordinates.
Definition: Point2.h:381
bool samePoint(const Point2 &p) const
Equality operator.
Definition: Point2.h:328
void setHeight(double z)
Set the z-coordinate.
Definition: Point2.h:258
double x() const
Get the x-coordinate.
Definition: Point2.h:195
Triangle2 * getIncidentTriangle() const
Get the associated triangle.
Definition: Point2.h:348
void xyz(double &x_, double &y_, double &z_) const
Get the x-, y- and z-coordinate.
Definition: Point2.h:230
void set(const Point2 &pnt)
Set the coordiantes.
Definition: Point2.h:423
Point2 operator-(const Vector2 &vec) const
Subtract vector from point.
Definition: Point2.h:520
bool operator<(const Point2 &p) const
Less than operator.
Definition: Point2.h:290
Point2(const Point2 &p_)
Copy constructor.
Definition: Point2.h:87
Vector2 operator-(const Point2 &other) const
Returns a vector from other to *this.
Definition: Point2.h:491
Point2(const double x_, const double y_, const double z_)
Constructor.
Definition: Point2.h:61
Triangle.
Definition: Triangle2.h:60
Vector.
Definition: Vector2.h:42
double x() const
Get the x-value.
double y() const
Get the y-value.
double z() const
Get the z-value.
Functor to sort points lexicographically.
Definition: Point2.h:691