Fade2D Documentation pages v1.86
Delaunay Features
Point2.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 
18 #pragma once
19 
20 #include "common.h"
21 #include "Vector2.h"
22 
23 #if GEOM_PSEUDO3D==GEOM_TRUE
24  namespace GEOM_FADE25D {
25 #elif GEOM_PSEUDO3D==GEOM_FALSE
26  namespace GEOM_FADE2D {
27 #else
28  #error GEOM_PSEUDO3D is not defined
29 #endif
30 
31 
32 class Triangle2; // FWD
33 
34 
40 class CLASS_DECLSPEC Point2
41 {
42 #ifdef GEOM_DBG
43  int getSeqNum()
44  {
45  static int seqNum(0);
46  return seqNum++;
47  }
48 #endif
49 
50 public:
51 
52 #if GEOM_PSEUDO3D==GEOM_TRUE
53 
59  Point2(const double x_,const double y_,const double z_):
60  coordX(x_),
61  coordY(y_),
62  coordZ(z_),
63  pAssociatedTriangle(NULL),
64  customIndex(-1)
65  {
66 #ifdef GEOM_DBG
67  customIndex=getSeqNum();
68 #endif
69  }
70 
71 
75  Point2():coordX(-DBL_MAX),coordY(-DBL_MAX),coordZ(-DBL_MAX),pAssociatedTriangle(NULL),customIndex(-1)
76  {
77 #ifdef GEOM_DBG
78  customIndex=getSeqNum();
79 #endif
80  }
85  Point2(const Point2& p_):
86  coordX(p_.x()),
87  coordY(p_.y()),
88  coordZ(p_.z()),
89  pAssociatedTriangle(NULL),
90  customIndex(p_.customIndex)
91  {
92  }
93 
94  Point2 &operator=(const Point2& other)
95  {
96  coordX=other.x();
97  coordY=other.y();
98  coordZ=other.z();
99  pAssociatedTriangle=NULL;
100  customIndex=other.customIndex;
101  return *this;
102  }
103 
104 
105 // Deprecated, use setHeight() instead. Kept for backward compatibility
108  void setZ(double z)
109  {
110  setHeight(z);
111  }
112 
113 
116  void print()
117  {
118  std::cout<<coordX<<" "<<coordY<<" "<<coordZ<<std::endl;
119  }
120 
121 
122 
123 #else
124 
125 
131  Point2(const double x_,const double y_):
132  coordX(x_),
133  coordY(y_),
134  pAssociatedTriangle(NULL),
135  customIndex(-1)
136  {
137  //BC("Point2 Constructor default");
138  }
144  coordX(-DBL_MAX),
145  coordY(-DBL_MAX),
146  pAssociatedTriangle(NULL),
147  customIndex(-1)
148  {
149  }
154  Point2(const Point2& p_):
155  coordX(p_.x()),
156  coordY(p_.y()),
157  pAssociatedTriangle(NULL),
158  customIndex(p_.customIndex)
159  {
160  }
161 
162  Point2 &operator=(const Point2& other)
163  {
164  coordX=other.x();
165  coordY=other.y();
166  pAssociatedTriangle=NULL;
167  customIndex=other.customIndex;
168  return *this;
169  }
170 
173  void print()
174  {
175  std::cout<<coordX<<" "<<coordY<<std::endl;
176  }
177 
178 #endif
179 
180 
181 
182 
183 
184  ~Point2()
185  {
186  }
187 
193  double x() const
194  {
195  return coordX;
196  }
202  double y() const
203  {
204  return coordY;
205  }
206 
207 #if GEOM_PSEUDO3D==GEOM_TRUE
208 
213  double z() const
214  {
215  return coordZ;
216  }
217 #endif
218 
219 #if GEOM_PSEUDO3D==GEOM_TRUE
220 
228  void xyz(double& x_,double& y_,double& z_) const
229  {
230  x_=coordX;
231  y_=coordY;
232  z_=coordZ;
233  }
234 #endif
235 
243  void xy(double& x_,double& y_) const
244  {
245  x_=coordX;
246  y_=coordY;
247  }
248 
249 
250 #if GEOM_PSEUDO3D==GEOM_TRUE
251 
256  void setHeight(double z)
257  {
258  coordZ=z;
259  }
260 #endif
261 
262 
263 
264 
269  double getMaxAbs() const
270  {
271  double a(fabs(coordX));
272  double b(fabs(coordY));
273  return (std::max)(a,b);
274  }
275 
276 
277 
278 
279 
280 
288  bool operator<(const Point2& p) const
289  {
290  if(coordX<p.coordX) return true;
291  if(coordX>p.coordX) return false;
292  if(coordY<p.coordY) return true;
293  return false;
294  }
302  bool operator>(const Point2& p) const
303  {
304  if(coordX>p.coordX) return true;
305  if(coordX<p.coordX) return false;
306  if(coordY>p.coordY) return true;
307  return false;
308  }
316  bool operator==(const Point2& p) const
317  {
318  return (coordX==p.coordX && coordY==p.coordY);
319  }
320 #if GEOM_PSEUDO3D==GEOM_TRUE
321 
326  bool samePoint(const Point2& p) const
327  {
328  return(coordX==p.coordX && coordY==p.coordY && coordZ==p.coordZ);
329  }
330 #endif
331 
337  bool operator!=(const Point2& p) const
338  {
339  if(coordX!=p.coordX || coordY!=p.coordY) return true;
340  return false;
341  }
347  {
348  return pAssociatedTriangle;
349  }
350 
351 
352 #if GEOM_PSEUDO3D==GEOM_TRUE
353 
363  void setCoords(const double x_,const double y_,const double z_)
364  {
365  coordX=x_;
366  coordY=y_;
367  coordZ=z_;
368  }
379  void set(const double x_,const double y_,const double z_,int customIndex_)
380  {
381  coordX=x_;
382  coordY=y_;
383  coordZ=z_;
384  pAssociatedTriangle=NULL;
385  customIndex=customIndex_;
386 #ifdef GEOM_DBG
387  customIndex=getSeqNum();
388 #endif
389  }
390 #else
391 
399  void set(const double x_,const double y_,int customIndex_)
400  {
401  coordX=x_;
402  coordY=y_;
403  pAssociatedTriangle=NULL;
404  customIndex=customIndex_;
405 #ifdef GEOM_DBG
406  customIndex=getSeqNum();
407 #endif
408  }
409  void change(const double x_,const double y_)
410  {
411  coordX=x_;
412  coordY=y_;
413  }
414 #endif
415 
420 #if GEOM_PSEUDO3D==GEOM_TRUE
421  void set(const Point2& pnt)
422  {
423  coordX=pnt.x();
424  coordY=pnt.y();
425  coordZ=pnt.z();
426  pAssociatedTriangle=NULL;
427  this->customIndex=pnt.customIndex;
428  }
429 #else
430  void set(const Point2& pnt)
431  {
432  coordX=pnt.x();
433  coordY=pnt.y();
434  pAssociatedTriangle=NULL;
435  this->customIndex=pnt.customIndex;
436  }
437 #endif
438 
439 
440 
456  void setCustomIndex(int customIndex_)
457  {
458  customIndex=customIndex_;
459  }
473  int getCustomIndex() const
474  {
475  return customIndex;
476  }
477 
483  {
484  pAssociatedTriangle=pT;
485  }
486 
489 Vector2 operator-(const Point2& other) const
490 {
491 #if GEOM_PSEUDO3D==GEOM_TRUE
492  double xdiff(x()-other.x());
493  double ydiff(y()-other.y());
494  double zdiff(z()-other.z());
495  return Vector2(xdiff,ydiff,zdiff);
496 #else
497  double xdiff(x()-other.x());
498  double ydiff(y()-other.y());
499  return Vector2(xdiff,ydiff);
500 #endif
501 
502 
503 }
504 
507 Point2 operator+(const Vector2& vec) const
508 {
509 #if GEOM_PSEUDO3D==GEOM_TRUE
510  return Point2(x()+vec.x(),y()+vec.y(),z()+vec.z());
511 #else
512  return Point2(x()+vec.x(),y()+vec.y());
513 #endif
514 }
515 
518 Point2 operator-(const Vector2& vec) const
519 {
520 #if GEOM_PSEUDO3D==GEOM_TRUE
521  return Point2(x()-vec.x(),y()-vec.y(),z()-vec.z());
522 #else
523  return Point2(x()-vec.x(),y()-vec.y());
524 #endif
525 }
526 
527 
528  friend std::ostream &operator<<(std::ostream &stream, const Point2& pnt);
529  friend std::istream &operator>>(std::istream &stream, Point2& pnt);
530 
531 
532 protected:
533 friend class Dt2;
534  double coordX;
535  double coordY;
536 #if GEOM_PSEUDO3D==GEOM_TRUE
537  double coordZ;
538 #endif
539  Triangle2* pAssociatedTriangle;
540  int customIndex;
541 };
542 
543 
544 inline std::ostream &operator<<(std::ostream &stream, const Point2& pnt)
545 {
546 #if GEOM_PSEUDO3D==GEOM_TRUE
547  stream << "Point2 ("<<&pnt<<","<<pnt.customIndex<<"): "<<pnt.x()<<", "<<pnt.y()<<", "<<pnt.z();
548  //#ifndef NDEBUG
549  //stream<<", anyT="<<pnt.getIncidentTriangle();
550  //#endif
551 #else
552  stream << "Point2 ("<<&pnt<<","<<pnt.customIndex<<"): "<<pnt.x()<<", "<<pnt.y();
553 #endif
554 
555 
556  return stream;
557 }
558 
559 inline std::istream &operator>>(std::istream &stream, Point2& pnt)
560 {
561 #if GEOM_PSEUDO3D==GEOM_TRUE
562  stream >> pnt.coordX >> pnt.coordY >> pnt.coordZ;
563 #else
564  stream >> pnt.coordX >> pnt.coordY;
565 #endif
566  return stream;
567 }
568 
569 // Free functions
570 
575 inline
576 double sqDistance2D(const Point2& p0,const Point2& p1)
577 {
578  double deltaX=p1.x()-p0.x();
579  double deltaY=p1.y()-p0.y();
580  return (deltaX*deltaX+deltaY*deltaY);
581 }
582 
583 
588 inline
589 double sqDistance2D(const double x0,const double y0,const Point2& p1)
590 {
591  double deltaX=p1.x()-x0;
592  double deltaY=p1.y()-y0;
593  return (deltaX*deltaX+deltaY*deltaY);
594 }
595 
596 #if GEOM_PSEUDO3D==GEOM_TRUE
597 
602 inline
603 double sqDistance25D(const Point2& p0,const Point2& p1)
604 {
605  double deltaX=p1.x()-p0.x();
606  double deltaY=p1.y()-p0.y();
607  double deltaZ=p1.z()-p0.z();
608  double result(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
609 
610  if(result!=result)
611  {
612  std::cerr<<"warning, sqDistance25D, nan value, no distance"<<std::endl;
613  std::cerr<<"p0="<<p0<<std::endl;
614  std::cerr<<"p1="<<p1<<std::endl;
615  }
616 
617  return result;
618 }
619 
620 
625 inline
626 double sqDistance25D(const double x0,const double y0,const double z0,const Point2& p1)
627 {
628  double deltaX=p1.x()-x0;
629  double deltaY=p1.y()-y0;
630  double deltaZ=p1.z()-z0;
631  double result(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ);
632 
633  if(result!=result)
634  {
635  std::cerr<<"warning, sqDistance25D, nan value, no distance"<<std::endl;
636  std::cerr<<"x0="<<x0<<", y0="<<y0<<", z0="<<z0<<std::endl;
637  std::cerr<<"p1="<<p1<<std::endl;
638  }
639 
640  return result;
641 
642 }
643 
644 
645 #endif
646 
647 
648 
655 inline
656 Point2 center(const Point2& p0,const Point2& p1)
657 {
658 #if GEOM_PSEUDO3D==GEOM_TRUE
659  Point2 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0,(p0.z()+p1.z())/2.0);
660 
661 #else
662  Point2 center((p0.x()+p1.x())/2.0,(p0.y()+p1.y())/2.0);
663 #endif
664  return center;
665 }
666 
678 CLASS_DECLSPEC
679 Point2 centerWithShift(const Point2& p0,const Point2& p1);
680 
681 #if GEOM_PSEUDO3D==GEOM_TRUE
682 struct CLASS_DECLSPEC Func_ltPointXYZ
684 {
685  bool operator()(const Point2& p0,const Point2& p1) const
686  {
687  if(p0.x()<p1.x()) return true;
688  if(p0.x()>p1.x()) return false;
689  if(p0.y()<p1.y()) return true;
690  if(p0.y()>p1.y()) return false;
691  if(p0.z()<p1.z()) return true;
692  return false;
693  }
694 };
695 
696 #endif
697 
698 } // (namespace)
GEOM_FADE2D::Triangle2
Triangle.
Definition: Triangle2.h:48
GEOM_FADE2D::Point2::setIncidentTriangle
void setIncidentTriangle(Triangle2 *pT)
Associate a triangle with the point.
Definition: Point2.h:482
GEOM_FADE2D::Point2::operator!=
bool operator!=(const Point2 &p) const
Inequality operator.
Definition: Point2.h:337
GEOM_FADE2D::Vector2
Vector.
Definition: Vector2.h:34
GEOM_FADE2D::Point2::operator-
Point2 operator-(const Vector2 &vec) const
Subtract vector from point.
Definition: Point2.h:518
GEOM_FADE2D::Point2
Point.
Definition: Point2.h:40
GEOM_FADE2D::Point2::x
double x() const
Get the x-coordinate.
Definition: Point2.h:193
GEOM_FADE2D::Point2::getMaxAbs
double getMaxAbs() const
Get max(abs(x),abs(y))
Definition: Point2.h:269
GEOM_FADE2D::Point2::Point2
Point2(const Point2 &p_)
Copy constructor.
Definition: Point2.h:154
GEOM_FADE2D::Point2::set
void set(const Point2 &pnt)
Set the coordiantes.
Definition: Point2.h:430
GEOM_FADE2D::Vector2::y
double y() const
Get the y-value.
GEOM_FADE2D::Point2::y
double y() const
Get the y-coordinate.
Definition: Point2.h:202
GEOM_FADE2D::Point2::operator-
Vector2 operator-(const Point2 &other) const
Returns a vector from other to *this.
Definition: Point2.h:489
GEOM_FADE2D::Point2::setCustomIndex
void setCustomIndex(int customIndex_)
Set a custom index.
Definition: Point2.h:456
GEOM_FADE2D::Point2::Point2
Point2(const double x_, const double y_)
Constructor.
Definition: Point2.h:131
GEOM_FADE2D::Point2::operator+
Point2 operator+(const Vector2 &vec) const
Add vector and point.
Definition: Point2.h:507
GEOM_FADE2D::Point2::operator<
bool operator<(const Point2 &p) const
Less than operator.
Definition: Point2.h:288
GEOM_FADE2D::Vector2::x
double x() const
Get the x-value.
GEOM_FADE2D::Point2::operator>
bool operator>(const Point2 &p) const
Greater than operator.
Definition: Point2.h:302
GEOM_FADE2D::Point2::Point2
Point2()
Default constructor.
Definition: Point2.h:143
GEOM_FADE2D::Point2::set
void set(const double x_, const double y_, int customIndex_)
Set the coordinates and customIndex.
Definition: Point2.h:399
GEOM_FADE2D::Point2::operator==
bool operator==(const Point2 &p) const
Equality operator.
Definition: Point2.h:316
GEOM_FADE2D::Point2::xy
void xy(double &x_, double &y_) const
Get the x- and y-coordinate.
Definition: Point2.h:243
GEOM_FADE2D::Point2::getIncidentTriangle
Triangle2 * getIncidentTriangle() const
Get the associated triangle.
Definition: Point2.h:346
GEOM_FADE2D::Point2::getCustomIndex
int getCustomIndex() const
Get the custom index.
Definition: Point2.h:473