QhullLinkedList_test.cpp
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/qhulltest/QhullLinkedList_test.cpp#3 $$Change: 2062 $
5 ** $DateTime: 2016/01/17 13:13:18 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 //pre-compiled headers
10 #include <QtCore/QList>
11 #include "qhulltest/RoadTest.h"
12 
14 #include "libqhullcpp/Qhull.h"
16 #include "libqhullcpp/RboxPoints.h"
17 
18 namespace orgQhull {
19 
21 {
22  Q_OBJECT
23 
24 #
25 private slots:
26  void cleanup();
27  void t_construct();
28  void t_convert();
29  void t_element();
30  void t_search();
31  void t_iterator();
32  void t_const_iterator();
34  void t_io();
35 };//QhullLinkedList_test
36 
37 void
39 {
40  new QhullLinkedList_test(); // RoadTest::s_testcases
41 }
42 
43 //Executed after each testcase
46 {
48 }
49 
52 {
53  // QhullLinkedList vs; //private (compiler error). No memory allocation
54  RboxPoints rcube("c");
55  {
56  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
57  QCOMPARE(q.facetCount(), 12);
59  QCOMPARE(vs.count(), 8);
60  QCOMPARE(vs.size(), 8u);
61  QVERIFY(!vs.isEmpty());
62  QhullVertexList vs2 = q.vertexList();
63  QCOMPARE(vs2.count(), 8);
64  QCOMPARE(vs2.size(),8u);
65  QVERIFY(!vs2.isEmpty());
66  QVERIFY(vs==vs2);
67  // vs= vs2; // disabled. Would not copy the vertices
68  QhullVertexList vs3= vs2; // copy constructor
69  QVERIFY(vs3==vs2);
70  }
71 }//t_construct
72 
75 {
76  RboxPoints rcube("c");
77  {
78  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
79  QCOMPARE(q.facetCount(), 12);
80  QhullVertexList vs = q.vertexList();
81  QCOMPARE(vs.size(), 8u);
82  QVERIFY(!vs.isEmpty());
83  std::vector<QhullVertex> vs2= vs.toStdVector();
84  QCOMPARE(vs2.size(), vs.size());
85  QhullVertexList::Iterator i= vs.begin();
86  for(int k= 0; k<(int)vs2.size(); k++){
87  QCOMPARE(vs2[k], *i++);
88  }
89  QList<QhullVertex> vs3= vs.toQList();
90  QCOMPARE(vs3.count(), vs.count());
91  i= vs.begin();
92  for(int k= 0; k<vs3.count(); k++){
93  QCOMPARE(vs3[k], *i++);
94  }
95  QhullVertexList vs4(q.endVertex(), q.endVertex());
96  QVERIFY(vs4.isEmpty());
97  QVERIFY(vs==vs);
98  QVERIFY(vs4==vs4);
99  QVERIFY(vs!=vs4);
100  }
101 }//t_convert
102 
103 //ReadOnly tested by t_convert
104 
107 {
108  RboxPoints rcube("c");
109  Qhull q(rcube,"QR0"); // rotated unit cube
110  QhullVertexList vs = q.vertexList();
111  QhullVertex v= vs.first();
112  QCOMPARE(v.previous(), QhullVertex(NULL));
113  QCOMPARE(vs.front(), vs.first());
114  QhullVertex v2= vs.last();
115  QCOMPARE(v2.next().next(), QhullVertex(NULL)); // sentinel has NULL next
116  QCOMPARE(vs.back(), v2);
117  QCOMPARE(vs.back(), vs.last());
118 }//t_element
119 
122 {
123  RboxPoints rcube("c");
124  Qhull q(rcube,"QR0"); // rotated unit cube
125  QhullVertexList vs = q.vertexList();
126  QhullVertex v(q);
127  QVERIFY(!vs.contains(v));
128  QCOMPARE(vs.count(v), 0);
129  QhullVertex v2= *vs.begin();
130  QhullVertex v3= vs.last();
131  QVERIFY(vs.contains(v2));
132  QCOMPARE(vs.count(v2), 1);
133  QVERIFY(vs.contains(v3));
134  QCOMPARE(vs.count(v3), 1);
135 }//t_search
136 
139 {
140  RboxPoints rcube("c");
141  {
142  Qhull q(rcube,"QR0"); // rotated unit cube
143  QhullVertexList vs = q.vertexList();
146  QVERIFY(i==i2);
147  // No comparisons
148  i= vs.begin();
149  QVERIFY(i==i2);
150  i2= vs.end();
151  QVERIFY(i!=i2);
152  QhullVertex v3(*i);
153  i2--;
154  QhullVertex v8= *i2;
155  QhullVertex v= vs.first();
156  QhullVertex v2= v.next();
157  QCOMPARE(v3.id(), v.id());
158  QCOMPARE(v8.id(), vs.last().id());
160  QCOMPARE(*i2, *i3);
161 
162  (i3= i)++;
163  QCOMPARE((*i3).id(), v2.id());
164  QVERIFY(i==i);
165  QVERIFY(i!=i2);
166 
168  QVERIFY(i==i4); // iterator COMP const_iterator
169  QVERIFY(i4==i); // const_iterator COMP iterator
170  QVERIFY(i2!=i4);
171  QVERIFY(i4!=i2);
172  ++i4;
173 
174  i= vs.begin();
175  i2= vs.begin();
176  QCOMPARE(i, i2++);
177  QCOMPARE(*i2, v2);
178  QCOMPARE(++i, i2);
179  QCOMPARE(i, i2--);
180  QCOMPARE(i2, vs.begin());
181  QCOMPARE(--i, i2);
182  QCOMPARE(i2 += 8, vs.end());
183  QCOMPARE(i2 -= 8, vs.begin());
184  QCOMPARE(i2+0, vs.begin());
185  QCOMPARE(i2+8, vs.end());
186  i2 += 8;
187  i= i2-0;
188  QCOMPARE(i, i2);
189  i= i2-8;
190  QCOMPARE(i, vs.begin());
191 
192  //vs.begin end tested above
193 
194  // QhullVertexList is const-only
195  }
196 }//t_iterator
197 
200 {
201  RboxPoints rcube("c");
202  {
203  Qhull q(rcube,"QR0"); // rotated unit cube
204  QhullVertexList vs = q.vertexList();
207  QVERIFY(i==i2);
208  i= vs.begin();
209  QVERIFY(i==i2);
210  i2= vs.end();
211  QVERIFY(i!=i2);
212  QhullVertex v3(*i);
213  i2--;
214  QhullVertex v8= *i2;
215  QhullVertex v= vs.first();
216  QhullVertex v2= v.next();
217  QCOMPARE(v3.id(), v.id());
218  QCOMPARE(v8.id(), vs.last().id());
220  QCOMPARE(*i2, *i3);
221 
222  (i3= i)++;
223  QCOMPARE((*i3).id(), v2.id());
224  QVERIFY(i==i);
225  QVERIFY(i!=i2);
226 
227  // See t_iterator for const_iterator COMP iterator
228 
229  i= vs.begin();
230  i2= vs.constBegin();
231  QCOMPARE(i, i2++);
232  QCOMPARE(*i2, v2);
233  QCOMPARE(++i, i2);
234  QCOMPARE(i, i2--);
235  QCOMPARE(i2, vs.constBegin());
236  QCOMPARE(--i, i2);
237  QCOMPARE(i2 += 8, vs.constEnd());
238  QCOMPARE(i2 -= 8, vs.constBegin());
239  QCOMPARE(i2+0, vs.constBegin());
240  QCOMPARE(i2+8, vs.constEnd());
241  i2 += 8;
242  i= i2-0;
243  QCOMPARE(i, i2);
244  i= i2-8;
245  QCOMPARE(i, vs.constBegin());
246 
247  // QhullVertexList is const-only
248  }
249 }//t_const_iterator
250 
253 {
254  RboxPoints rcube("c");
255  Qhull q(rcube,"QR0"); // rotated unit cube
256  QhullVertexList vs(q.endVertex(), q.endVertex());
258  QCOMPARE(vs.count(), 0);
259  QVERIFY(!i.hasNext());
260  QVERIFY(!i.hasPrevious());
261  i.toBack();
262  QVERIFY(!i.hasNext());
263  QVERIFY(!i.hasPrevious());
264 
265  QhullVertexList vs2 = q.vertexList();
266  QhullVertexListIterator i2(vs2);
267  QCOMPARE(vs2.count(), 8);
268  i= vs2;
269  QVERIFY(i2.hasNext());
270  QVERIFY(!i2.hasPrevious());
271  QVERIFY(i.hasNext());
272  QVERIFY(!i.hasPrevious());
273  i2.toBack();
274  i.toFront();
275  QVERIFY(!i2.hasNext());
276  QVERIFY(i2.hasPrevious());
277  QVERIFY(i.hasNext());
278  QVERIFY(!i.hasPrevious());
279 
280  // i at front, i2 at end/back, 4 neighbors
281  QhullVertexList vs3 = q.vertexList(); // same as vs2
282  QhullVertex v3(vs3.first());
283  QhullVertex v4= vs3.first();
284  QCOMPARE(v3, v4);
285  QVERIFY(v3==v4);
286  QhullVertex v5(v4.next());
287  QVERIFY(v4!=v5);
288  QhullVertex v6(v5.next());
289  QhullVertex v7(v6.next());
290  QhullVertex v8(vs3.last());
291  QCOMPARE(i2.peekPrevious(), v8);
292  i2.previous();
293  i2.previous();
294  i2.previous();
295  i2.previous();
296  QCOMPARE(i2.previous(), v7);
297  QCOMPARE(i2.previous(), v6);
298  QCOMPARE(i2.previous(), v5);
299  QCOMPARE(i2.previous(), v4);
300  QVERIFY(!i2.hasPrevious());
301  QCOMPARE(i.peekNext(), v4);
302  // i.peekNext()= 1.0; // compiler error
303  QCOMPARE(i.next(), v4);
304  QCOMPARE(i.peekNext(), v5);
305  QCOMPARE(i.next(), v5);
306  QCOMPARE(i.next(), v6);
307  QCOMPARE(i.next(), v7);
308  i.next();
309  i.next();
310  i.next();
311  QCOMPARE(i.next(), v8);
312  QVERIFY(!i.hasNext());
313  i.toFront();
314  QCOMPARE(i.next(), v4);
315 }//t_QhullLinkedList_iterator
316 
319 {
320  RboxPoints rcube("c");
321  Qhull q(rcube,"QR0"); // rotated unit cube
322  QhullVertexList vs(q.endVertex(), q.endVertex());
323  std::cout << "INFO: empty QhullVertextList" << vs << std::endl;
324  QhullVertexList vs2= q.vertexList();
325  std::cout << "INFO: " << vs2 << std::endl;
326 }//t_io
327 
328 }//namespace orgQhull
329 
330 #include "moc/QhullLinkedList_test.moc"
QhullRidge – Qhull&#39;s ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
q
QhullVertexList vertexList() const
Return vertices of the convex hull.
Definition: Qhull.cpp:204
std::vector< T > toStdVector() const
list v
Definition: obb.py:45
QhullVertex beginVertex() const
Definition: Qhull.h:103
Interface to Qhull from C++.
Definition: Qhull.h:43
const_iterator constBegin() const
QhullVertex next() const
Definition: QhullVertex.h:79
bool contains(const T &t) const
QhullVertex endVertex() const
Definition: Qhull.h:106
QhullVertex previous() const
Definition: QhullVertex.h:83
void add_QhullLinkedList_test()
void cleanup()
Executed after each test.
Definition: RoadTest.cpp:38
QhullLinkedList< QhullVertex > QhullVertexList
Definition: QhullVertex.h:28
countT facetCount() const
Definition: Qhull.h:72
countT id() const
Definition: QhullVertex.h:75
const_iterator constEnd() const
const T back() const
For back() and last(), return T instead of T& (T is computed)


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