Fade2.5D Documentation pages v2.16.3
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 #include <cstring>
25 
26 #if GEOM_PSEUDO3D==GEOM_TRUE
27  namespace GEOM_FADE25D {
28 #elif GEOM_PSEUDO3D==GEOM_FALSE
29  namespace GEOM_FADE2D {
30 #else
31  #error GEOM_PSEUDO3D is not defined
32 #endif
33 
34 
35 class Triangle2; // FWD
36 
37 
38 
39 struct VtxColor
40 {
41  VtxColor(unsigned char r_,unsigned char g_,unsigned char b_,unsigned char a_):r(r_),g(g_),b(b_),a(a_)
42  {}
43  float r,g,b,a;
44 };
45 
46 
52 class CLASS_DECLSPEC Point2
53 {
54 #ifdef GEOM_DBG
55  int getSeqNum()
56  {
57  static int seqNum(0);
58  return seqNum++;
59  }
60 #endif
61 
62 public:
63 
64 #if GEOM_PSEUDO3D==GEOM_TRUE
71  Point2(const double x_,const double y_,const double z_):
72  coordX(x_),
73  coordY(y_),
74  coordZ(z_),
75  pAssociatedTriangle(NULL),
76  customIndex(-1)
77  {
78 #ifdef GEOM_DBG
79  customIndex=getSeqNum();
80 #endif
81  }
82 
83 
87  Point2():coordX(-DBL_MAX),coordY(-DBL_MAX),coordZ(-DBL_MAX),pAssociatedTriangle(NULL),customIndex(-1)
88  {
89 #ifdef GEOM_DBG
90  customIndex=getSeqNum();
91 #endif
92  }
97  Point2(const Point2& p_):
98  coordX(p_.x()),
99  coordY(p_.y()),
100  coordZ(p_.z()),
101  pAssociatedTriangle(NULL),
102  customIndex(p_.customIndex)
103  {
104  }
105 
106  Point2 &operator=(const Point2& other)
107  {
108  coordX=other.x();
109  coordY=other.y();
110  coordZ=other.z();
111  pAssociatedTriangle=NULL;
112  customIndex=other.customIndex;
113  return *this;
114  }
115 
116 
117 // Deprecated, use setHeight() instead. Kept for backward compatibility
120  void setZ(double z)
121  {
122  setHeight(z);
123  }
124 
125 
128  void print()
129  {
130  std::cout<<coordX<<" "<<coordY<<" "<<coordZ<<std::endl;
131  }
132 
133 
134 
135 #else
136 
137 
143  Point2(const double x_,const double y_):
144  coordX(x_),
145  coordY(y_),
146  pAssociatedTriangle(NULL),
147  customIndex(-1)
148  {
149  //BC("Point2 Constructor default");
150  }
155  Point2():
156  coordX(-DBL_MAX),
157  coordY(-DBL_MAX),
158  pAssociatedTriangle(NULL),
159  customIndex(-1)
160  {
161  }
166  Point2(const Point2& p_):
167  coordX(p_.x()),
168  coordY(p_.y()),
169  pAssociatedTriangle(NULL),
170  customIndex(p_.customIndex)
171  {
172  }
173 
174  Point2 &operator=(const Point2& other)
175  {
176  coordX=other.x();
177  coordY=other.y();
178  pAssociatedTriangle=NULL;
179  customIndex=other.customIndex;
180  return *this;
181  }
182 
185  void print()
186  {
187  std::cout<<coordX<<" "<<coordY<<std::endl;
188  }
189 
190 #endif
191 
192  ~Point2()
193  {
194  }
195 
201  double x() const
202  {
203  return coordX;
204  }
210  double y() const
211  {
212  return coordY;
213  }
214 
215 #if GEOM_PSEUDO3D==GEOM_TRUE
221  double z() const
222  {
223  return coordZ;
224  }
225 #endif
226 
227 #if GEOM_PSEUDO3D==GEOM_TRUE
236  void xyz(double& x_,double& y_,double& z_) const
237  {
238  x_=coordX;
239  y_=coordY;
240  z_=coordZ;
241  }
242 #endif
243 
251  void xy(double& x_,double& y_) const
252  {
253  x_=coordX;
254  y_=coordY;
255  }
256 
257 
258 #if GEOM_PSEUDO3D==GEOM_TRUE
264  void setHeight(double z)
265  {
266  coordZ=z;
267  }
268 #endif
269 
270 
271 
272 
277  double getMaxAbs() const
278  {
279  double a(fabs(coordX));
280  double b(fabs(coordY));
281  return (std::max)(a,b);
282  }
283 
284 
285 
286 
287 
288 
296  bool operator<(const Point2& p) const
297  {
298  if(coordX<p.coordX) return true;
299  if(coordX>p.coordX) return false;
300  if(coordY<p.coordY) return true;
301  return false;
302  }
310  bool operator>(const Point2& p) const
311  {
312  if(coordX>p.coordX) return true;
313  if(coordX<p.coordX) return false;
314  if(coordY>p.coordY) return true;
315  return false;
316  }
324  bool operator==(const Point2& p) const
325  {
326  return (coordX==p.coordX && coordY==p.coordY);
327  }
328 #if GEOM_PSEUDO3D==GEOM_TRUE
334  bool samePoint(const Point2& p) const
335  {
336  return(coordX==p.coordX && coordY==p.coordY && coordZ==p.coordZ);
337  }
338 #endif
345  bool operator!=(const Point2& p) const
346  {
347  if(coordX!=p.coordX || coordY!=p.coordY) return true;
348  return false;
349  }
355  {
356  return pAssociatedTriangle;
357  }
358 
359 
360 #if GEOM_PSEUDO3D==GEOM_TRUE
371  void setCoords(const double x_,const double y_,const double z_)
372  {
373  coordX=x_;
374  coordY=y_;
375  coordZ=z_;
376  }
387  void set(const double x_,const double y_,const double z_,int customIndex_)
388  {
389  coordX=x_;
390  coordY=y_;
391  coordZ=z_;
392  pAssociatedTriangle=NULL;
393  customIndex=customIndex_;
394 #ifdef GEOM_DBG
395  customIndex=getSeqNum();
396 #endif
397  }
398 #else
407  void set(const double x_,const double y_,int customIndex_)
408  {
409  coordX=x_;
410  coordY=y_;
411  pAssociatedTriangle=NULL;
412  customIndex=customIndex_;
413 #ifdef GEOM_DBG
414  customIndex=getSeqNum();
415 #endif
416  }
417  void change(const double x_,const double y_)
418  {
419  coordX=x_;
420  coordY=y_;
421  }
422 #endif
423 
428 #if GEOM_PSEUDO3D==GEOM_TRUE
429  void set(const Point2& pnt)
430  {
431  pnt.xyz(coordX,coordY,coordZ);
432  pAssociatedTriangle=NULL;
433  this->customIndex=pnt.customIndex;
434  }
435 #else
436  void set(const Point2& pnt)
437  {
438  pnt.xy(coordX,coordY);
439  pAssociatedTriangle=NULL;
440  this->customIndex=pnt.customIndex;
441  }
442 #endif
443 
444 
445 
461  void setCustomIndex(int customIndex_)
462  {
463  customIndex=customIndex_;
464  }
478  int getCustomIndex() const
479  {
480  return customIndex;
481  }
482 
488  {
489  pAssociatedTriangle=pT;
490  }
491 
494 Vector2 operator-(const Point2& other) const
495 {
496 #if GEOM_PSEUDO3D==GEOM_TRUE
497  double xdiff(x()-other.x());
498  double ydiff(y()-other.y());
499  double zdiff(z()-other.z());
500  return Vector2(xdiff,ydiff,zdiff);
501 #else
502  double xdiff(x()-other.x());
503  double ydiff(y()-other.y());
504  return Vector2(xdiff,ydiff);
505 #endif
506 
507 
508 }
509 
512 Point2 operator+(const Vector2& vec) const
513 {
514 #if GEOM_PSEUDO3D==GEOM_TRUE
515  return Point2(x()+vec.x(),y()+vec.y(),z()+vec.z());
516 #else
517  return Point2(x()+vec.x(),y()+vec.y());
518 #endif
519 }
520 
523 Point2 operator-(const Vector2& vec) const
524 {
525 #if GEOM_PSEUDO3D==GEOM_TRUE
526  return Point2(x()-vec.x(),y()-vec.y(),z()-vec.z());
527 #else
528  return Point2(x()-vec.x(),y()-vec.y());
529 #endif
530 }
531 
532 
533  friend std::ostream &operator<<(std::ostream &stream, const Point2& pnt);
534  friend std::istream &operator>>(std::istream &stream, Point2& pnt);
535 
536 
537 protected:
538 friend class Dt2;
539  double coordX;
540  double coordY;
541 #if GEOM_PSEUDO3D==GEOM_TRUE
542  double coordZ;
543 #endif
544  Triangle2* pAssociatedTriangle;
545  int customIndex;
546 }; // End of class
547 
549 inline std::ostream &operator<<(std::ostream &stream, const Point2& pnt)
550 {
551 #if GEOM_PSEUDO3D==GEOM_TRUE
552  stream << "Point2 ("<<&pnt<<",ci="<<pnt.customIndex<<"): "<<pnt.x()<<", "<<pnt.y()<<", "<<pnt.z();
553  //#ifndef NDEBUG
554  //stream<<", anyT="<<pnt.getIncidentTriangle();
555  //#endif
556 #else
557  stream << "Point2 ("<<&pnt<<","<<pnt.customIndex<<"): "<<pnt.x()<<", "<<pnt.y();
558 #endif
559 
560 
561  return stream;
562 }
563 
565 inline std::istream &operator>>(std::istream &stream, Point2& pnt)
566 {
567 #if GEOM_PSEUDO3D==GEOM_TRUE
568  stream >> pnt.coordX >> pnt.coordY >> pnt.coordZ;
569 #else
570  stream >> pnt.coordX >> pnt.coordY;
571 #endif
572  return stream;
573 }
574 
575 // Free functions
576 
583 inline
584 double sqDistance2D(const Point2& p0,const Point2& p1)
585 {
586  double deltaX=p1.x()-p0.x();
587  double deltaY=p1.y()-p0.y();
588  return (deltaX*deltaX+deltaY*deltaY);
589 }
590 
591 
598 inline
599 double sqDistance2D(const double x0,const double y0,const Point2& p1)
600 {
601  double deltaX=p1.x()-x0;
602  double deltaY=p1.y()-y0;
603  return (deltaX*deltaX+deltaY*deltaY);
604 }
605 
606 #if GEOM_PSEUDO3D==GEOM_TRUE
607 
612 inline
613 double sqDistance25D(const Point2& p0,const Point2& p1)
614 {
615  double deltaX=p1.x()-p0.x();
616  double deltaY=p1.y()-p0.y();
617  double deltaZ=p1.z()-p0.z();
618  double result(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
619 
620  if(result!=result)
621  {
622  std::cerr<<"warning, sqDistance25D, nan value, no distance"<<std::endl;
623  std::cerr<<"p0="<<p0<<std::endl;
624  std::cerr<<"p1="<<p1<<std::endl;
625  }
626 
627  return result;
628 }
629 
630 
635 inline
636 double sqDistance25D(const double x0,const double y0,const double z0,const Point2& p1)
637 {
638  double deltaX=p1.x()-x0;
639  double deltaY=p1.y()-y0;
640  double deltaZ=p1.z()-z0;
641  double result(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
642 
643  if(result!=result)
644  {
645  std::cerr<<"warning, sqDistance25D, nan value, no distance"<<std::endl;
646  std::cerr<<"x0="<<x0<<", y0="<<y0<<", z0="<<z0<<std::endl;
647  std::cerr<<"p1="<<p1<<std::endl;
648  }
649 
650  return result;
651 
652 }
653 
654 
655 #endif
656 
657 
658 
665 inline
666 Point2 center(const Point2& p0,const Point2& p1)
667 {
668 #if GEOM_PSEUDO3D==GEOM_TRUE
669  Point2 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0,(p0.z()+p1.z())/2.0);
670 
671 #else
672  Point2 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0);
673 #endif
674  return center;
675 }
676 
688 CLASS_DECLSPEC
689 Point2 centerWithShift(const Point2& p0,const Point2& p1);
690 
691 #if GEOM_PSEUDO3D==GEOM_TRUE
693 struct CLASS_DECLSPEC Func_ltPointXYZ
694 {
695  bool operator()(const Point2& p0,const Point2& p1) const
696  {
697  if(p0.x()<p1.x()) return true;
698  if(p0.x()>p1.x()) return false;
699  if(p0.y()<p1.y()) return true;
700  if(p0.y()>p1.y()) return false;
701  return p0.z()<p1.z();
702  }
703 };
705 struct CLASS_DECLSPEC Func_samePointXYZ
706 {
707  bool operator()(const Point2& p0,const Point2& p1) const
708  {
709  return p0.x()==p1.x() && p0.y()==p1.y() && p0.z()==p1.z();
710  }
711 };
712 #endif
713 
714 } // (namespace)
double sqDistance25D(const Point2 &p0, const Point2 &p1)
Get the squared distance between two points.
Definition: Point2.h:613
std::istream & operator>>(std::istream &stream, Point2 &pnt)
Stream-to-Point.
Definition: Point2.h:565
double sqDistance2D(const Point2 &p0, const Point2 &p1)
Get the squared distance between two points in 2D.
Definition: Point2.h:584
Point2 center(const Point2 &p0, const Point2 &p1)
Compute the midpoint of p0 and p1.
Definition: Point2.h:666
Point2 centerWithShift(const Point2 &p0, const Point2 &p1)
Compute the midpoint of p0 and p1 and adapt it.
Point.
Definition: Point2.h:53
double getMaxAbs() const
Get max(abs(x),abs(y))
Definition: Point2.h:277
double z() const
Get the z-coordinate.
Definition: Point2.h:221
bool operator!=(const Point2 &p) const
Inequality operator.
Definition: Point2.h:345
void xy(double &x_, double &y_) const
Get the x- and y-coordinate.
Definition: Point2.h:251
bool operator==(const Point2 &p) const
Equality operator.
Definition: Point2.h:324
Point2 operator+(const Vector2 &vec) const
Add vector and point.
Definition: Point2.h:512
void setCoords(const double x_, const double y_, const double z_)
Set the coordinates.
Definition: Point2.h:371
void setIncidentTriangle(Triangle2 *pT)
Associate a triangle with the point.
Definition: Point2.h:487
int getCustomIndex() const
Get the custom index.
Definition: Point2.h:478
void setCustomIndex(int customIndex_)
Set a custom index.
Definition: Point2.h:461
double y() const
Get the y-coordinate.
Definition: Point2.h:210
bool operator>(const Point2 &p) const
Greater than operator.
Definition: Point2.h:310
Point2()
Default constructor.
Definition: Point2.h:87
void set(const double x_, const double y_, const double z_, int customIndex_)
Set the coordinates.
Definition: Point2.h:387
bool samePoint(const Point2 &p) const
Equality operator.
Definition: Point2.h:334
void setHeight(double z)
Set the z-coordinate.
Definition: Point2.h:264
double x() const
Get the x-coordinate.
Definition: Point2.h:201
Triangle2 * getIncidentTriangle() const
Get the associated triangle.
Definition: Point2.h:354
void xyz(double &x_, double &y_, double &z_) const
Get the x-, y- and z-coordinate.
Definition: Point2.h:236
void set(const Point2 &pnt)
Set the coordiantes.
Definition: Point2.h:429
Point2 operator-(const Vector2 &vec) const
Subtract vector from point.
Definition: Point2.h:523
bool operator<(const Point2 &p) const
Less than operator.
Definition: Point2.h:296
Point2(const Point2 &p_)
Copy constructor.
Definition: Point2.h:97
Vector2 operator-(const Point2 &other) const
Returns a vector from other to *this.
Definition: Point2.h:494
Point2(const double x_, const double y_, const double z_)
Constructor.
Definition: Point2.h:71
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:694
Functor to compare two points in 3 dimensions.
Definition: Point2.h:706
Definition: Point2.h:40