Delaunator
2D Delaunay Triangulation in C++ with Python wrapper.
 All Classes Namespaces Functions
edge_iterators.h
1 #ifndef DELAUNATOR_EDGE_ITERATORS_H_INCLUDED
2 #define DELAUNATOR_EDGE_ITERATORS_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 #include "edge.h"
14 #include "iterators.h"
15 
16 
17 /*
18  * DEFINES
19  */
20 
21 
22 
23 
24 /*
25  * PREDECLARATIONS
26  */
27 // NB: iterators defined next() function for portability to Python's wraps,
28 // or other language where ++ unary operator don't exist.
29 // So, next() and operator++ are equivalent.
30 
31 
32 
33 
34 /******************************************************************
35  * ITERATORS ON ALL EDGES
36  ******************************************************************/
38  public:
39  // CONSTRUCTOR
40  IteratorOnEdges(std::vector<Edge*>* v) : edges(v) {
41  this->it = this->edges->begin();
42  // ignore the edges that are not necessary for linked user Vertex
43  while((*this->it)->isExternal()) this->it++;
44  }
45  // PUBLIC METHODS
46  IteratorOnEdges& next() { return (*this)++; }
47  // OPERATORS
48  bool operator!=(const IteratorOnEdges& othr) const {
49  return this->it != othr.it;
50  }
51  bool operator!=(const std::vector<Edge*>::iterator& ot) const {
52  return this->it != ot;
53  }
54  IteratorOnEdges& operator++(int i) { // post increment
55  this->it++;
56  return *this;
57  }
58  Edge* operator*() { //pointer dereferences
59  return *(this->it);
60  }
61  // ACCESSORS
62  std::vector<Edge*>::iterator begin() const { return this->edges->begin(); }
63  std::vector<Edge*>::iterator end() const { return this->edges->end(); }
64  std::vector<Edge*>* getEdges() const { return this->edges; }
65  protected:
66  // ATTRIBUTES
67  std::vector<Edge*>* edges;
68  std::vector<Edge*>::iterator it;
69  // PRIVATE METHODS
70 };
72  public:
73  // CONSTRUCTOR
74  IteratorOnEdges_read(const std::vector<Edge*>* const v) : edges(v) {
75  this->it = this->edges->begin();
76  // ignore the edges that are not necessary for linked user Vertex
77  while((*this->it)->isExternal()) this->it++;
78  }
79  // PUBLIC METHODS
80  IteratorOnEdges_read& next() { return (*this)++; }
81  // OPERATORS
82  bool operator!=(const IteratorOnEdges_read& othr) const {
83  return this->it != othr.it;
84  }
85  bool operator!=(const std::vector<Edge*>::const_iterator& ot) const {
86  return this->it != ot;
87  }
88  IteratorOnEdges_read& operator++(int i) { // post increment
89  this->it++;
90  return *this;
91  }
92  Edge* operator*() const { //pointer dereferences
93  return *(this->it);
94  }
95  // ACCESSORS
96  std::vector<Edge*>::const_iterator begin() const { return this->edges->begin(); }
97  std::vector<Edge*>::const_iterator end() const { return this->edges->end(); }
98  const std::vector<Edge*>* getEdges() const { return this->edges; }
99  protected:
100  // ATTRIBUTES
101  const std::vector<Edge*>* const edges;
102  std::vector<Edge*>::const_iterator it;
103  // PRIVATE METHODS
104 };
105 
106 
107 
108 
109 
110 /******************************************************************
111  * ITERATORS ON ALL EDGES
112  ******************************************************************/
114  public:
115  // CONSTRUCTOR
116  IteratorOnAllEdges(std::vector<Edge*>* v) : edges(v) {
117  this->it = this->edges->begin();
118  }
119  // PUBLIC METHODS
120  IteratorOnAllEdges& next() { return (*this)++; }
121  // OPERATORS
122  bool operator!=(const IteratorOnAllEdges& othr) const {
123  return this->it != othr.it;
124  }
125  bool operator!=(const std::vector<Edge*>::iterator& ot) const {
126  return this->it != ot;
127  }
128  IteratorOnAllEdges& operator++(int i) { // post increment
129  this->it++;
130  return *this;
131  }
132  Edge* operator*() { //pointer dereferences
133  return *(this->it);
134  }
135  // ACCESSORS
136  std::vector<Edge*>::iterator begin() const { return this->edges->begin(); }
137  std::vector<Edge*>::iterator end() const { return this->edges->end(); }
138  std::vector<Edge*>* getEdges() const { return this->edges; }
139  protected:
140  // ATTRIBUTES
141  std::vector<Edge*>* edges;
142  std::vector<Edge*>::iterator it;
143  // PRIVATE METHODS
144 };
146  public:
147  // CONSTRUCTOR
148  IteratorOnAllEdges_read(const std::vector<Edge*>* const v) : edges(v) {
149  this->it = this->edges->begin();
150  }
151  // PUBLIC METHODS
152  IteratorOnAllEdges_read& next() { return (*this)++; }
153  // OPERATORS
154  bool operator!=(const IteratorOnAllEdges_read& othr) const {
155  return this->it != othr.it;
156  }
157  bool operator!=(const std::vector<Edge*>::const_iterator& ot) const {
158  return this->it != ot;
159  }
160  IteratorOnAllEdges_read& operator++(int i) { // post increment
161  this->it++;
162  return *this;
163  }
164  Edge* operator*() const { //pointer dereferences
165  return *(this->it);
166  }
167  // ACCESSORS
168  std::vector<Edge*>::const_iterator begin() const { return this->edges->begin(); }
169  std::vector<Edge*>::const_iterator end() const { return this->edges->end(); }
170  const std::vector<Edge*>* getEdges() const { return this->edges; }
171  protected:
172  // ATTRIBUTES
173  const std::vector<Edge*>* const edges;
174  std::vector<Edge*>::const_iterator it;
175  // PRIVATE METHODS
176 };
177 
178 
179 #endif