Coordinates.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (c) 2009-2015 C.B. Barber. All rights reserved.
4 ** $Id: //main/2015/qhull/src/libqhullcpp/Coordinates.h#5 $$Change: 2066 $
5 ** $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 #ifndef QHCOORDINATES_H
10 #define QHCOORDINATES_H
11 
12 extern "C" {
13  #include "libqhull_r/qhull_ra.h"
14 }
15 #include "libqhullcpp/QhullError.h"
17 
18 #include <cstddef> // ptrdiff_t, size_t
19 #include <ostream>
20 // Requires STL vector class. Can use with another vector class such as QList.
21 #include <vector>
22 
23 namespace orgQhull {
24 
25 #
26  class Coordinates;
30  class MutableCoordinatesIterator;
31 
32 class Coordinates {
33 
34 private:
35 #
36  std::vector<coordT> coordinate_array;
37 
38 public:
39 #
40 
41  class const_iterator;
42  class iterator;
43  typedef iterator Iterator;
45 
46  typedef coordT value_type;
47  typedef const value_type *const_pointer;
48  typedef const value_type & const_reference;
49  typedef value_type * pointer;
50  typedef value_type & reference;
51  typedef ptrdiff_t difference_type;
52  typedef countT size_type;
53 
54 #
55  Coordinates() {};
56  explicit Coordinates(const std::vector<coordT> &other) : coordinate_array(other) {}
58  Coordinates & operator=(const Coordinates &other) { coordinate_array= other.coordinate_array; return *this; }
59  Coordinates & operator=(const std::vector<coordT> &other) { coordinate_array= other; return *this; }
61 
62 #
63 
64 #ifndef QHULL_NO_STL
65  std::vector<coordT> toStdVector() const { return coordinate_array; }
66 #endif //QHULL_NO_STL
67 #ifdef QHULL_USES_QT
68  QList<coordT> toQList() const;
69 #endif //QHULL_USES_QT
70 
71 #
72  countT count() const { return static_cast<countT>(size()); }
73  coordT * data() { return isEmpty() ? 0 : &at(0); }
74  const coordT * data() const { return const_cast<const pointT*>(isEmpty() ? 0 : &at(0)); }
75  bool isEmpty() const { return coordinate_array.empty(); }
76  bool operator==(const Coordinates &other) const { return coordinate_array==other.coordinate_array; }
77  bool operator!=(const Coordinates &other) const { return coordinate_array!=other.coordinate_array; }
78  size_t size() const { return coordinate_array.size(); }
79 
80 #
81  coordT & at(countT idx) { return coordinate_array.at(idx); }
82  const coordT & at(countT idx) const { return coordinate_array.at(idx); }
83  coordT & back() { return coordinate_array.back(); }
84  const coordT & back() const { return coordinate_array.back(); }
85  coordT & first() { return front(); }
86  const coordT & first() const { return front(); }
87  coordT & front() { return coordinate_array.front(); }
88  const coordT & front() const { return coordinate_array.front(); }
89  coordT & last() { return back(); }
90  const coordT & last() const { return back(); }
91  Coordinates mid(countT idx, countT length= -1) const;
92  coordT & operator[](countT idx) { return coordinate_array.operator[](idx); }
93  const coordT & operator[](countT idx) const { return coordinate_array.operator[](idx); }
94  coordT value(countT idx, const coordT &defaultValue) const;
95 
96 #
97  iterator begin() { return iterator(coordinate_array.begin()); }
98  const_iterator begin() const { return const_iterator(coordinate_array.begin()); }
99  const_iterator constBegin() const { return begin(); }
100  const_iterator constEnd() const { return end(); }
101  iterator end() { return iterator(coordinate_array.end()); }
103 
104 #
105  Coordinates operator+(const Coordinates &other) const;
106 
107 #
108  void append(int pointDimension, coordT *c);
109  void append(const coordT &c) { push_back(c); }
110  void clear() { coordinate_array.clear(); }
111  iterator erase(iterator idx) { return iterator(coordinate_array.erase(idx.base())); }
112  iterator erase(iterator beginIterator, iterator endIterator) { return iterator(coordinate_array.erase(beginIterator.base(), endIterator.base())); }
113  void insert(countT before, const coordT &c) { insert(begin()+before, c); }
114  iterator insert(iterator before, const coordT &c) { return iterator(coordinate_array.insert(before.base(), c)); }
115  void move(countT from, countT to) { insert(to, takeAt(from)); }
116  Coordinates & operator+=(const Coordinates &other);
117  Coordinates & operator+=(const coordT &c) { append(c); return *this; }
118  Coordinates & operator<<(const Coordinates &other) { return *this += other; }
119  Coordinates & operator<<(const coordT &c) { return *this += c; }
120  void pop_back() { coordinate_array.pop_back(); }
121  void pop_front() { removeFirst(); }
122  void prepend(const coordT &c) { insert(begin(), c); }
123  void push_back(const coordT &c) { coordinate_array.push_back(c); }
124  void push_front(const coordT &c) { insert(begin(), c); }
125  //removeAll below
126  void removeAt(countT idx) { erase(begin()+idx); }
127  void removeFirst() { erase(begin()); }
128  void removeLast() { erase(--end()); }
129  void replace(countT idx, const coordT &c) { (*this)[idx]= c; }
130  void reserve(countT i) { coordinate_array.reserve(i); }
131  void swap(countT idx, countT other);
132  coordT takeAt(countT idx);
133  coordT takeFirst() { return takeAt(0); }
134  coordT takeLast();
135 
136 #
137  bool contains(const coordT &t) const;
138  countT count(const coordT &t) const;
139  countT indexOf(const coordT &t, countT from = 0) const;
140  countT lastIndexOf(const coordT &t, countT from = -1) const;
141  void removeAll(const coordT &t);
142 
143 #
144  // before const_iterator for conversion with comparison operators
145  // Reviewed corelib/tools/qlist.h and corelib/tools/qvector.h w/o QT_STRICT_ITERATORS
146  class iterator {
147 
148  private:
149  std::vector<coordT>::iterator i;
150  friend class const_iterator;
151 
152  public:
153  typedef std::random_access_iterator_tag iterator_category;
155  typedef value_type *pointer;
156  typedef value_type &reference;
157  typedef ptrdiff_t difference_type;
158 
159  iterator() {}
160  iterator(const iterator &other) { i= other.i; }
161  explicit iterator(const std::vector<coordT>::iterator &vi) { i= vi; }
162  iterator & operator=(const iterator &other) { i= other.i; return *this; }
163  std::vector<coordT>::iterator &base() { return i; }
164  coordT & operator*() const { return *i; }
165  // No operator->() when the base type is double
166  coordT & operator[](countT idx) const { return i[idx]; }
167 
168  bool operator==(const iterator &other) const { return i==other.i; }
169  bool operator!=(const iterator &other) const { return i!=other.i; }
170  bool operator<(const iterator &other) const { return i<other.i; }
171  bool operator<=(const iterator &other) const { return i<=other.i; }
172  bool operator>(const iterator &other) const { return i>other.i; }
173  bool operator>=(const iterator &other) const { return i>=other.i; }
174  // reinterpret_cast to break circular dependency
175  bool operator==(const Coordinates::const_iterator &other) const { return *this==reinterpret_cast<const iterator &>(other); }
176  bool operator!=(const Coordinates::const_iterator &other) const { return *this!=reinterpret_cast<const iterator &>(other); }
177  bool operator<(const Coordinates::const_iterator &other) const { return *this<reinterpret_cast<const iterator &>(other); }
178  bool operator<=(const Coordinates::const_iterator &other) const { return *this<=reinterpret_cast<const iterator &>(other); }
179  bool operator>(const Coordinates::const_iterator &other) const { return *this>reinterpret_cast<const iterator &>(other); }
180  bool operator>=(const Coordinates::const_iterator &other) const { return *this>=reinterpret_cast<const iterator &>(other); }
181 
182  iterator & operator++() { ++i; return *this; }
183  iterator operator++(int) { return iterator(i++); }
184  iterator & operator--() { --i; return *this; }
185  iterator operator--(int) { return iterator(i--); }
186  iterator & operator+=(countT idx) { i += idx; return *this; }
187  iterator & operator-=(countT idx) { i -= idx; return *this; }
188  iterator operator+(countT idx) const { return iterator(i+idx); }
189  iterator operator-(countT idx) const { return iterator(i-idx); }
190  difference_type operator-(iterator other) const { return i-other.i; }
191  };//Coordinates::iterator
192 
193 #
194  class const_iterator {
195 
196  private:
197  std::vector<coordT>::const_iterator i;
198 
199  public:
200  typedef std::random_access_iterator_tag iterator_category;
202  typedef const value_type *pointer;
203  typedef const value_type &reference;
204  typedef ptrdiff_t difference_type;
205 
207  const_iterator(const const_iterator &other) { i= other.i; }
208  const_iterator(const iterator &o) : i(o.i) {}
209  explicit const_iterator(const std::vector<coordT>::const_iterator &vi) { i= vi; }
210  const_iterator &operator=(const const_iterator &other) { i= other.i; return *this; }
211  const coordT & operator*() const { return *i; }
212  // No operator->() when the base type is double
213  const coordT & operator[](countT idx) const { return i[idx]; }
214 
215  bool operator==(const const_iterator &other) const { return i==other.i; }
216  bool operator!=(const const_iterator &other) const { return i!=other.i; }
217  bool operator<(const const_iterator &other) const { return i<other.i; }
218  bool operator<=(const const_iterator &other) const { return i<=other.i; }
219  bool operator>(const const_iterator &other) const { return i>other.i; }
220  bool operator>=(const const_iterator &other) const { return i>=other.i; }
221 
222  const_iterator & operator++() { ++i; return *this; }
224  const_iterator & operator--() { --i; return *this; }
226  const_iterator & operator+=(countT idx) { i += idx; return *this; }
227  const_iterator & operator-=(countT idx) { i -= idx; return *this; }
228  const_iterator operator+(countT idx) const { return const_iterator(i+idx); }
229  const_iterator operator-(countT idx) const { return const_iterator(i-idx); }
230  difference_type operator-(const_iterator other) const { return i-other.i; }
231  };//Coordinates::const_iterator
232 
233 };//Coordinates
234 
235 //class CoordinatesIterator
236 //QHULL_DECLARE_SEQUENTIAL_ITERATOR(Coordinates, coordT)
237 
239 {
241 
242 private:
243  const Coordinates * c;
244  const_iterator i;
245 
246 public:
247  CoordinatesIterator(const Coordinates &container): c(&container), i(c->constBegin()) {}
248  CoordinatesIterator &operator=(const Coordinates &container) { c= &container; i= c->constBegin(); return *this; }
250 
251  bool findNext(const coordT &t) { while (i != c->constEnd()) if(*i++ == t){ return true;} return false; }
252  bool findPrevious(const coordT &t) { while (i != c->constBegin())if (*(--i) == t){ return true;} return false; }
253  bool hasNext() const { return i != c->constEnd(); }
254  bool hasPrevious() const { return i != c->constBegin(); }
255  const coordT & next() { return *i++; }
256  const coordT & previous() { return *--i; }
257  const coordT & peekNext() const { return *i; }
258  const coordT & peekPrevious() const { const_iterator p= i; return *--p; }
259  void toFront() { i= c->constBegin(); }
260  void toBack() { i= c->constEnd(); }
261 };//CoordinatesIterator
262 
263 //class MutableCoordinatesIterator
264 //QHULL_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(Coordinates, coordT)
266 {
269 
270 private:
272  iterator i;
273  iterator n;
274  bool item_exists() const { return const_iterator(n) != c->constEnd(); }
275 
276 public:
277  MutableCoordinatesIterator(Coordinates &container) : c(&container) { i= c->begin(); n= c->end(); }
278  MutableCoordinatesIterator &operator=(Coordinates &container) { c= &container; i= c->begin(); n= c->end(); return *this; }
280 
281  bool findNext(const coordT &t) { while(c->constEnd()!=const_iterator(n= i)){ if(*i++==t){ return true;}} return false; }
282  bool findPrevious(const coordT &t) { while(c->constBegin()!=const_iterator(i)){ if(*(n= --i)== t){ return true;}} n= c->end(); return false; }
283  bool hasNext() const { return (c->constEnd()!=const_iterator(i)); }
284  bool hasPrevious() const { return (c->constBegin()!=const_iterator(i)); }
285  void insert(const coordT &t) { n= i= c->insert(i, t); ++i; }
286  coordT & next() { n= i++; return *n; }
287  coordT & peekNext() const { return *i; }
288  coordT & peekPrevious() const { iterator p= i; return *--p; }
289  coordT & previous() { n= --i; return *n; }
290  void remove() { if(c->constEnd()!=const_iterator(n)){ i= c->erase(n); n= c->end();} }
291  void setValue(const coordT &t) const { if(c->constEnd()!=const_iterator(n)){ *n= t;} }
292  void toFront() { i= c->begin(); n= c->end(); }
293  void toBack() { i= c->end(); n= i; }
294  coordT & value() { QHULL_ASSERT(item_exists()); return *n; }
295  const coordT & value() const { QHULL_ASSERT(item_exists()); return *n; }
296 };//MutableCoordinatesIterator
297 
298 
299 }//namespace orgQhull
300 
301 #
302 
303 std::ostream &operator<<(std::ostream &os, const orgQhull::Coordinates &c);
304 
305 #endif // QHCOORDINATES_H
bool operator>=(const Coordinates::const_iterator &other) const
Definition: Coordinates.h:180
Coordinates & operator=(const Coordinates &other)
Definition: Coordinates.h:58
iterator erase(iterator idx)
Definition: Coordinates.h:111
bool operator>(const Coordinates::const_iterator &other) const
Definition: Coordinates.h:179
void append(const coordT &c)
Definition: Coordinates.h:109
const value_type * const_pointer
Definition: Coordinates.h:47
bool operator<=(const iterator &other) const
Definition: Coordinates.h:171
iterator(const iterator &other)
Definition: Coordinates.h:160
QhullRidge – Qhull&#39;s ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
bool operator<=(const const_iterator &other) const
Definition: Coordinates.h:218
bool isEmpty() const
Definition: Coordinates.h:75
void push_front(const coordT &c)
Definition: Coordinates.h:124
bool operator==(const iterator &other) const
Definition: Coordinates.h:168
std::vector< coordT >::const_iterator i
Definition: Coordinates.h:197
MutableCoordinatesIterator(Coordinates &container)
Definition: Coordinates.h:277
t
#define pointT
Definition: libqhull.h:96
const_iterator & operator+=(countT idx)
Definition: Coordinates.h:226
bool findNext(const coordT &t)
Definition: Coordinates.h:281
bool operator==(const Coordinates &other) const
Definition: Coordinates.h:76
Coordinates & operator+=(const coordT &c)
Definition: Coordinates.h:117
void replace(countT idx, const coordT &c)
Definition: Coordinates.h:129
Coordinates & operator<<(const coordT &c)
Definition: Coordinates.h:119
coordT & at(countT idx)
Definition: Coordinates.h:81
bool operator!=(const Coordinates::const_iterator &other) const
Definition: Coordinates.h:176
value_type & reference
Definition: Coordinates.h:50
const coordT & last() const
Definition: Coordinates.h:90
void setValue(const coordT &t) const
Definition: Coordinates.h:291
const Coordinates * c
Definition: Coordinates.h:243
const coordT & peekNext() const
Definition: Coordinates.h:257
coordT & operator[](countT idx) const
Definition: Coordinates.h:166
const_iterator operator+(countT idx) const
Definition: Coordinates.h:228
difference_type operator-(iterator other) const
Definition: Coordinates.h:190
std::random_access_iterator_tag iterator_category
Definition: Coordinates.h:200
std::vector< coordT >::iterator & base()
Definition: Coordinates.h:163
iterator operator-(countT idx) const
Definition: Coordinates.h:189
countT count() const
Definition: Coordinates.h:72
countT lastIndexOf(const coordT &t, countT from=-1) const
c
const_iterator constBegin() const
Definition: Coordinates.h:99
const coordT & front() const
Definition: Coordinates.h:88
bool operator<(const Coordinates::const_iterator &other) const
Definition: Coordinates.h:177
const coordT & operator[](countT idx) const
Definition: Coordinates.h:213
bool operator<=(const Coordinates::const_iterator &other) const
Definition: Coordinates.h:178
const_iterator & operator=(const const_iterator &other)
Definition: Coordinates.h:210
#define coordT
Definition: libqhull.h:80
bool operator<(const iterator &other) const
Definition: Coordinates.h:170
bool operator!=(const Coordinates &other) const
Definition: Coordinates.h:77
iterator erase(iterator beginIterator, iterator endIterator)
Definition: Coordinates.h:112
const coordT & first() const
Definition: Coordinates.h:86
#define QHULL_ASSERT
Definition: QhullError.h:16
bool operator<(const const_iterator &other) const
Definition: Coordinates.h:217
Coordinates::const_iterator const_iterator
Definition: Coordinates.h:240
bool findNext(const coordT &t)
Definition: Coordinates.h:251
difference_type operator-(const_iterator other) const
Definition: Coordinates.h:230
void removeAt(countT idx)
Definition: Coordinates.h:126
Coordinates::const_iterator const_iterator
Definition: Coordinates.h:268
const coordT & value() const
Definition: Coordinates.h:295
void insert(countT before, const coordT &c)
Definition: Coordinates.h:113
const coordT & operator*() const
Definition: Coordinates.h:211
const_iterator begin() const
Definition: Coordinates.h:98
iterator insert(iterator before, const coordT &c)
Definition: Coordinates.h:114
Coordinates & operator+=(const Coordinates &other)
Definition: Coordinates.cpp:61
bool operator!=(const iterator &other) const
Definition: Coordinates.h:169
iterator & operator=(const iterator &other)
Definition: Coordinates.h:162
coordT value(countT idx, const coordT &defaultValue) const
Definition: Coordinates.cpp:45
bool operator==(const Coordinates::const_iterator &other) const
Definition: Coordinates.h:175
const coordT & operator[](countT idx) const
Definition: Coordinates.h:93
void swap(countT idx, countT other)
iterator & operator+=(countT idx)
Definition: Coordinates.h:186
size_t size() const
Definition: Coordinates.h:78
iterator & operator-=(countT idx)
Definition: Coordinates.h:187
Coordinates & operator<<(const Coordinates &other)
Definition: Coordinates.h:118
bool operator>(const iterator &other) const
Definition: Coordinates.h:172
const_iterator(const const_iterator &other)
Definition: Coordinates.h:207
iterator(const std::vector< coordT >::iterator &vi)
Definition: Coordinates.h:161
const coordT * data() const
Definition: Coordinates.h:74
bool findPrevious(const coordT &t)
Definition: Coordinates.h:282
const coordT & back() const
Definition: Coordinates.h:84
void prepend(const coordT &c)
Definition: Coordinates.h:122
bool operator==(const const_iterator &other) const
Definition: Coordinates.h:215
void removeAll(const coordT &t)
const_iterator constEnd() const
Definition: Coordinates.h:100
MutableCoordinatesIterator & operator=(Coordinates &container)
Definition: Coordinates.h:278
bool operator!=(const const_iterator &other) const
Definition: Coordinates.h:216
const_iterator ConstIterator
Definition: Coordinates.h:44
void push_back(const coordT &c)
Definition: Coordinates.h:123
bool findPrevious(const coordT &t)
Definition: Coordinates.h:252
ptrdiff_t difference_type
Definition: Coordinates.h:51
const_iterator operator-(countT idx) const
Definition: Coordinates.h:229
bool operator>(const const_iterator &other) const
Definition: Coordinates.h:219
countT indexOf(const coordT &t, countT from=0) const
void reserve(countT i)
Definition: Coordinates.h:130
Coordinates::iterator iterator
Definition: Coordinates.h:267
iterator operator+(countT idx) const
Definition: Coordinates.h:188
const coordT & at(countT idx) const
Definition: Coordinates.h:82
coordT takeAt(countT idx)
Definition: Coordinates.cpp:86
std::vector< coordT > coordinate_array
Definition: Coordinates.h:36
CoordinatesIterator & operator=(const Coordinates &container)
Definition: Coordinates.h:248
void move(countT from, countT to)
Definition: Coordinates.h:115
const_iterator(const std::vector< coordT >::const_iterator &vi)
Definition: Coordinates.h:209
value_type * pointer
Definition: Coordinates.h:49
bool operator>=(const iterator &other) const
Definition: Coordinates.h:173
const_iterator end() const
Definition: Coordinates.h:102
std::vector< coordT > toStdVector() const
Definition: Coordinates.h:65
int countT
Definition: user_r.h:182
Coordinates & operator=(const std::vector< coordT > &other)
Definition: Coordinates.h:59
Coordinates(const std::vector< coordT > &other)
Definition: Coordinates.h:56
const coordT & peekPrevious() const
Definition: Coordinates.h:258
void append(int pointDimension, coordT *c)
Definition: Coordinates.cpp:75
const_iterator & operator-=(countT idx)
Definition: Coordinates.h:227
std::random_access_iterator_tag iterator_category
Definition: Coordinates.h:153
coordT & operator[](countT idx)
Definition: Coordinates.h:92
bool operator>=(const const_iterator &other) const
Definition: Coordinates.h:220
const value_type & const_reference
Definition: Coordinates.h:48
std::vector< coordT >::iterator i
Definition: Coordinates.h:149
Coordinates mid(countT idx, countT length=-1) const
Definition: Coordinates.cpp:31
Coordinates(const Coordinates &other)
Definition: Coordinates.h:57
CoordinatesIterator(const Coordinates &container)
Definition: Coordinates.h:247


hpp-fcl
Author(s):
autogenerated on Fri Jun 2 2023 02:39:00