Fade2D Documentation pages v2.16.8
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 // unclear to you.
14 //
15 // Support: https://www.geom.at/contact/
16 // Project: https://www.geom.at/fade2d/html/
17 
19 
20 #pragma once
21 
22 #include "common.h"
23 #include "Vector2.h"
24 #include <cstring>
25 
33 enum CINC2
34 {
39 };
40 
41 #if GEOM_PSEUDO3D==GEOM_TRUE
42  namespace GEOM_FADE25D {
43 #elif GEOM_PSEUDO3D==GEOM_FALSE
44  namespace GEOM_FADE2D {
45 #else
46  #error GEOM_PSEUDO3D is not defined
47 #endif
48 
49 
50 class Triangle2; // FWD
51 
53 struct VtxColor
54 {
57  VtxColor(unsigned char r_,unsigned char g_,unsigned char b_,unsigned char a_):r(r_),g(g_),b(b_),a(a_)
58  {}
59  float r,g,b,a;
60 };
61 
62 
75 class CLASS_DECLSPEC Point2
76 {
77 #ifdef GEOM_DBG
79  int getSeqNum()
80  {
81  static int seqNum(0);
82  return seqNum++;
83  }
84 #endif
85 
86 public:
87 
88 #if GEOM_PSEUDO3D==GEOM_TRUE
95  Point2(const double x_,const double y_,const double z_):
96  coordX(x_),
97  coordY(y_),
98  coordZ(z_),
99  pAssociatedTriangle(NULL),
100  customIndex(-1)
101  {
102 #ifdef GEOM_DBG
103  customIndex=getSeqNum();
104 #endif
105  }
106 
107 
114  Point2():coordX(-DBL_MAX),coordY(-DBL_MAX),coordZ(-DBL_MAX),pAssociatedTriangle(NULL),customIndex(-1)
115  {
116 #ifdef GEOM_DBG
117  customIndex=getSeqNum();
118 #endif
119  }
126  Point2(const Point2& p_):
127  coordX(p_.x()),
128  coordY(p_.y()),
129  coordZ(p_.z()),
130  pAssociatedTriangle(NULL),
131  customIndex(p_.customIndex)
132  {
133  }
140  Point2 &operator=(const Point2& other)
141  {
142  coordX=other.x();
143  coordY=other.y();
144  coordZ=other.z();
145  pAssociatedTriangle=NULL;
146  customIndex=other.customIndex;
147  return *this;
148  }
149 
151  void setZ(double z)
152  {
153  setHeight(z);
154  }
155 
157  void print()
158  {
159  GCOUT<<coordX<<" "<<coordY<<" "<<coordZ<<std::endl;
160  }
161 #else
168  Point2(const double x_,const double y_):
169  coordX(x_),
170  coordY(y_),
171  pAssociatedTriangle(NULL),
172  customIndex(-1)
173  {
174  //BC("Point2 Constructor default");
175  }
181  coordX(-DBL_MAX),
182  coordY(-DBL_MAX),
183  pAssociatedTriangle(NULL),
184  customIndex(-1)
185  {
186  }
193  Point2(const Point2& p_):
194  coordX(p_.x()),
195  coordY(p_.y()),
196  pAssociatedTriangle(NULL),
197  customIndex(p_.customIndex)
198  {
199  }
206  Point2 &operator=(const Point2& other)
207  {
208  coordX=other.x();
209  coordY=other.y();
210  pAssociatedTriangle=NULL;
211  customIndex=other.customIndex;
212  return *this;
213  }
214 
216  void print()
217  {
218  GCOUT<<coordX<<" "<<coordY<<std::endl;
219  }
220 #endif
221 
227  {
228  }
229 
230 
239  double x() const
240  {
241  return coordX;
242  }
250  double y() const
251  {
252  return coordY;
253  }
254 
255 #if GEOM_PSEUDO3D==GEOM_TRUE
263  double z() const
264  {
265  return coordZ;
266  }
267 #endif
268 
269 #if GEOM_PSEUDO3D==GEOM_TRUE
277  void xyz(double& x_,double& y_,double& z_) const
278  {
279  x_=coordX;
280  y_=coordY;
281  z_=coordZ;
282  }
283 #endif
291  void xy(double& x_,double& y_) const
292  {
293  x_=coordX;
294  y_=coordY;
295  }
296 
297 
298 #if GEOM_PSEUDO3D==GEOM_TRUE
306  void setHeight(double z)
307  {
308  coordZ=z;
309  }
310 #endif
318  double getMaxAbs() const
319  {
320  double a(fabs(coordX));
321  double b(fabs(coordY));
322  return (std::max)(a,b);
323  }
337  bool operator<(const Point2& p) const
338  {
339  if(coordX<p.coordX) return true;
340  if(coordX>p.coordX) return false;
341  if(coordY<p.coordY) return true;
342  return false;
343  }
357  bool operator>(const Point2& p) const
358  {
359  if(coordX>p.coordX) return true;
360  if(coordX<p.coordX) return false;
361  if(coordY>p.coordY) return true;
362  return false;
363  }
376  bool operator==(const Point2& p) const
377  {
378  return (coordX==p.coordX && coordY==p.coordY);
379  }
380 #if GEOM_PSEUDO3D==GEOM_TRUE
392  bool samePoint(const Point2& p) const
393  {
394  return(coordX==p.coordX && coordY==p.coordY && coordZ==p.coordZ);
395  }
396 #endif
410  bool operator!=(const Point2& p) const
411  {
412  if(coordX!=p.coordX || coordY!=p.coordY) return true;
413  return false;
414  }
415 
421  Triangle2* getIncidentTriangle() const
422  {
423  return pAssociatedTriangle;
424  }
425 
426 
427 #if GEOM_PSEUDO3D==GEOM_TRUE
434  void setCoords(const double x_,const double y_,const double z_)
435  {
436  coordX=x_;
437  coordY=y_;
438  coordZ=z_;
439  }
445  void set(const double x_,const double y_,const double z_,int customIndex_)
446  {
447  coordX=x_;
448  coordY=y_;
449  coordZ=z_;
450  pAssociatedTriangle=NULL;
451  customIndex=customIndex_;
452 #ifdef GEOM_DBG
453  customIndex=getSeqNum();
454 #endif
455  }
456 #else
464  void set(const double x_,const double y_,int customIndex_)
465  {
466  coordX=x_;
467  coordY=y_;
468  pAssociatedTriangle=NULL;
469  customIndex=customIndex_;
470 #ifdef GEOM_DBG
471  customIndex=getSeqNum();
472 #endif
473  }
479  void change(const double x_,const double y_)
480  {
481  coordX=x_;
482  coordY=y_;
483  }
484 #endif
485 
490 #if GEOM_PSEUDO3D==GEOM_TRUE
491  void set(const Point2& pnt)
492  {
493  pnt.xyz(coordX,coordY,coordZ);
494  pAssociatedTriangle=NULL;
495  this->customIndex=pnt.customIndex;
496  }
497 #else
498  void set(const Point2& pnt)
499  {
500  pnt.xy(coordX,coordY);
501  pAssociatedTriangle=NULL;
502  this->customIndex=pnt.customIndex;
503  }
504 #endif
505 
506 
507 
523  void setCustomIndex(int customIndex_)
524  {
525  customIndex=customIndex_;
526  }
539  int getCustomIndex() const
540  {
541  return customIndex;
542  }
543 
551  void setIncidentTriangle(Triangle2* pT)
552  {
553  pAssociatedTriangle=pT;
554  }
555 
565 Vector2 operator-(const Point2& other) const
566 {
567 #if GEOM_PSEUDO3D==GEOM_TRUE
568  double xdiff(x()-other.x());
569  double ydiff(y()-other.y());
570  double zdiff(z()-other.z());
571  return Vector2(xdiff,ydiff,zdiff);
572 #else
573  double xdiff(x()-other.x());
574  double ydiff(y()-other.y());
575  return Vector2(xdiff,ydiff);
576 #endif
577 
578 
579 }
580 
589 Point2 operator+(const Vector2& vec) const
590 {
591 #if GEOM_PSEUDO3D==GEOM_TRUE
592  return Point2(x()+vec.x(),y()+vec.y(),z()+vec.z());
593 #else
594  return Point2(x()+vec.x(),y()+vec.y());
595 #endif
596 }
605 Point2 operator-(const Vector2& vec) const
606 {
607 #if GEOM_PSEUDO3D==GEOM_TRUE
608  return Point2(x()-vec.x(),y()-vec.y(),z()-vec.z());
609 #else
610  return Point2(x()-vec.x(),y()-vec.y());
611 #endif
612 }
613 friend std::ostream &operator<<(std::ostream &stream, const Point2& pnt);
614 friend std::istream &operator>>(std::istream &stream, Point2& pnt);
615 
616 protected:
617  friend class Dt2;
618  double coordX;
619  double coordY;
620 #if GEOM_PSEUDO3D==GEOM_TRUE
621  double coordZ;
622 #endif
623  Triangle2* pAssociatedTriangle;
625 }; // End of class
626 
635 inline std::ostream &operator<<(std::ostream &stream, const Point2& pnt)
636 {
637 #if GEOM_PSEUDO3D==GEOM_TRUE
638  stream << "Point2 ("<<&pnt<<",ci="<<pnt.customIndex<<"): "<<pnt.x()<<", "<<pnt.y()<<", "<<pnt.z();
639  //#ifndef NDEBUG
640  //stream<<", anyT="<<pnt.getIncidentTriangle();
641  //#endif
642 #else
643  stream << "Point2 ("<<&pnt<<","<<pnt.customIndex<<"): "<<pnt.x()<<", "<<pnt.y();
644 #endif
645 
646 
647  return stream;
648 }
649 
658 inline std::istream &operator>>(std::istream &stream, Point2& pnt)
659 {
660 #if GEOM_PSEUDO3D==GEOM_TRUE
661  stream >> pnt.coordX >> pnt.coordY >> pnt.coordZ;
662 #else
663  stream >> pnt.coordX >> pnt.coordY;
664 #endif
665  return stream;
666 }
667 
668 // Free functions
669 
681 inline
682 double sqDistance2D(const Point2& p0,const Point2& p1)
683 {
684  double deltaX=p1.x()-p0.x();
685  double deltaY=p1.y()-p0.y();
686  return (deltaX*deltaX+deltaY*deltaY);
687 }
688 
689 
702 inline
703 double sqDistance2D(const double x0,const double y0,const Point2& p1)
704 {
705  double deltaX=p1.x()-x0;
706  double deltaY=p1.y()-y0;
707  return (deltaX*deltaX+deltaY*deltaY);
708 }
709 
710 #if GEOM_PSEUDO3D==GEOM_TRUE
711 
719 inline
720 double sqDistance25D(const Point2& p0,const Point2& p1)
721 {
722  double deltaX=p1.x()-p0.x();
723  double deltaY=p1.y()-p0.y();
724  double deltaZ=p1.z()-p0.z();
725  double result(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
726 
727  if(result!=result)
728  {
729  GCOUT<<"warning, sqDistance25D, nan value, no distance"<<std::endl;
730  GCOUT<<"p0="<<p0<<std::endl;
731  GCOUT<<"p1="<<p1<<std::endl;
732  }
733 
734  return result;
735 }
736 
737 
747 inline
748 double sqDistance25D(const double x0,const double y0,const double z0,const Point2& p1)
749 {
750  double deltaX=p1.x()-x0;
751  double deltaY=p1.y()-y0;
752  double deltaZ=p1.z()-z0;
753  double result(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
754 
755  if(result!=result)
756  {
757  GCOUT<<"warning, sqDistance25D, nan value, no distance"<<std::endl;
758  GCOUT<<"x0="<<x0<<", y0="<<y0<<", z0="<<z0<<std::endl;
759  GCOUT<<"p1="<<p1<<std::endl;
760  }
761 
762  return result;
763 
764 }
765 #endif
766 
767 
781 inline
782 Point2 center(const Point2& p0,const Point2& p1)
783 {
784 #if GEOM_PSEUDO3D==GEOM_TRUE
785  Point2 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0,(p0.z()+p1.z())/2.0);
786 
787 #else
788  Point2 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0);
789 #endif
790  return center;
791 }
792 
809 CLASS_DECLSPEC
810 Point2 centerWithShift(const Point2& p0,const Point2& p1);
811 
812 #if GEOM_PSEUDO3D==GEOM_TRUE
814 struct CLASS_DECLSPEC Func_ltPointXYZ
815 {
816  bool operator()(const Point2& p0,const Point2& p1) const
817  {
818  if(p0.x()<p1.x()) return true;
819  if(p0.x()>p1.x()) return false;
820  if(p0.y()<p1.y()) return true;
821  if(p0.y()>p1.y()) return false;
822  return p0.z()<p1.z();
823  }
824 };
826 struct CLASS_DECLSPEC Func_samePointXYZ
827 {
828  bool operator()(const Point2& p0,const Point2& p1) const
829  {
830  return p0.x()==p1.x() && p0.y()==p1.y() && p0.z()==p1.z();
831  }
832 };
833 #endif
834 
835 } // (namespace)
std::ostream & operator<<(std::ostream &stream, const Bbox2 &pC)
Prints the bounding box to a stream.
Definition: Bbox2.h:605
CINC2
Enum for the position of a point relative to a circle.
Definition: Point2.h:34
@ CINC2_UNKNOWN
Invalid value (undefined)
Definition: Point2.h:35
@ CINC2_ZERO
Point lies exactly on the circumference of the circle.
Definition: Point2.h:36
@ CINC2_OUTCIRCLE
Point lies outside the circle.
Definition: Point2.h:38
@ CINC2_INCIRCLE
Point lies inside the circle.
Definition: Point2.h:37
std::istream & operator>>(std::istream &stream, Point2 &pnt)
Read coordinates from an input stream into a Point2.
Definition: Point2.h:658
double sqDistance2D(const Point2 &p0, const Point2 &p1)
Get the squared 2D distance between two points.
Definition: Point2.h:682
Point2 center(const Point2 &p0, const Point2 &p1)
Compute the midpoint of points p0 and p1.
Definition: Point2.h:782
Represents a 2D point.
Definition: Point2.h:76
Point2(const Point2 &p_)
Copy constructor.
Definition: Point2.h:193
Point2()
Default constructor.
Definition: Point2.h:180
double coordY
y-coordinate
Definition: Point2.h:619
int customIndex
User-defined index.
Definition: Point2.h:624
void xy(double &x_, double &y_) const
Get the x- and y- coordinates of the Point2.
Definition: Point2.h:291
void setCustomIndex(int customIndex_)
Sets a custom index for the Point2.
Definition: Point2.h:523
double getMaxAbs() const
Get the larger of the absolute values of x and y.
Definition: Point2.h:318
int getCustomIndex() const
Retrieves the custom index of the Point2.
Definition: Point2.h:539
bool operator==(const Point2 &p) const
Compares if the current Point2 is equal to another one.
Definition: Point2.h:376
bool operator>(const Point2 &p) const
Compare if the current Point2 is greater than another one.
Definition: Point2.h:357
Vector2 operator-(const Point2 &other) const
Create a Vector2 by subtracing another Point2 from the current one.
Definition: Point2.h:565
bool operator<(const Point2 &p) const
Compare if the current Point2 is less than another one.
Definition: Point2.h:337
bool operator!=(const Point2 &p) const
Compares if the current Point2 is different from another one.
Definition: Point2.h:410
Point2 operator-(const Vector2 &vec) const
Subtract a Vector2 from the Point2.
Definition: Point2.h:605
double coordX
x-coordinate
Definition: Point2.h:618
double x() const
Get the x-coordinate of the Point2.
Definition: Point2.h:239
~Point2()
Destructor.
Definition: Point2.h:226
Point2 & operator=(const Point2 &other)
Assignment operator.
Definition: Point2.h:206
double y() const
Get the y-coordinate of the Point2.
Definition: Point2.h:250
Point2 operator+(const Vector2 &vec) const
Add a Vector2 to the Point2.
Definition: Point2.h:589
Point2(const double x_, const double y_)
Constructor.
Definition: Point2.h:168
Represents a triangle in a triangulation.
Definition: Triangle2.h:59
Vector.
Definition: Vector2.h:47
double y() const
Get the y-value.
double x() const
Get the x-value.
Structure to store vertex color (RGBA).
Definition: Point2.h:54
VtxColor(unsigned char r_, unsigned char g_, unsigned char b_, unsigned char a_)
Constructor.
Definition: Point2.h:57