QhullPoint_test.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (c) 2008-2015 C.B. Barber. All rights reserved.
4 ** $Id: //main/2015/qhull/src/qhulltest/QhullPoint_test.cpp#3 $$Change: 2062 $
5 ** $DateTime: 2016/01/17 13:13:18 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 //pre-compiled headers
10 #include <iostream>
11 #include "RoadTest.h" // QT_VERSION
12 
13 #include "libqhullcpp/QhullPoint.h"
15 #include "libqhullcpp/RboxPoints.h"
16 #include "libqhullcpp/QhullError.h"
17 #include "libqhullcpp/QhullFacet.h"
18 #include "libqhullcpp/QhullPoint.h"
19 #include "libqhullcpp/Qhull.h"
20 
21 #include <numeric>
22 
23 using std::cout;
24 using std::endl;
25 using std::ostringstream;
26 using std::ostream;
27 using std::string;
28 
29 namespace orgQhull {
30 
31 class QhullPoint_test : public RoadTest
32 {
33  Q_OBJECT
34 
35 #
36 private slots:
37  void cleanup();
38  void t_construct();
39  void t_convert();
40  void t_readonly();
41  void t_define();
42  void t_operator();
43  void t_iterator();
44  void t_const_iterator();
45  void t_qhullpoint_iterator();
46  void t_method();
47  void t_io();
48 };//QhullPoint_test
49 
50 void
52 {
53  new QhullPoint_test(); // RoadTest::s_testcases
54 }
55 
56 //Executed after each test
59 {
61 }
62 
65 {
66  QhullPoint p12;
67  QVERIFY(!p12.isValid());
68  QCOMPARE(p12.coordinates(), (coordT *)0);
69  QCOMPARE(p12.dimension(), 0);
70  QCOMPARE(p12.qh(), (QhullQh *)0);
71  QCOMPARE(p12.id(), -3);
72  QCOMPARE(p12.begin(), p12.end());
73  QCOMPARE(p12.constBegin(), p12.constEnd());
74 
75  RboxPoints rcube("c");
76  Qhull q(rcube, "Qt QR0"); // triangulation of rotated unit cube
77  QhullPoint p(q);
78  QVERIFY(!p.isValid());
79  QCOMPARE(p.dimension(),3);
80  QCOMPARE(p.coordinates(),static_cast<double *>(0));
81  QhullPoint p7(q.qh());
82  QCOMPARE(p, p7);
83 
84  // copy constructor and copy assignment
85  QhullVertex v2(q.beginVertex());
86  QhullPoint p2(v2.point());
87  QVERIFY(p2.isValid());
88  QCOMPARE(p2.dimension(),3);
89  QVERIFY(p2!=p12);
90  p= p2;
91  QCOMPARE(p, p2);
92 
93  QhullPoint p3(q, p2.dimension(), p2.coordinates());
94  QCOMPARE(p3, p2);
95  QhullPoint p8(q, p2.coordinates()); // Qhull defines dimension
96  QCOMPARE(p8, p2);
97  QhullPoint p9(q.qh(), p2.dimension(), p2.coordinates());
98  QCOMPARE(p9, p2);
99  QhullPoint p10(q.qh(), p2.coordinates()); // Qhull defines dimension
100  QCOMPARE(p10, p2);
101 
102  Coordinates c;
103  c << 0.0 << 0.0 << 0.0;
104  QhullPoint p6(q, c);
105  QCOMPARE(p6, q.origin());
106  QhullPoint p11(q.qh(), c);
107  QCOMPARE(p11, q.origin());
108 
109  QhullPoint p5= p2; // copy constructor
110  QVERIFY(p5==p2);
111 }//t_construct
112 
115 {
116  RboxPoints rcube("c");
117  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
118  QhullVertex v= q.firstVertex();
119  QhullPoint p= v.point();
120  std::vector<double> vs= p.toStdVector();
121  QCOMPARE(vs.size(), 3u);
122  for(int k=3; k--; ){
123  QCOMPARE(vs[k], p[k]);
124  }
125  QList<double> qs= p.toQList();
126  QCOMPARE(qs.size(), 3);
127  for(int k=3; k--; ){
128  QCOMPARE(qs[k], p[k]);
129  }
130 }//t_convert
131 
134 {
135  RboxPoints rcube("c");
136  {
137  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
138  QhullVertexList vs= q.vertexList();
139  cout << "Point ids in 'rbox c'\n";
141  while(i.hasNext()){
142  QhullPoint p= i.next().point();
143  int id= p.id();
144  cout << "p" << id << endl;
145  QVERIFY(p.isValid());
146  QCOMPARE(p.dimension(),3);
147  QCOMPARE(id, p.id());
148  QVERIFY(p.id()>=0 && p.id()<9);
149  const coordT *c= p.coordinates();
150  coordT *c2= p.coordinates();
151  QCOMPARE(c, c2);
152  QCOMPARE(p.dimension(), 3);
153  QCOMPARE(q.qh(), p.qh());
154  }
155  QhullPoint p2= vs.first().point();
156  QhullPoint p3= vs.last().point();
157  QVERIFY(p2!=p3);
158  QVERIFY(p3.coordinates()!=p2.coordinates());
159  }
160 }//t_readonly
161 
164 {
165  RboxPoints rcube("c");
166  {
167  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
168  QhullVertexList vs= q.vertexList();
169  QhullPoint p= vs.first().point();
170  QhullPoint p2= p;
171  QVERIFY(p==p2);
172  QhullPoint p3= vs.last().point();
173  QVERIFY(p2!=p3);
174  int idx= (p3.coordinates()-p2.coordinates())/p2.dimension();
175  QVERIFY(idx>-8 && idx<8);
176  p2.advancePoint(idx);
177  QVERIFY(p2==p3);
178  p2.advancePoint(-idx);
179  QVERIFY(p2==p);
180  p2.advancePoint(0);
181  QVERIFY(p2==p);
182 
183  QhullPoint p4= p3;
184  QVERIFY(p4==p3);
185  p4.defineAs(p2);
186  QVERIFY(p2==p4);
187  QhullPoint p5= p3;
188  p5.defineAs(p2.dimension(), p2.coordinates());
189  QVERIFY(p2==p5);
190  QhullPoint p6= p3;
191  p6.setCoordinates(p2.coordinates());
192  QCOMPARE(p2.coordinates(), p6.coordinates());
193  QVERIFY(p2==p6);
194  p6.setDimension(2);
195  QCOMPARE(p6.dimension(), 2);
196  QVERIFY(p2!=p6);
197  }
198 }//t_define
199 
202 {
203  RboxPoints rcube("c");
204  Qhull q(rcube,"Qt QR0"); // triangulation of rotated unit cube
205  const QhullPoint p= q.firstVertex().point();
206  //operator== and operator!= tested elsewhere
207  const coordT *c= p.coordinates();
208  for(int k=p.dimension(); k--; ){
209  QCOMPARE(c[k], p[k]);
210  }
211  //p[0]= 10.0; // compiler error, const
212  QhullPoint p2= q.firstVertex().point();
213  p2[0]= 10.0; // Overwrites point coordinate
214  QCOMPARE(p2[0], 10.0);
215 }//t_operator
216 
219 {
220  RboxPoints rcube("c");
221  {
222  Qhull q(rcube,"QR0"); // rotated unit cube
223  QhullPoint p2(q);
224  QCOMPARE(p2.begin(), p2.end());
225 
226  QhullPoint p= q.firstVertex().point();
228  QhullPoint::iterator i2= p.begin();
229  QVERIFY(i==i2);
230  QVERIFY(i>=i2);
231  QVERIFY(i<=i2);
232  i= p.begin();
233  QVERIFY(i==i2);
234  i2= p.end();
235  QVERIFY(i!=i2);
236  double d3= *i;
237  i2--;
238  double d2= *i2;
239  QCOMPARE(d3, p[0]);
240  QCOMPARE(d2, p[2]);
241  QhullPoint::Iterator i3(i2);
242  QCOMPARE(*i2, *i3);
243 
244  (i3= i)++;
245  QCOMPARE((*i3), p[1]);
246  QVERIFY(i==i);
247  QVERIFY(i!=i2);
248  QVERIFY(i<i2);
249  QVERIFY(i<=i2);
250  QVERIFY(i2>i);
251  QVERIFY(i2>=i);
252 
254  QVERIFY(i==i4); // iterator COMP const_iterator
255  QVERIFY(i<=i4);
256  QVERIFY(i>=i4);
257  QVERIFY(i4==i); // const_iterator COMP iterator
258  QVERIFY(i4<=i);
259  QVERIFY(i4>=i);
260  QVERIFY(i>=i4);
261  QVERIFY(i4<=i);
262  QVERIFY(i2!=i4);
263  QVERIFY(i2>i4);
264  QVERIFY(i2>=i4);
265  QVERIFY(i4!=i2);
266  QVERIFY(i4<i2);
267  QVERIFY(i4<=i2);
268  ++i4;
269  QVERIFY(i<i4);
270  QVERIFY(i<=i4);
271  QVERIFY(i4>i);
272  QVERIFY(i4>=i);
273 
274  i= p.begin();
275  i2= p.begin();
276  QCOMPARE(i, i2++);
277  QCOMPARE(*i2, p[1]);
278  QCOMPARE(++i, i2);
279  QCOMPARE(i, i2--);
280  QCOMPARE(i2, p.begin());
281  QCOMPARE(--i, i2);
282  QCOMPARE(i2 += 3, p.end());
283  QCOMPARE(i2 -= 3, p.begin());
284  QCOMPARE(i2+0, p.begin());
285  QCOMPARE(i2+3, p.end());
286  i2 += 3;
287  i= i2-0;
288  QCOMPARE(i, i2);
289  i= i2-3;
290  QCOMPARE(i, p.begin());
291  QCOMPARE(i2-i, 3);
292 
293  //p.begin end tested above
294 
295  // QhullPoint is const-only
296  }
297 }//t_iterator
298 
301 {
302  RboxPoints rcube("c");
303  {
304  Qhull q(rcube,"QR0"); // rotated unit cube
305  QhullPoint p= q.firstVertex().point();
308  QVERIFY(i==i2);
309  QVERIFY(i>=i2);
310  QVERIFY(i<=i2);
311  i= p.begin();
312  QVERIFY(i==i2);
313  i2= p.end();
314  QVERIFY(i!=i2);
315  double d3= *i;
316  i2--;
317  double d2= *i2;
318  QCOMPARE(d3, p[0]);
319  QCOMPARE(d2, p[2]);
321  QCOMPARE(*i2, *i3);
322 
323  (i3= i)++;
324  QCOMPARE((*i3), p[1]);
325  QVERIFY(i==i);
326  QVERIFY(i!=i2);
327  QVERIFY(i<i2);
328  QVERIFY(i<=i2);
329  QVERIFY(i2>i);
330  QVERIFY(i2>=i);
331 
332  // See t_iterator for const_iterator COMP iterator
333 
334  i= p.begin();
335  i2= p.constBegin();
336  QCOMPARE(i, i2++);
337  QCOMPARE(*i2, p[1]);
338  QCOMPARE(++i, i2);
339  QCOMPARE(i, i2--);
340  QCOMPARE(i2, p.constBegin());
341  QCOMPARE(--i, i2);
342  QCOMPARE(i2+=3, p.constEnd());
343  QCOMPARE(i2-=3, p.constBegin());
344  QCOMPARE(i2+0, p.constBegin());
345  QCOMPARE(i2+3, p.constEnd());
346  i2 += 3;
347  i= i2-0;
348  QCOMPARE(i, i2);
349  i= i2-3;
350  QCOMPARE(i, p.constBegin());
351  QCOMPARE(i2-i, 3);
352 
353  // QhullPoint is const-only
354  }
355 }//t_const_iterator
356 
359 {
360  RboxPoints rcube("c");
361  Qhull q(rcube,"QR0"); // rotated unit cube
362 
363  QhullPoint p2(q);
364  QhullPointIterator i= p2;
365  QCOMPARE(p2.dimension(), 3);
366  QVERIFY(!i.hasNext());
367  QVERIFY(!i.hasPrevious());
368  i.toBack();
369  QVERIFY(!i.hasNext());
370  QVERIFY(!i.hasPrevious());
371 
372  QhullPoint p = q.firstVertex().point();
373  QhullPointIterator i2(p);
374  QCOMPARE(p.dimension(), 3);
375  i= p;
376  QVERIFY(i2.hasNext());
377  QVERIFY(!i2.hasPrevious());
378  QVERIFY(i.hasNext());
379  QVERIFY(!i.hasPrevious());
380  i2.toBack();
381  i.toFront();
382  QVERIFY(!i2.hasNext());
383  QVERIFY(i2.hasPrevious());
384  QVERIFY(i.hasNext());
385  QVERIFY(!i.hasPrevious());
386 
387  // i at front, i2 at end/back, 3 coordinates
388  QCOMPARE(i.peekNext(), p[0]);
389  QCOMPARE(i2.peekPrevious(), p[2]);
390  QCOMPARE(i2.previous(), p[2]);
391  QCOMPARE(i2.previous(), p[1]);
392  QCOMPARE(i2.previous(), p[0]);
393  QVERIFY(!i2.hasPrevious());
394  QCOMPARE(i.peekNext(), p[0]);
395  // i.peekNext()= 1.0; // compiler error, i is const
396  QCOMPARE(i.next(), p[0]);
397  QCOMPARE(i.peekNext(), p[1]);
398  QCOMPARE(i.next(), p[1]);
399  QCOMPARE(i.next(), p[2]);
400  QVERIFY(!i.hasNext());
401  i.toFront();
402  QCOMPARE(i.next(), p[0]);
403 }//t_qhullpoint_iterator
404 
407 {
408  // advancePoint tested above
409  RboxPoints rcube("c");
410  Qhull q(rcube, "");
411  QhullPoint p = q.firstVertex().point();
412  double dist= p.distance(q.origin());
413  QCOMPARE(dist, sqrt(double(2.0+1.0))/2); // half diagonal of unit cube
414 }//t_qhullpoint_iterator
415 
418 {
419  RboxPoints rcube("c");
420  {
421  Qhull q(rcube, "");
422  QhullPoint p= q.beginVertex().point();
423  ostringstream os;
424  os << "Point:\n";
425  os << p;
426  os << "Point w/ print:\n";
427  os << p.print(" message ");
428  os << p.printWithIdentifier(" Point with id and a message ");
429  cout << os.str();
430  QString s= QString::fromStdString(os.str());
431  QCOMPARE(s.count("p"), 2);
432  }
433 }//t_io
434 
435 }//orgQhull
436 
437 #include "moc/QhullPoint_test.moc"
orgQhull::QhullPoint_test::t_operator
void t_operator()
Definition: QhullPoint_test.cpp:201
Coordinates.h
QhullFacet.h
orgQhull::QhullPoint::setDimension
void setDimension(int pointDimension)
Definition: QhullPoint.h:105
coordT
#define coordT
Definition: libqhull.h:80
orgQhull::QhullPoint::id
countT id() const
Definition: QhullPoint.h:97
orgQhull::QhullPoint::ConstIterator
QhullPoint::const_iterator ConstIterator
Definition: QhullPoint.h:47
orgQhull::QhullPoint::advancePoint
void advancePoint(countT idx)
Definition: QhullPoint.h:118
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
orgQhull::QhullPoint_test::t_iterator
void t_iterator()
Definition: QhullPoint_test.cpp:218
orgQhull::QhullPoint
Definition: QhullPoint.h:39
orgQhull::QhullPoint::constEnd
const_iterator constEnd() const
Definition: QhullPoint.h:111
orgQhull::QhullPoint_test::cleanup
void cleanup()
Definition: QhullPoint_test.cpp:58
Qhull.h
orgQhull::QhullVertex
Definition: QhullVertex.h:48
orgQhull::QhullPoint::toStdVector
std::vector< coordT > toStdVector() const
Definition: QhullPoint.cpp:71
orgQhull::QhullPoint_test
Definition: QhullPoint_test.cpp:31
orgQhull::QhullLinkedListIterator::hasNext
bool hasNext() const
Definition: QhullLinkedList.h:211
orgQhull::QhullPoint::print
PrintPoint print(const char *message) const
Definition: QhullPoint.h:129
orgQhull::QhullPoint::end
iterator end()
Definition: QhullPoint.h:113
orgQhull::QhullPoint::distance
double distance(const QhullPoint &p) const
Return distance between two points.
Definition: QhullPoint.cpp:123
orgQhull::Qhull
Interface to Qhull from C++.
Definition: Qhull.h:49
orgQhull::QhullPoint::setCoordinates
void setCoordinates(coordT *c)
Definition: QhullPoint.h:104
orgQhull::QhullPoint_test::t_const_iterator
void t_const_iterator()
Definition: QhullPoint_test.cpp:300
c
c
orgQhull::QhullPoint_test::t_method
void t_method()
Definition: QhullPoint_test.cpp:406
orgQhull::QhullPoint::begin
iterator begin()
Definition: QhullPoint.h:108
orgQhull::QhullPoint_test::t_define
void t_define()
Definition: QhullPoint_test.cpp:163
orgQhull::QhullQh
POD type equivalent to qhT. No virtual members.
Definition: QhullQh.h:58
orgQhull::QhullLinkedListIterator::next
T next()
Definition: QhullLinkedList.h:213
orgQhull::QhullPoint::qh
QhullQh * qh()
Definition: QhullPoint.h:103
q
q
orgQhull::QhullPoint::iterator
const typedef coordT * iterator
Definition: QhullPoint.h:44
orgQhull::QhullPoint::dimension
int dimension() const
Definition: QhullPoint.h:95
orgQhull::RoadTest
Definition: RoadTest.h:54
orgQhull::RboxPoints
Definition: RboxPoints.h:37
QhullPoint.h
orgQhull::QhullLinkedList::first
const T & first() const
Definition: QhullLinkedList.h:106
orgQhull::QhullLinkedListIterator
Definition: QhullLinkedList.h:200
orgQhull::QhullPoint::const_iterator
const typedef coordT * const_iterator
Definition: QhullPoint.h:45
RoadTest.h
orgQhull::QhullVertex::point
QhullPoint point() const
Definition: QhullVertex.h:95
orgQhull::Coordinates
Definition: Coordinates.h:38
orgQhull::QhullLinkedList
Definition: QhullLinkedList.h:50
orgQhull::QhullPoint::constBegin
const_iterator constBegin() const
Definition: QhullPoint.h:110
orgQhull::QhullPoint_test::t_readonly
void t_readonly()
Definition: QhullPoint_test.cpp:133
orgQhull::QhullPoint_test::t_qhullpoint_iterator
void t_qhullpoint_iterator()
Definition: QhullPoint_test.cpp:358
orgQhull::QhullPoint_test::t_io
void t_io()
Definition: QhullPoint_test.cpp:417
orgQhull::QhullPoint::defineAs
void defineAs(coordT *c)
Definition: QhullPoint.h:92
orgQhull::QhullPoint_test::t_convert
void t_convert()
Definition: QhullPoint_test.cpp:114
orgQhull::QhullPoint::isValid
bool isValid() const
Definition: QhullPoint.h:98
c2
c2
orgQhull::QhullPoint::Iterator
QhullPoint::iterator Iterator
Definition: QhullPoint.h:46
orgQhull::add_QhullPoint_test
void add_QhullPoint_test()
Definition: QhullPoint_test.cpp:51
RboxPoints.h
QhullError.h
orgQhull::QhullLinkedList::last
const T last() const
Definition: QhullLinkedList.h:110
orgQhull::RoadTest::cleanup
void cleanup()
Executed after each test.
Definition: RoadTest.cpp:38
obb.v
list v
Definition: obb.py:48
orgQhull::QhullPoint_test::t_construct
void t_construct()
Definition: QhullPoint_test.cpp:64


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:58