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; }
60  ~Coordinates() {}
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()); }
102  const_iterator end() const { return const_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)); }
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);
133  coordT takeFirst() { return takeAt(0); }
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;
154  typedef coordT value_type;
155  typedef value_type *pointer;
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;
201  typedef coordT value_type;
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; }
223  const_iterator operator++(int) { return const_iterator(i++); }
224  const_iterator & operator--() { --i; return *this; }
225  const_iterator operator--(int) { return const_iterator(i--); }
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;
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 {
267  typedef Coordinates::iterator iterator;
269 
270 private:
272  iterator i;
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
orgQhull::Coordinates::iterator::operator!=
bool operator!=(const iterator &other) const
Definition: Coordinates.h:175
coordT
#define coordT
Definition: libqhull.h:80
orgQhull::Coordinates::difference_type
ptrdiff_t difference_type
Definition: Coordinates.h:57
orgQhull::Coordinates::iterator::operator>
bool operator>(const iterator &other) const
Definition: Coordinates.h:178
orgQhull::Coordinates::iterator::value_type
coordT value_type
Definition: Coordinates.h:160
orgQhull::Coordinates::reference
value_type & reference
Definition: Coordinates.h:56
countT
int countT
Definition: user_r.h:182
orgQhull::Coordinates::data
coordT * data()
Definition: Coordinates.h:79
orgQhull::Coordinates::const_reference
const typedef value_type & const_reference
Definition: Coordinates.h:54
orgQhull::Coordinates::count
countT count() const
Definition: Coordinates.h:78
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
orgQhull::Coordinates::operator+
Coordinates operator+(const Coordinates &other) const
Definition: Coordinates.cpp:59
orgQhull::Coordinates::mid
Coordinates mid(countT idx, countT length=-1) const
Definition: Coordinates.cpp:37
orgQhull::Coordinates::iterator::operator*
coordT & operator*() const
Definition: Coordinates.h:170
orgQhull::Coordinates::iterator::operator==
bool operator==(const iterator &other) const
Definition: Coordinates.h:174
orgQhull::Coordinates::back
coordT & back()
Definition: Coordinates.h:89
orgQhull::Coordinates::iterator::pointer
value_type * pointer
Definition: Coordinates.h:161
orgQhull::Coordinates::pop_front
void pop_front()
Definition: Coordinates.h:127
orgQhull::Coordinates::takeLast
coordT takeLast()
Definition: Coordinates.cpp:100
orgQhull::Coordinates::replace
void replace(countT idx, const coordT &c)
Definition: Coordinates.h:135
QhullIterator.h
orgQhull::Coordinates::back
const coordT & back() const
Definition: Coordinates.h:90
orgQhull::Coordinates::const_iterator::value_type
coordT value_type
Definition: Coordinates.h:207
orgQhull::Coordinates::const_pointer
const typedef value_type * const_pointer
Definition: Coordinates.h:53
orgQhull::Coordinates::operator!=
bool operator!=(const Coordinates &other) const
Definition: Coordinates.h:83
orgQhull::Coordinates::constEnd
const_iterator constEnd() const
Definition: Coordinates.h:106
orgQhull::Coordinates::end
iterator end()
Definition: Coordinates.h:107
orgQhull::MutableCoordinatesIterator::const_iterator
Coordinates::const_iterator const_iterator
Definition: Coordinates.h:274
orgQhull::Coordinates::first
coordT & first()
Definition: Coordinates.h:91
orgQhull::Coordinates::iterator::operator[]
coordT & operator[](countT idx) const
Definition: Coordinates.h:172
orgQhull::Coordinates::pop_back
void pop_back()
Definition: Coordinates.h:126
orgQhull::Coordinates::prepend
void prepend(const coordT &c)
Definition: Coordinates.h:128
orgQhull::Coordinates::iterator::operator++
iterator & operator++()
Definition: Coordinates.h:188
orgQhull::Coordinates::const_iterator::i
std::vector< coordT >::const_iterator i
Definition: Coordinates.h:203
orgQhull::Coordinates::at
coordT & at(countT idx)
Definition: Coordinates.h:87
orgQhull::Coordinates::toStdVector
std::vector< coordT > toStdVector() const
Definition: Coordinates.h:71
orgQhull::Coordinates::takeAt
coordT takeAt(countT idx)
Definition: Coordinates.cpp:92
orgQhull::Coordinates::size
size_t size() const
Definition: Coordinates.h:84
orgQhull::Coordinates::iterator
Definition: Coordinates.h:152
orgQhull::Coordinates::pointer
value_type * pointer
Definition: Coordinates.h:55
orgQhull::Coordinates::removeFirst
void removeFirst()
Definition: Coordinates.h:133
orgQhull::Coordinates::append
void append(int pointDimension, coordT *c)
Definition: Coordinates.cpp:81
orgQhull::Coordinates::value
coordT value(countT idx, const coordT &defaultValue) const
Definition: Coordinates.cpp:51
orgQhull::Coordinates::push_back
void push_back(const coordT &c)
Definition: Coordinates.h:129
orgQhull::MutableCoordinatesIterator
Definition: Coordinates.h:271
orgQhull::Coordinates::last
coordT & last()
Definition: Coordinates.h:95
orgQhull::Coordinates::const_iterator::difference_type
ptrdiff_t difference_type
Definition: Coordinates.h:210
orgQhull::Coordinates::erase
iterator erase(iterator idx)
Definition: Coordinates.h:117
orgQhull::Coordinates::front
coordT & front()
Definition: Coordinates.h:93
orgQhull::Coordinates::isEmpty
bool isEmpty() const
Definition: Coordinates.h:81
orgQhull::Coordinates::iterator::operator--
iterator & operator--()
Definition: Coordinates.h:190
orgQhull::Coordinates::reserve
void reserve(countT i)
Definition: Coordinates.h:136
orgQhull::Coordinates::iterator::reference
value_type & reference
Definition: Coordinates.h:162
c
c
operator<<
std::ostream & operator<<(std::ostream &os, const orgQhull::Coordinates &c)
orgQhull::Coordinates::ConstIterator
const_iterator ConstIterator
Definition: Coordinates.h:50
orgQhull::Coordinates::iterator::operator+=
iterator & operator+=(countT idx)
Definition: Coordinates.h:192
orgQhull::Coordinates::clear
void clear()
Definition: Coordinates.h:116
value
float value
orgQhull::Coordinates::iterator::base
std::vector< coordT >::iterator & base()
Definition: Coordinates.h:169
orgQhull::Coordinates::iterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: Coordinates.h:159
orgQhull::Coordinates::iterator::i
std::vector< coordT >::iterator i
Definition: Coordinates.h:155
t
tuple t
orgQhull::Coordinates::iterator::operator-
iterator operator-(countT idx) const
Definition: Coordinates.h:195
qhull_ra.h
orgQhull::Coordinates::operator==
bool operator==(const Coordinates &other) const
Definition: Coordinates.h:82
orgQhull::Coordinates::iterator::operator<
bool operator<(const iterator &other) const
Definition: Coordinates.h:176
orgQhull::Coordinates::removeAt
void removeAt(countT idx)
Definition: Coordinates.h:132
orgQhull::Coordinates::iterator::operator-=
iterator & operator-=(countT idx)
Definition: Coordinates.h:193
orgQhull::Coordinates::operator<<
Coordinates & operator<<(const Coordinates &other)
Definition: Coordinates.h:124
orgQhull::Coordinates::iterator::operator<=
bool operator<=(const iterator &other) const
Definition: Coordinates.h:177
orgQhull::CoordinatesIterator
Definition: Coordinates.h:244
orgQhull::Coordinates::push_front
void push_front(const coordT &c)
Definition: Coordinates.h:130
orgQhull::Coordinates::swap
void swap(countT idx, countT other)
Definition: Coordinates.cpp:108
orgQhull::Coordinates::iterator::operator=
iterator & operator=(const iterator &other)
Definition: Coordinates.h:168
orgQhull::Coordinates::value_type
coordT value_type
Definition: Coordinates.h:52
orgQhull::Coordinates::const_iterator
Definition: Coordinates.h:200
pointT
#define pointT
Definition: libqhull.h:96
orgQhull::Coordinates::iterator::iterator
iterator()
Definition: Coordinates.h:165
orgQhull::Coordinates::~Coordinates
~Coordinates()
Definition: Coordinates.h:66
orgQhull::Coordinates
Definition: Coordinates.h:38
orgQhull::Coordinates::insert
void insert(countT before, const coordT &c)
Definition: Coordinates.h:119
orgQhull::Coordinates::iterator::difference_type
ptrdiff_t difference_type
Definition: Coordinates.h:163
orgQhull::Coordinates::coordinate_array
std::vector< coordT > coordinate_array
Definition: Coordinates.h:42
orgQhull::Coordinates::move
void move(countT from, countT to)
Definition: Coordinates.h:121
QHULL_ASSERT
#define QHULL_ASSERT
Definition: QhullError.h:16
orgQhull::Coordinates::begin
iterator begin()
Definition: Coordinates.h:103
orgQhull::Coordinates::constBegin
const_iterator constBegin() const
Definition: Coordinates.h:105
orgQhull::Coordinates::size_type
countT size_type
Definition: Coordinates.h:58
orgQhull::Coordinates::indexOf
countT indexOf(const coordT &t, countT from=0) const
Definition: Coordinates.cpp:136
orgQhull::Coordinates::removeLast
void removeLast()
Definition: Coordinates.h:134
orgQhull::Coordinates::iterator::operator>=
bool operator>=(const iterator &other) const
Definition: Coordinates.h:179
orgQhull::Coordinates::operator=
Coordinates & operator=(const Coordinates &other)
Definition: Coordinates.h:64
orgQhull::Coordinates::lastIndexOf
countT lastIndexOf(const coordT &t, countT from=-1) const
Definition: Coordinates.cpp:157
orgQhull::Coordinates::Iterator
iterator Iterator
Definition: Coordinates.h:48
orgQhull::Coordinates::const_iterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: Coordinates.h:206
orgQhull::Coordinates::operator[]
coordT & operator[](countT idx)
Definition: Coordinates.h:98
orgQhull::Coordinates::iterator::operator+
iterator operator+(countT idx) const
Definition: Coordinates.h:194
orgQhull::Coordinates::removeAll
void removeAll(const coordT &t)
Definition: Coordinates.cpp:176
orgQhull::Coordinates::takeFirst
coordT takeFirst()
Definition: Coordinates.h:139
QhullError.h
orgQhull::Coordinates::Coordinates
Coordinates()
Definition: Coordinates.h:61
orgQhull::Coordinates::operator+=
Coordinates & operator+=(const Coordinates &other)
Definition: Coordinates.cpp:67


hpp-fcl
Author(s):
autogenerated on Fri Aug 2 2024 02:45:13