Fade2D Documentation pages v2.09
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 
37 
38 
44 class CLASS_DECLSPEC Point2
45 {
46 #ifdef GEOM_DBG
47  int getSeqNum()
48  {
49  static int seqNum(0);
50  return seqNum++;
51  }
52 #endif
53 
54 public:
55 
56 #if GEOM_PSEUDO3D==GEOM_TRUE
63  Point2(const double x_,const double y_,const double z_):
64  coordX(x_),
65  coordY(y_),
66  coordZ(z_),
67  pAssociatedTriangle(NULL),
68  customIndex(-1)
69  {
70 #ifdef GEOM_DBG
71  customIndex=getSeqNum();
72 #endif
73  }
74 
75 
79  Point2():coordX(-DBL_MAX),coordY(-DBL_MAX),coordZ(-DBL_MAX),pAssociatedTriangle(NULL),customIndex(-1)
80  {
81 #ifdef GEOM_DBG
82  customIndex=getSeqNum();
83 #endif
84  }
89  Point2(const Point2& p_):
90  coordX(p_.x()),
91  coordY(p_.y()),
92  coordZ(p_.z()),
93  pAssociatedTriangle(NULL),
94  customIndex(p_.customIndex)
95  {
96  }
97 
98  Point2 &operator=(const Point2& other)
99  {
100  coordX=other.x();
101  coordY=other.y();
102  coordZ=other.z();
103  pAssociatedTriangle=NULL;
104  customIndex=other.customIndex;
105  return *this;
106  }
107 
108 
109 // Deprecated, use setHeight() instead. Kept for backward compatibility
112  void setZ(double z)
113  {
114  setHeight(z);
115  }
116 
117 
120  void print()
121  {
122  std::cout<<coordX<<" "<<coordY<<" "<<coordZ<<std::endl;
123  }
124 
125 
126 
127 #else
128 
129 
135  Point2(const double x_,const double y_):
136  coordX(x_),
137  coordY(y_),
138  pAssociatedTriangle(NULL),
139  customIndex(-1)
140  {
141  //BC("Point2 Constructor default");
142  }
148  coordX(-DBL_MAX),
149  coordY(-DBL_MAX),
150  pAssociatedTriangle(NULL),
151  customIndex(-1)
152  {
153  }
158  Point2(const Point2& p_):
159  coordX(p_.x()),
160  coordY(p_.y()),
161  pAssociatedTriangle(NULL),
162  customIndex(p_.customIndex)
163  {
164  }
165 
166  Point2 &operator=(const Point2& other)
167  {
168  coordX=other.x();
169  coordY=other.y();
170  pAssociatedTriangle=NULL;
171  customIndex=other.customIndex;
172  return *this;
173  }
174 
177  void print()
178  {
179  std::cout<<coordX<<" "<<coordY<<std::endl;
180  }
181 
182 #endif
183 
184 
185 
186 
187 
188  ~Point2()
189  {
190  }
191 
197  double x() const
198  {
199  return coordX;
200  }
206  double y() const
207  {
208  return coordY;
209  }
210 
211 #if GEOM_PSEUDO3D==GEOM_TRUE
217  double z() const
218  {
219  return coordZ;
220  }
221 #endif
222 
223 #if GEOM_PSEUDO3D==GEOM_TRUE
232  void xyz(double& x_,double& y_,double& z_) const
233  {
234  x_=coordX;
235  y_=coordY;
236  z_=coordZ;
237  }
238 #endif
239 
247  void xy(double& x_,double& y_) const
248  {
249  x_=coordX;
250  y_=coordY;
251  }
252 
253 
254 #if GEOM_PSEUDO3D==GEOM_TRUE
260  void setHeight(double z)
261  {
262  coordZ=z;
263  }
264 #endif
265 
266 
267 
268 
273  double getMaxAbs() const
274  {
275  double a(fabs(coordX));
276  double b(fabs(coordY));
277  return (std::max)(a,b);
278  }
279 
280 
281 
282 
283 
284 
292  bool operator<(const Point2& p) const
293  {
294  if(coordX<p.coordX) return true;
295  if(coordX>p.coordX) return false;
296  if(coordY<p.coordY) return true;
297  return false;
298  }
306  bool operator>(const Point2& p) const
307  {
308  if(coordX>p.coordX) return true;
309  if(coordX<p.coordX) return false;
310  if(coordY>p.coordY) return true;
311  return false;
312  }
320  bool operator==(const Point2& p) const
321  {
322  return (coordX==p.coordX && coordY==p.coordY);
323  }
324 #if GEOM_PSEUDO3D==GEOM_TRUE
330  bool samePoint(const Point2& p) const
331  {
332  return(coordX==p.coordX && coordY==p.coordY && coordZ==p.coordZ);
333  }
334 #endif
341  bool operator!=(const Point2& p) const
342  {
343  if(coordX!=p.coordX || coordY!=p.coordY) return true;
344  return false;
345  }
351  {
352  return pAssociatedTriangle;
353  }
354 
355 
356 #if GEOM_PSEUDO3D==GEOM_TRUE
367  void setCoords(const double x_,const double y_,const double z_)
368  {
369  coordX=x_;
370  coordY=y_;
371  coordZ=z_;
372  }
383  void set(const double x_,const double y_,const double z_,int customIndex_)
384  {
385  coordX=x_;
386  coordY=y_;
387  coordZ=z_;
388  pAssociatedTriangle=NULL;
389  customIndex=customIndex_;
390 #ifdef GEOM_DBG
391  customIndex=getSeqNum();
392 #endif
393  }
394 #else
403  void set(const double x_,const double y_,int customIndex_)
404  {
405  coordX=x_;
406  coordY=y_;
407  pAssociatedTriangle=NULL;
408  customIndex=customIndex_;
409 #ifdef GEOM_DBG
410  customIndex=getSeqNum();
411 #endif
412  }
413  void change(const double x_,const double y_)
414  {
415  coordX=x_;
416  coordY=y_;
417  }
418 #endif
419 
424 #if GEOM_PSEUDO3D==GEOM_TRUE
425  void set(const Point2& pnt)
426  {
427  coordX=pnt.x();
428  coordY=pnt.y();
429  coordZ=pnt.z();
430  pAssociatedTriangle=NULL;
431  this->customIndex=pnt.customIndex;
432  }
433 #else
434  void set(const Point2& pnt)
435  {
436  coordX=pnt.x();
437  coordY=pnt.y();
438  pAssociatedTriangle=NULL;
439  this->customIndex=pnt.customIndex;
440  }
441 #endif
442 
443 
444 
460  void setCustomIndex(int customIndex_)
461  {
462  customIndex=customIndex_;
463  }
477  int getCustomIndex() const
478  {
479  return customIndex;
480  }
481 
487  {
488  pAssociatedTriangle=pT;
489  }
490 
493 Vector2 operator-(const Point2& other) const
494 {
495 #if GEOM_PSEUDO3D==GEOM_TRUE
496  double xdiff(x()-other.x());
497  double ydiff(y()-other.y());
498  double zdiff(z()-other.z());
499  return Vector2(xdiff,ydiff,zdiff);
500 #else
501  double xdiff(x()-other.x());
502  double ydiff(y()-other.y());
503  return Vector2(xdiff,ydiff);
504 #endif
505 
506 
507 }
508 
511 Point2 operator+(const Vector2& vec) const
512 {
513 #if GEOM_PSEUDO3D==GEOM_TRUE
514  return Point2(x()+vec.x(),y()+vec.y(),z()+vec.z());
515 #else
516  return Point2(x()+vec.x(),y()+vec.y());
517 #endif
518 }
519 
522 Point2 operator-(const Vector2& vec) const
523 {
524 #if GEOM_PSEUDO3D==GEOM_TRUE
525  return Point2(x()-vec.x(),y()-vec.y(),z()-vec.z());
526 #else
527  return Point2(x()-vec.x(),y()-vec.y());
528 #endif
529 }
530 
531 
532  friend std::ostream &operator<<(std::ostream &stream, const Point2& pnt);
533  friend std::istream &operator>>(std::istream &stream, Point2& pnt);
534 
535 
536 protected:
537 friend class Dt2;
538  double coordX;
539  double coordY;
540 #if GEOM_PSEUDO3D==GEOM_TRUE
541  double coordZ;
542 #endif
543  Triangle2* pAssociatedTriangle;
544  int customIndex;
545 }; // End of class
546 
548 inline std::ostream &operator<<(std::ostream &stream, const Point2& pnt)
549 {
550 #if GEOM_PSEUDO3D==GEOM_TRUE
551  stream << "Point2 ("<<&pnt<<",ci="<<pnt.customIndex<<"): "<<pnt.x()<<", "<<pnt.y()<<", "<<pnt.z();
552  //#ifndef NDEBUG
553  //stream<<", anyT="<<pnt.getIncidentTriangle();
554  //#endif
555 #else
556  stream << "Point2 ("<<&pnt<<","<<pnt.customIndex<<"): "<<pnt.x()<<", "<<pnt.y();
557 #endif
558 
559 
560  return stream;
561 }
562 
564 inline std::istream &operator>>(std::istream &stream, Point2& pnt)
565 {
566 #if GEOM_PSEUDO3D==GEOM_TRUE
567  stream >> pnt.coordX >> pnt.coordY >> pnt.coordZ;
568 #else
569  stream >> pnt.coordX >> pnt.coordY;
570 #endif
571  return stream;
572 }
573 
574 // Free functions
575 
582 inline
583 double sqDistance2D(const Point2& p0,const Point2& p1)
584 {
585  double deltaX=p1.x()-p0.x();
586  double deltaY=p1.y()-p0.y();
587  return (deltaX*deltaX+deltaY*deltaY);
588 }
589 
590 
597 inline
598 double sqDistance2D(const double x0,const double y0,const Point2& p1)
599 {
600  double deltaX=p1.x()-x0;
601  double deltaY=p1.y()-y0;
602  return (deltaX*deltaX+deltaY*deltaY);
603 }
604 
605 #if GEOM_PSEUDO3D==GEOM_TRUE
606 
611 inline
612 double sqDistance25D(const Point2& p0,const Point2& p1)
613 {
614  double deltaX=p1.x()-p0.x();
615  double deltaY=p1.y()-p0.y();
616  double deltaZ=p1.z()-p0.z();
617  double result(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
618 
619  if(result!=result)
620  {
621  std::cerr<<"warning, sqDistance25D, nan value, no distance"<<std::endl;
622  std::cerr<<"p0="<<p0<<std::endl;
623  std::cerr<<"p1="<<p1<<std::endl;
624  }
625 
626  return result;
627 }
628 
629 
634 inline
635 double sqDistance25D(const double x0,const double y0,const double z0,const Point2& p1)
636 {
637  double deltaX=p1.x()-x0;
638  double deltaY=p1.y()-y0;
639  double deltaZ=p1.z()-z0;
640  double result(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
641 
642  if(result!=result)
643  {
644  std::cerr<<"warning, sqDistance25D, nan value, no distance"<<std::endl;
645  std::cerr<<"x0="<<x0<<", y0="<<y0<<", z0="<<z0<<std::endl;
646  std::cerr<<"p1="<<p1<<std::endl;
647  }
648 
649  return result;
650 
651 }
652 
653 
654 #endif
655 
656 
657 
664 inline
665 Point2 center(const Point2& p0,const Point2& p1)
666 {
667 #if GEOM_PSEUDO3D==GEOM_TRUE
668  Point2 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0,(p0.z()+p1.z())/2.0);
669 
670 #else
671  Point2 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0);
672 #endif
673  return center;
674 }
675 
687 CLASS_DECLSPEC
688 Point2 centerWithShift(const Point2& p0,const Point2& p1);
689 
690 #if GEOM_PSEUDO3D==GEOM_TRUE
692 struct CLASS_DECLSPEC Func_ltPointXYZ
693 {
694  bool operator()(const Point2& p0,const Point2& p1) const
695  {
696  if(p0.x()<p1.x()) return true;
697  if(p0.x()>p1.x()) return false;
698  if(p0.y()<p1.y()) return true;
699  if(p0.y()>p1.y()) return false;
700  if(p0.z()<p1.z()) return true;
701  return false;
702  }
703 };
704 
705 #endif
706 
707 } // (namespace)
std::ostream & operator<<(std::ostream &stream, const Bbox2 &pC)
Print the box.
Definition: Bbox2.h:492
std::istream & operator>>(std::istream &stream, Point2 &pnt)
Stream-to-Point.
Definition: Point2.h:564
double sqDistance2D(const Point2 &p0, const Point2 &p1)
Get the squared distance between two points in 2D.
Definition: Point2.h:583
Point2 centerWithShift(const Point2 &p0, const Point2 &p1)
Compute the midpoint of p0 and p1 and adapt it.
Point2 center(const Point2 &p0, const Point2 &p1)
Compute the midpoint of p0 and p1.
Definition: Point2.h:665
Point.
Definition: Point2.h:45
void set(const Point2 &pnt)
Set the coordiantes.
Definition: Point2.h:434
Point2(const Point2 &p_)
Copy constructor.
Definition: Point2.h:158
Point2()
Default constructor.
Definition: Point2.h:147
void xy(double &x_, double &y_) const
Get the x- and y-coordinate.
Definition: Point2.h:247
void setCustomIndex(int customIndex_)
Set a custom index.
Definition: Point2.h:460
void set(const double x_, const double y_, int customIndex_)
Set the coordinates and customIndex.
Definition: Point2.h:403
double getMaxAbs() const
Get max(abs(x),abs(y))
Definition: Point2.h:273
int getCustomIndex() const
Get the custom index.
Definition: Point2.h:477
bool operator==(const Point2 &p) const
Equality operator.
Definition: Point2.h:320
bool operator>(const Point2 &p) const
Greater than operator.
Definition: Point2.h:306
Vector2 operator-(const Point2 &other) const
Returns a vector from other to *this.
Definition: Point2.h:493
void setIncidentTriangle(Triangle2 *pT)
Associate a triangle with the point.
Definition: Point2.h:486
bool operator<(const Point2 &p) const
Less than operator.
Definition: Point2.h:292
bool operator!=(const Point2 &p) const
Inequality operator.
Definition: Point2.h:341
Point2 operator-(const Vector2 &vec) const
Subtract vector from point.
Definition: Point2.h:522
Triangle2 * getIncidentTriangle() const
Get the associated triangle.
Definition: Point2.h:350
double x() const
Get the x-coordinate.
Definition: Point2.h:197
double y() const
Get the y-coordinate.
Definition: Point2.h:206
Point2 operator+(const Vector2 &vec) const
Add vector and point.
Definition: Point2.h:511
Point2(const double x_, const double y_)
Constructor.
Definition: Point2.h:135
Triangle.
Definition: Triangle2.h:60
Vector.
Definition: Vector2.h:42
double y() const
Get the y-value.
double x() const
Get the x-value.