Delaunator
2D Delaunay Triangulation in C++ with Python wrapper.
 All Classes Namespaces Functions
edge.h
1 #ifndef EDGE_H_INCLUDED
2 #define EDGE_H_INCLUDED
3 
4 
5 
6 /*
7  * LIBRARIES
8  */
9 // LOCAL MODULES
10 #include "commons.h"
11 #include "vertex.h"
12 #include "face.h"
13 
14 
15 
16 /*
17  * DEFINES
18  */
19 
20 
21 
22 
23 /*
24  * PREDECLARATIONS
25  */
26 class Vertex;
27 class Face;
28 
29 
30 
31 
35 class Edge {
36  public:
37  // CONSTRUCTOR
38  Edge(Vertex* = NULL, Edge* = NULL, Edge* = NULL, Face* = NULL, bool = true);
39  ~Edge();
40  // PUBLIC METHODS
45  float distanceTo(Coordinates c) const { return sqrt(this->squareDistanceTo(c.x(), c.y())); }
51  float distanceTo(float x, float y) const { return sqrt(this->squareDistanceTo(x, y)); }
56  float squareDistanceTo(Coordinates c) const { return this->squareDistanceTo(c.x(), c.y()); }
62  float squareDistanceTo(float x, float y) const;
64  bool coordOnTheRight(Coordinates) const;
66  bool coordOnTheLeft(Coordinates) const;
67  // ACCESSORS
68  // getter
69  Vertex* originVertex() const { return this->origin_vertex; }
70  Vertex* destinVertex() const { return this->opposite_edge->origin_vertex; }
71 
72  Edge* oppositeEdge() const { return this->opposite_edge; }
73  Edge* nextLeftEdge() const { return this->next_left_edge; }
74  Edge* prevLeftEdge() const { return this->next_left_edge->next_left_edge; }
75  Edge* nextRightEdge() const { return this->
76  opposite_edge->next_left_edge->next_left_edge->opposite_edge;}
77  Edge* prevRightEdge() const { return this->opposite_edge->next_left_edge->opposite_edge; }
78  Edge* rotLeftEdge() const { return this->next_left_edge->next_left_edge->opposite_edge; }
79  Edge* rotRightEdge() const { return this->opposite_edge->next_left_edge; }
80  Face* leftFace() const { return this->left_face; }
81  Face* rightFace() const { return this->opposite_edge->left_face; }
82 
83  bool isVisible() const { return this->visible; }
84  bool isConstraigned() const { return this->constraigned; }
85  bool isExternal() const;
86  unsigned int getID() const { return this->id; }
87  float length() const;
88  float squareLength() const;
89 
90  Coordinates middle() const;
91  // setters
92  void setOriginVertex(Vertex* v) { this->origin_vertex = v; v->setEdge(this); }
93  void setOppositeEdge(Edge* e) { this->opposite_edge = e; }
94  void setNextLeftEdge(Edge* e) { this->next_left_edge = e; }
95  void setLeftFace(Face* f, short ttl = 4) { // time to live permit an update on all sides of face.
96  this->left_face = f;
97  if(ttl > 0)
98  this->nextLeftEdge()->setLeftFace(f, ttl-1);
99  }
100  void setVisibility(bool v) { this->visible = v; }
101  void setConstraigned(bool c) { this->constraigned = c; }
102 #ifdef FOLLOW_SEARCH
103  bool passing;
104 #endif
105  private:
106  // ATTRIBUTES
107  bool visible; // in a graphical representation
108  bool constraigned = false; // must always rely same Vertex
109  Vertex* origin_vertex;
110  Edge* opposite_edge;
111  Edge* next_left_edge;
112  Face* left_face;
113  unsigned int id;
114  static unsigned int last_id;
115  // PRIVATE METHODS
116 };
117 
118 
119 // EXTERNAL METHODS
120 #if !SWIG
121  std::ostream& operator<<(std::ostream&, Edge const &);
122 #endif
123 
124 #endif