QhullPointSet_test.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (p) 2009-2015 C.B. Barber. All rights reserved.
4 ** $Id: //main/2015/qhull/src/qhulltest/QhullPointSet_test.cpp#3 $$Change: 2062 $
5 ** $DateTime: 2016/01/17 13:13:18 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 //pre-compiled header
10 #include <iostream>
11 #include "RoadTest.h" // QT_VERSION
12 
14 #include "libqhullcpp/RboxPoints.h"
15 #include "libqhullcpp/QhullPoint.h"
16 #include "libqhullcpp/QhullFacet.h"
18 #include "libqhullcpp/Qhull.h"
19 
20 using std::cout;
21 using std::endl;
22 using std::ostringstream;
23 
24 namespace orgQhull {
25 
27 {
28  Q_OBJECT
29 
30 #
31 private slots:
32  void cleanup();
33  void t_construct();
34  void t_convert();
35  void t_element();
36  void t_iterator();
37  void t_const_iterator();
38  void t_search();
39  void t_pointset_iterator();
40  void t_io();
41 };//QhullPointSet_test
42 
43 void
45 {
46  new QhullPointSet_test(); // RoadTest::s_testcases
47 }
48 
49 //Executed after each testcase
52 {
54 }
55 
58 {
59  // Default constructor is disallowed (i.e., private)
60  RboxPoints rcube("c W0 1000");
61  Qhull q(rcube,"Qc"); // cube with 1000 coplanar points
62  int coplanarCount= 0;
63  foreach(QhullFacet f, q.facetList()){
65  QVERIFY(ps.isEmpty());
66  QCOMPARE(ps.count(), 0);
67  QCOMPARE(ps.size(), 0u);
68  QhullPointSet ps2(q.qh(), f.getFacetT()->coplanarset);
69  QVERIFY(!ps2.isEmpty());
70  coplanarCount += ps2.count();
71  QCOMPARE(ps2.count(), (int)ps2.size());
72  QhullPointSet ps3(ps2);
73  QVERIFY(!ps3.isEmpty());
74  QCOMPARE(ps3.count(), ps2.count());
75  QVERIFY(ps3==ps2);
76  QVERIFY(ps3!=ps);
77  QhullPointSet ps4= ps3;
78  QVERIFY(ps4==ps2);
79  }
80  QCOMPARE(coplanarCount, 1000);
81 }//t_construct
82 
85 {
86  RboxPoints rcube("c W0 1000");
87  Qhull q(rcube,"Qc"); // cube with 1000 coplanar points
88  QhullFacet f= q.firstFacet();
90  QVERIFY(ps.count()>=1); // Sometimes no coplanar points
91  std::vector<QhullPoint> vs= ps.toStdVector();
92  QCOMPARE(vs.size(), ps.size());
93  QhullPoint p= ps[0];
94  QhullPoint p2= vs[0];
95  QCOMPARE(p, p2);
96  QList<QhullPoint> qs= ps.toQList();
97  QCOMPARE(qs.size(), static_cast<int>(ps.size()));
98  QhullPoint p3= qs[0];
99  QCOMPARE(p3, p);
100 }//t_convert
101 
102 // readonly tested in t_construct
103 // empty, isEmpty, ==, !=, size
104 
107 {
108  RboxPoints rcube("c W0 1000");
109  Qhull q(rcube,"Qc"); // cube with 1000 coplanar points
110  QhullFacet f= q.firstFacet();
112  QVERIFY(ps.count()>=3); // Sometimes no coplanar points
113  QhullPoint p= ps[0];
114  QCOMPARE(p, ps[0]);
115  QhullPoint p2= ps[ps.count()-1];
116  QCOMPARE(ps.at(1), ps[1]);
117  QCOMPARE(ps.second(), ps[1]);
118  QCOMPARE(ps.first(), p);
119  QCOMPARE(ps.front(), ps.first());
120  QCOMPARE(ps.last(), p2);
121  QCOMPARE(ps.back(), ps.last());
122  QhullPoint p8(q);
123  QCOMPARE(ps.value(2), ps[2]);
124  QCOMPARE(ps.value(-1), p8);
125  QCOMPARE(ps.value(ps.count()), p8);
126  QCOMPARE(ps.value(ps.count(), p), p);
127  QVERIFY(ps.value(1, p)!=p);
128  QhullPointSet ps8= f.coplanarPoints();
130  foreach(QhullPoint p9, ps){ // Qt only
131  QCOMPARE(p9.dimension(), 3);
132  QCOMPARE(p9, *i++);
133  }
134 }//t_element
135 
138 {
139  RboxPoints rcube("c W0 1000");
140  Qhull q(rcube,"Qc"); // cube with 1000 coplanar points
141  QhullFacet f= q.firstFacet();
143  QVERIFY(ps.count()>=3); // Sometimes no coplanar points
145  QhullPointSet::iterator i2= ps.begin();
146  QVERIFY(i==i2);
147  QVERIFY(i>=i2);
148  QVERIFY(i<=i2);
149  i= ps.begin();
150  QVERIFY(i==i2);
151  i2= ps.end();
152  QVERIFY(i!=i2);
153  QhullPoint p= *i;
154  QCOMPARE(p.dimension(), q.dimension());
155  QCOMPARE(p, ps[0]);
156  i2--;
157  QhullPoint p2= *i2;
158  QCOMPARE(p2.dimension(), q.dimension());
159  QCOMPARE(p2, ps.last());
161  QCOMPARE(*i2, *i5);
162  QhullPointSet::Iterator i3= i+1;
163  QVERIFY(i!=i3);
164  QCOMPARE(i[1], *i3);
165  (i3= i)++;
166  QCOMPARE((*i3)[0], ps[1][0]);
167  QCOMPARE((*i3).dimension(), 3);
168 
169  QVERIFY(i==i);
170  QVERIFY(i!=i3);
171  QVERIFY(i<i3);
172  QVERIFY(i<=i3);
173  QVERIFY(i3>i);
174  QVERIFY(i3>=i);
175 
177  QVERIFY(i==i4); // iterator COMP const_iterator
178  QVERIFY(i<=i4);
179  QVERIFY(i>=i4);
180  QVERIFY(i4==i); // const_iterator COMP iterator
181  QVERIFY(i4<=i);
182  QVERIFY(i4>=i);
183  QVERIFY(i>=i4);
184  QVERIFY(i4<=i);
185  QVERIFY(i2!=i4);
186  QVERIFY(i2>i4);
187  QVERIFY(i2>=i4);
188  QVERIFY(i4!=i2);
189  QVERIFY(i4<i2);
190  QVERIFY(i4<=i2);
191  ++i4;
192  QVERIFY(i!=i4); // iterator COMP const_iterator
193  QVERIFY(i<i4);
194  QVERIFY(i<=i4);
195  QVERIFY(i4>i);
196  QVERIFY(i4>=i);
197  i4= ps.constBegin();
198  QVERIFY(i==i4); // iterator COMP const_iterator
199  QCOMPARE(i4+ps.count(), ps.constEnd());
200 
201  i= ps.begin();
202  i2= ps.begin();
203  QCOMPARE(i, i2++);
204  QCOMPARE(*i2, ps[1]);
205  QCOMPARE(++i, i2);
206  QCOMPARE(i, i2--);
207  QCOMPARE(i2, ps.begin());
208  QCOMPARE(--i, i2);
209  QCOMPARE(i2+=ps.count(), ps.end());
210  QCOMPARE(i2-=ps.count(), ps.begin());
211  QCOMPARE(i2+0, ps.begin());
212  QCOMPARE(i2+ps.count(), ps.end());
213  i2 += ps.count();
214  i= i2-0;
215  QCOMPARE(i, i2);
216  i= i2-ps.count();
217  QCOMPARE(i, ps.begin());
218  QCOMPARE(i2-i, ps.count());
219 
220  //ps.begin end tested above
221 
222  // QhullPointSet is const-only
223 }//t_iterator
224 
227 {
228  RboxPoints rcube("c W0 1000");
229  Qhull q(rcube,"Qc"); // cube with 1000 coplanar points
230  QhullFacet f= q.firstFacet();
232  QVERIFY(ps.count()>=3); // Sometimes no coplanar points
234  QhullPointSet::const_iterator i2= ps.begin();
235  QVERIFY(i==i2);
236  QVERIFY(i>=i2);
237  QVERIFY(i<=i2);
238 
239  // See t_iterator for const_iterator COMP iterator
240 
241  i= ps.begin();
242  QVERIFY(i==i2);
243  i2= ps.end();
244  QVERIFY(i!=i2);
245  QhullPoint p= *i; // QhullPoint is the base class for QhullPointSet::iterator
246  QCOMPARE(p.dimension(), q.dimension());
247  QCOMPARE(p, ps[0]);
248  i2--;
249  QhullPoint p2= *i2;
250  QCOMPARE(p2.dimension(), q.dimension());
251  QCOMPARE(p2, ps.last());
253  QCOMPARE(*i2, *i5);
254 
255 
257  QVERIFY(i!=i3);
258  QCOMPARE(i[1], *i3);
259 
260  QVERIFY(i==i);
261  QVERIFY(i!=i3);
262  QVERIFY(i<i3);
263  QVERIFY(i<=i3);
264  QVERIFY(i3>i);
265  QVERIFY(i3>=i);
266 
267  // QhullPointSet is const-only
268 }//t_const_iterator
269 
270 
273 {
274  RboxPoints rcube("c W0 1000");
275  Qhull q(rcube,"Qc"); // cube with 1000 coplanar points
276  QhullFacet f= q.firstFacet();
278  QVERIFY(ps.count()>=3); // Sometimes no coplanar points
279  QhullPoint p= ps.first();
280  QhullPoint p2= ps.last();
281  QVERIFY(ps.contains(p));
282  QVERIFY(ps.contains(p2));
283  QVERIFY(p!=p2);
284  QhullPoint p3= ps[2];
285  QVERIFY(ps.contains(p3));
286  QVERIFY(p!=p3);
287  QCOMPARE(ps.indexOf(p), 0);
288  QCOMPARE(ps.indexOf(p2), ps.count()-1);
289  QCOMPARE(ps.indexOf(p3), 2);
290  QhullPoint p4(q);
291  QCOMPARE(ps.indexOf(p4), -1);
292  QCOMPARE(ps.lastIndexOf(p), 0);
293  QCOMPARE(ps.lastIndexOf(p2), ps.count()-1);
294  QCOMPARE(ps.lastIndexOf(p3), 2);
295  QCOMPARE(ps.lastIndexOf(p4), -1);
296 }//t_search
297 
300 {
301  RboxPoints rcube("c W0 1000");
302  Qhull q(rcube,"Qc"); // cube with 1000 coplanar points
303  QhullFacet f= q.firstFacet();
304  QhullPointSet ps2= f.outsidePoints();
305  QVERIFY(ps2.count()==0); // No outside points after constructing the convex hull
306  QhullPointSetIterator i2= ps2;
307  QCOMPARE(i2.countRemaining(), 0);
308  QVERIFY(!i2.hasNext());
309  QVERIFY(!i2.hasPrevious());
310  i2.toBack();
311  QVERIFY(!i2.hasNext());
312  QVERIFY(!i2.hasPrevious());
313 
315  QVERIFY(ps.count()>=3); // Sometimes no coplanar points
316  QhullPointSetIterator i(ps);
317  i2= ps;
318  QCOMPARE(i2.countRemaining(), ps.count());
319  QVERIFY(i2.hasNext());
320  QVERIFY(!i2.hasPrevious());
321  QVERIFY(i.hasNext());
322  QVERIFY(!i.hasPrevious());
323  i2.toBack();
324  QCOMPARE(i2.countRemaining(), 0);
325  i.toFront();
326  QCOMPARE(i.countRemaining(), ps.count());
327  QCOMPARE(i2.countRemaining(), 0);
328  QVERIFY(!i2.hasNext());
329  QVERIFY(i2.hasPrevious());
330  QVERIFY(i.hasNext());
331  QVERIFY(!i.hasPrevious());
332 
333  QhullPoint p= ps[0];
334  QhullPoint p2(ps[0]);
335  QCOMPARE(p, p2);
336  QVERIFY(p==p2);
337  QhullPoint p3(ps.last());
338  // p2[0]= 0.0;
339  QVERIFY(p==p2);
340  QCOMPARE(i2.peekPrevious(), p3);
341  QCOMPARE(i2.previous(), p3);
342  QCOMPARE(i2.previous(), ps[ps.count()-2]);
343  QVERIFY(i2.hasPrevious());
344  QCOMPARE(i.peekNext(), p);
345  // i.peekNext()= 1.0; // compiler error
346  QCOMPARE(i.next(), p);
347  QCOMPARE(i.countRemaining(), ps.count()-1);
348  QhullPoint p4= i.peekNext();
349  QVERIFY(p4!=p3);
350  QCOMPARE(i.next(), p4);
351  QVERIFY(i.hasNext());
352  i.toFront();
353  QCOMPARE(i.next(), p);
354 }//t_pointset_iterator
355 
358 {
359  ostringstream os;
360  RboxPoints rcube("c W0 120");
361  Qhull q(rcube,"Qc"); // cube with 100 coplanar points
362  QhullFacet f= q.firstFacet();
364  QVERIFY(ps.count()>=3); // Sometimes no coplanar points
365  os << "QhullPointSet from coplanarPoints\n" << ps << endl;
366  os << ps.print("\nWith message\n");
367  os << ps.printIdentifiers("\nCoplanar points: ");
368  os << "\nAs a point set:\n";
369  os << ps;
370  cout << os.str();
371  QString s= QString::fromStdString(os.str());
372  QCOMPARE(s.count(" 0.5\n"), 3*ps.count());
373  QCOMPARE(s.count("p"), ps.count()+4);
374 }//t_io
375 
376 }//orgQhull
377 
378 #include "moc/QhullPointSet_test.moc"
QhullFacet.h
orgQhull::QhullSet< QhullPoint >::Iterator
QhullSet< QhullPoint >::iterator Iterator
Definition: QhullSet.h:116
orgQhull::QhullPointSet_test::t_search
void t_search()
Definition: QhullPointSet_test.cpp:272
orgQhull::QhullSet::first
const T first() const
Definition: QhullSet.h:163
orgQhull::QhullPointSet::print
PrintPointSet print(const char *message) const
Definition: QhullPointSet.h:72
orgQhull::QhullSet::value
T value(countT idx) const
Definition: QhullSet.h:365
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
orgQhull::QhullPointSet_test::t_io
void t_io()
Definition: QhullPointSet_test.cpp:357
orgQhull::QhullPointSet_test::t_const_iterator
void t_const_iterator()
Definition: QhullPointSet_test.cpp:226
QhullPointSet.h
orgQhull::QhullSet::indexOf
countT indexOf(const T &t) const
Definition: QhullSet.h:193
orgQhull::QhullFacet::outsidePoints
QhullPointSet outsidePoints() const
Definition: QhullFacet.cpp:186
orgQhull::QhullPoint
Definition: QhullPoint.h:39
orgQhull::QhullSetIterator::countRemaining
countT countRemaining()
Definition: QhullSet.h:308
orgQhull::QhullSet::toStdVector
std::vector< T > toStdVector() const
Definition: QhullSet.h:334
orgQhull::QhullPointSet_test::t_convert
void t_convert()
Definition: QhullPointSet_test.cpp:84
facetT::outsideset
setT * outsideset
Definition: libqhull.h:302
orgQhull::QhullPointSet
Definition: QhullPointSet.h:37
Qhull.h
orgQhull::QhullSet::lastIndexOf
countT lastIndexOf(const T &t) const
Definition: QhullSet.h:412
orgQhull::QhullPointSet_test::t_pointset_iterator
void t_pointset_iterator()
Definition: QhullPointSet_test.cpp:299
orgQhull::QhullSet< QhullPoint >::ConstIterator
QhullSet< QhullPoint >::const_iterator ConstIterator
Definition: QhullSet.h:118
orgQhull::QhullSetIterator
Faster then interator/const_iterator due to T::base_type.
Definition: QhullSet.h:289
QhullFacetList.h
orgQhull::QhullSet::second
const T second() const
Definition: QhullSet.h:175
orgQhull::QhullPointSet_test::t_element
void t_element()
Definition: QhullPointSet_test.cpp:106
orgQhull::QhullSetIterator::previous
T previous()
Definition: QhullSet.h:320
orgQhull::QhullSet::back
const T back() const
Definition: QhullSet.h:154
orgQhull::QhullPointSet_test::t_iterator
void t_iterator()
Definition: QhullPointSet_test.cpp:137
orgQhull::Qhull
Interface to Qhull from C++.
Definition: Qhull.h:49
orgQhull::QhullPointSet::printIdentifiers
PrintIdentifiers printIdentifiers(const char *message) const
Definition: QhullPointSet.h:65
orgQhull::QhullSetIterator::toBack
void toBack()
Definition: QhullSet.h:321
orgQhull::QhullSet::contains
bool contains(const T &t) const
Definition: QhullSet.h:385
orgQhull::QhullSetBase::size
size_t size() const
Definition: QhullSet.h:79
orgQhull::QhullSet::constEnd
const_iterator constEnd() const
Definition: QhullSet.h:186
orgQhull::QhullSetIterator::toFront
void toFront()
Definition: QhullSet.h:322
orgQhull::QhullSet::isEmpty
bool isEmpty() const
Definition: QhullSet.h:76
orgQhull::QhullSet::count
countT count(const T &t) const
Definition: QhullSet.h:395
orgQhull::QhullPointSet_test::t_construct
void t_construct()
Definition: QhullPointSet_test.cpp:57
orgQhull::QhullPointSet_test::cleanup
void cleanup()
Definition: QhullPointSet_test.cpp:51
orgQhull::QhullSetIterator::peekNext
T peekNext() const
Definition: QhullSet.h:318
q
q
orgQhull::QhullFacet::getFacetT
facetT * getFacetT() const
Definition: QhullFacet.h:77
orgQhull::QhullSet::last
const T last() const
Definition: QhullSet.h:169
orgQhull::QhullPoint::dimension
int dimension() const
Definition: QhullPoint.h:95
orgQhull::QhullSetIterator::hasPrevious
bool hasPrevious() const
Definition: QhullSet.h:316
orgQhull::RoadTest
Definition: RoadTest.h:54
orgQhull::QhullFacet
A QhullFacet is the C++ equivalent to Qhull's facetT*.
Definition: QhullFacet.h:43
orgQhull::RboxPoints
Definition: RboxPoints.h:37
orgQhull::QhullSet::at
const T at(countT idx) const
Definition: QhullSet.h:152
orgQhull::add_QhullPointSet_test
void add_QhullPointSet_test()
Definition: QhullPointSet_test.cpp:44
orgQhull::QhullSet::constBegin
const_iterator constBegin() const
Definition: QhullSet.h:185
QhullPoint.h
orgQhull::QhullPointSet_test
Definition: QhullPointSet_test.cpp:26
RoadTest.h
orgQhull::QhullSetIterator::next
T next()
Definition: QhullSet.h:317
orgQhull::QhullSet::front
const T front() const
Definition: QhullSet.h:166
orgQhull::QhullSet::begin
iterator begin()
Definition: QhullSet.h:183
facetT::coplanarset
setT * coplanarset
Definition: libqhull.h:305
RboxPoints.h
orgQhull::RoadTest::cleanup
void cleanup()
Executed after each test.
Definition: RoadTest.cpp:38
orgQhull::QhullSet::end
iterator end()
Definition: QhullSet.h:187
orgQhull::QhullSetIterator::hasNext
bool hasNext() const
Definition: QhullSet.h:315
orgQhull::QhullFacet::coplanarPoints
QhullPointSet coplanarPoints() const
Definition: QhullFacet.cpp:174
orgQhull::QhullSetIterator::peekPrevious
T peekPrevious() const
Definition: QhullSet.h:319


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