QhullPoint_test.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2008-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/qhulltest/QhullPoint_test.cpp#2 $$Change: 1342 $
00005 ** $DateTime: 2011/03/07 21:55:47 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 //pre-compiled headers
00010 #include <iostream>
00011 #include "../road/RoadTest.h"
00012 
00013 #include "QhullPoint.h"
00014 #include "Coordinates.h"
00015 #include "RboxPoints.h"
00016 #include "QhullError.h"
00017 #include "QhullFacet.h"
00018 #include "QhullPoint.h"
00019 #include "Qhull.h"
00020 
00021 #include <numeric>
00022 
00023 using std::cout;
00024 using std::endl;
00025 using std::ostringstream;
00026 using std::ostream;
00027 using std::string;
00028 
00029 namespace orgQhull {
00030 
00031 class QhullPoint_test : public RoadTest
00032 {
00033     Q_OBJECT
00034 
00035 #//Test slots
00036 private slots:
00037     void cleanup();
00038     void t_construct();
00039     void t_convert();
00040     void t_readonly();
00041     void t_define();
00042     void t_operator();
00043     void t_iterator();
00044     void t_const_iterator();
00045     void t_qhullpoint_iterator();
00046     void t_io();
00047 };//QhullPoint_test
00048 
00049 void
00050 add_QhullPoint_test()
00051 {
00052     new QhullPoint_test();
00053 }
00054 
00055 //Executed after each test
00056 void QhullPoint_test::
00057 cleanup()
00058 {
00059     UsingLibQhull::checkQhullMemoryEmpty();
00060     RoadTest::cleanup();
00061 }
00062 
00063 void QhullPoint_test::
00064 t_construct()
00065 {
00066     // Qhull.runQhull() constructs QhullFacets as facetT
00067     QhullPoint p;
00068     QVERIFY(!p.isDefined());
00069     QCOMPARE(p.dimension(),0);
00070     QCOMPARE(p.coordinates(),static_cast<double *>(0));
00071     RboxPoints rcube("c");
00072     Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00073     QhullVertex v2(q.beginVertex());
00074     QhullPoint p2(v2.point());
00075     QVERIFY(p2.isDefined());
00076     QCOMPARE(p2.dimension(),3);
00077     // p= p2;  // copy assignment disabled, ambiguous
00078     QhullPoint p3(p2.dimension(), p2.coordinates());
00079     QCOMPARE(p2, p3);
00080     Coordinates c;
00081     c << 0.0 << 0.0 << 0.0;
00082     QhullPoint p6(c);
00083     QCOMPARE(p6, q.origin());
00084     QhullPoint p5= p2; // copy constructor
00085     QVERIFY(p5==p2);
00086 }//t_construct
00087 
00088 void QhullPoint_test::
00089 t_convert()
00090 {
00091     RboxPoints rcube("c");
00092     Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00093     QhullVertex v= q.firstVertex();
00094     QhullPoint p= v.point();
00095     std::vector<double> vs= p.toStdVector();
00096     QCOMPARE(vs.size(), 3u);
00097     for(int k=3; k--; ){
00098         QCOMPARE(vs[k], p[k]);
00099     }
00100     QList<double> qs= p.toQList();
00101     QCOMPARE(qs.size(), 3);
00102     for(int k=3; k--; ){
00103         QCOMPARE(qs[k], p[k]);
00104     }
00105 }//t_convert
00106 
00107 void QhullPoint_test::
00108 t_readonly()
00109 {
00110     RboxPoints rcube("c");
00111     {
00112         Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00113         QhullVertexList vs= q.vertexList();
00114         QhullVertexListIterator i(vs);
00115         while(i.hasNext()){
00116             QhullPoint p= i.next().point();
00117             int id= p.id(q.runId());
00118             cout << "p" << id << endl;
00119             QVERIFY(p.isDefined());
00120             QCOMPARE(p.dimension(),3);
00121             QCOMPARE(id, p.id());
00122             QVERIFY(p.id()>=0 && p.id()<9);
00123             const coordT *c= p.coordinates();
00124             coordT *c2= p.coordinates();
00125             QCOMPARE(c, c2);
00126             QCOMPARE(p.dimension(), 3);
00127         }
00128         QhullPoint p2= vs.first().point();
00129         QhullPoint p3= vs.last().point();
00130         QVERIFY(p2!=p3);
00131         QVERIFY(p3.coordinates()!=p2.coordinates());
00132     }
00133 }//t_readonly
00134 
00135 void QhullPoint_test::
00136 t_define()
00137 {
00138     RboxPoints rcube("c");
00139     {
00140         Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00141         QhullVertexList vs= q.vertexList();
00142         QhullPoint p= vs.first().point();
00143         QhullPoint p2= p;
00144         QVERIFY(p==p2);
00145         QhullPoint p3= vs.last().point();
00146         QVERIFY(p2!=p3);
00147         int idx= (p3.coordinates()-p2.coordinates())/p2.dimension();
00148         QVERIFY(idx>-8 && idx<8);
00149         p2.advancePoint(idx);
00150         QVERIFY(p2==p3);
00151         p2.advancePoint(-idx);
00152         QVERIFY(p2==p);
00153         p2.advancePoint(0);
00154         QVERIFY(p2==p);
00155 
00156         QhullPoint p4= p3;
00157         p4.defineAs(p2);
00158         QVERIFY(p2==p4);
00159         QhullPoint p5= p3;
00160         p5.defineAs(p2.dimension(), p2.coordinates());
00161         QVERIFY(p2==p5);
00162         QhullPoint p6= p3;
00163         p6.setCoordinates(p2.coordinates());
00164         QCOMPARE(p2.coordinates(), p6.coordinates());
00165         QVERIFY(p2==p6);
00166         p6.setDimension(2);
00167         QCOMPARE(p6.dimension(), 2);
00168         QVERIFY(p2!=p6);
00169     }
00170 }//t_define
00171 
00172 void QhullPoint_test::
00173 t_operator()
00174 {
00175     RboxPoints rcube("c");
00176     Qhull q(rcube,"Qt QR0");  // triangulation of rotated unit cube
00177     const QhullPoint p= q.firstVertex().point();
00178     //operator== and operator!= tested elsewhere
00179     const coordT *c= p.coordinates();
00180     for(int k=p.dimension(); k--; ){
00181         QCOMPARE(c[k], p[k]);
00182     }
00183     //p[0]= 10.0; // compiler error, const
00184     QhullPoint p2= q.firstVertex().point();
00185     p2[0]= 10.0;  // Overwrites point coordinate
00186     QCOMPARE(p2[0], 10.0);
00187 }//t_operator
00188 
00189 void QhullPoint_test::
00190 t_iterator()
00191 {
00192     RboxPoints rcube("c");
00193     {
00194         QhullPoint p2;
00195         QCOMPARE(p2.begin(), p2.end());
00196         Qhull q(rcube,"QR0");  // rotated unit cube
00197         QhullPoint p= q.firstVertex().point();
00198         QhullPoint::Iterator i= p.begin();
00199         QhullPoint::iterator i2= p.begin();
00200         QVERIFY(i==i2);
00201         QVERIFY(i>=i2);
00202         QVERIFY(i<=i2);
00203         i= p.begin();
00204         QVERIFY(i==i2);
00205         i2= p.end();
00206         QVERIFY(i!=i2);
00207         double d3= *i;
00208         i2--;
00209         double d2= *i2;
00210         QCOMPARE(d3, p[0]);
00211         QCOMPARE(d2, p[2]);
00212         QhullPoint::Iterator i3(i2);
00213         QCOMPARE(*i2, *i3);
00214 
00215         (i3= i)++;
00216         QCOMPARE((*i3), p[1]);
00217         QVERIFY(i==i);
00218         QVERIFY(i!=i2);
00219         QVERIFY(i<i2);
00220         QVERIFY(i<=i2);
00221         QVERIFY(i2>i);
00222         QVERIFY(i2>=i);
00223 
00224         QhullPoint::ConstIterator i4= p.begin();
00225         QVERIFY(i==i4); // iterator COMP const_iterator
00226         QVERIFY(i<=i4);
00227         QVERIFY(i>=i4);
00228         QVERIFY(i4==i); // const_iterator COMP iterator
00229         QVERIFY(i4<=i);
00230         QVERIFY(i4>=i);
00231         QVERIFY(i>=i4);
00232         QVERIFY(i4<=i);
00233         QVERIFY(i2!=i4);
00234         QVERIFY(i2>i4);
00235         QVERIFY(i2>=i4);
00236         QVERIFY(i4!=i2);
00237         QVERIFY(i4<i2);
00238         QVERIFY(i4<=i2);
00239         ++i4;
00240         QVERIFY(i<i4);
00241         QVERIFY(i<=i4);
00242         QVERIFY(i4>i);
00243         QVERIFY(i4>=i);
00244 
00245         i= p.begin();
00246         i2= p.begin();
00247         QCOMPARE(i, i2++);
00248         QCOMPARE(*i2, p[1]);
00249         QCOMPARE(++i, i2);
00250         QCOMPARE(i, i2--);
00251         QCOMPARE(i2, p.begin());
00252         QCOMPARE(--i, i2);
00253         QCOMPARE(i2 += 3, p.end());
00254         QCOMPARE(i2 -= 3, p.begin());
00255         QCOMPARE(i2+0, p.begin());
00256         QCOMPARE(i2+3, p.end());
00257         i2 += 3;
00258         i= i2-0;
00259         QCOMPARE(i, i2);
00260         i= i2-3;
00261         QCOMPARE(i, p.begin());
00262         QCOMPARE(i2-i, 3);
00263 
00264         //p.begin end tested above
00265 
00266         // QhullPoint is const-only
00267     }
00268 }//t_iterator
00269 
00270 void QhullPoint_test::
00271 t_const_iterator()
00272 {
00273     RboxPoints rcube("c");
00274     {
00275         Qhull q(rcube,"QR0");  // rotated unit cube
00276         QhullPoint p= q.firstVertex().point();
00277         QhullPoint::ConstIterator i= p.begin();
00278         QhullPoint::const_iterator i2= p.begin();
00279         QVERIFY(i==i2);
00280         QVERIFY(i>=i2);
00281         QVERIFY(i<=i2);
00282         i= p.begin();
00283         QVERIFY(i==i2);
00284         i2= p.end();
00285         QVERIFY(i!=i2);
00286         double d3= *i;
00287         i2--;
00288         double d2= *i2;
00289         QCOMPARE(d3, p[0]);
00290         QCOMPARE(d2, p[2]);
00291         QhullPoint::ConstIterator i3(i2);
00292         QCOMPARE(*i2, *i3);
00293 
00294         (i3= i)++;
00295         QCOMPARE((*i3), p[1]);
00296         QVERIFY(i==i);
00297         QVERIFY(i!=i2);
00298         QVERIFY(i<i2);
00299         QVERIFY(i<=i2);
00300         QVERIFY(i2>i);
00301         QVERIFY(i2>=i);
00302 
00303         // See t_iterator for const_iterator COMP iterator
00304 
00305         i= p.begin();
00306         i2= p.constBegin();
00307         QCOMPARE(i, i2++);
00308         QCOMPARE(*i2, p[1]);
00309         QCOMPARE(++i, i2);
00310         QCOMPARE(i, i2--);
00311         QCOMPARE(i2, p.constBegin());
00312         QCOMPARE(--i, i2);
00313         QCOMPARE(i2+=3, p.constEnd());
00314         QCOMPARE(i2-=3, p.constBegin());
00315         QCOMPARE(i2+0, p.constBegin());
00316         QCOMPARE(i2+3, p.constEnd());
00317         i2 += 3;
00318         i= i2-0;
00319         QCOMPARE(i, i2);
00320         i= i2-3;
00321         QCOMPARE(i, p.constBegin());
00322         QCOMPARE(i2-i, 3);
00323 
00324         // QhullPoint is const-only
00325     }
00326 }//t_const_iterator
00327 
00328 void QhullPoint_test::
00329 t_qhullpoint_iterator()
00330 {
00331     QhullPoint p2;
00332     QhullPointIterator i= p2;
00333     QCOMPARE(p2.dimension(), 0);
00334     QVERIFY(!i.hasNext());
00335     QVERIFY(!i.hasPrevious());
00336     i.toBack();
00337     QVERIFY(!i.hasNext());
00338     QVERIFY(!i.hasPrevious());
00339 
00340     RboxPoints rcube("c");
00341     Qhull q(rcube,"QR0");  // rotated unit cube
00342     QhullPoint p = q.firstVertex().point();
00343     QhullPointIterator i2(p);
00344     QCOMPARE(p.dimension(), 3);
00345     i= p;
00346     QVERIFY(i2.hasNext());
00347     QVERIFY(!i2.hasPrevious());
00348     QVERIFY(i.hasNext());
00349     QVERIFY(!i.hasPrevious());
00350     i2.toBack();
00351     i.toFront();
00352     QVERIFY(!i2.hasNext());
00353     QVERIFY(i2.hasPrevious());
00354     QVERIFY(i.hasNext());
00355     QVERIFY(!i.hasPrevious());
00356 
00357     // i at front, i2 at end/back, 3 coordinates
00358     QCOMPARE(i.peekNext(), p[0]);
00359     QCOMPARE(i2.peekPrevious(), p[2]);
00360     QCOMPARE(i2.previous(), p[2]);
00361     QCOMPARE(i2.previous(), p[1]);
00362     QCOMPARE(i2.previous(), p[0]);
00363     QVERIFY(!i2.hasPrevious());
00364     QCOMPARE(i.peekNext(), p[0]);
00365     // i.peekNext()= 1.0; // compiler error, i is const
00366     QCOMPARE(i.next(), p[0]);
00367     QCOMPARE(i.peekNext(), p[1]);
00368     QCOMPARE(i.next(), p[1]);
00369     QCOMPARE(i.next(), p[2]);
00370     QVERIFY(!i.hasNext());
00371     i.toFront();
00372     QCOMPARE(i.next(), p[0]);
00373 }//t_qhullpoint_iterator
00374 
00375 void QhullPoint_test::
00376 t_io()
00377 {
00378     RboxPoints rcube("c");
00379     {
00380         Qhull q(rcube, "");
00381         QhullPoint p= q.beginVertex().point();
00382         ostringstream os;
00383         os << "Point w/o runId:\n";
00384         os << p;
00385         os << "Point w/ runId:\n";
00386         os << p.print(q.runId()) << p.print(q.runId(), " and a message ");
00387         os << p.printWithIdentifier(q.runId(), " Point with id and a message ");
00388         cout << os.str();
00389         QString s= QString::fromStdString(os.str());
00390         QCOMPARE(s.count("p"), 3);
00391         // QCOMPARE(s.count(QRegExp("f\\d")), 3*7 + 13*3*2);
00392     }
00393 }//t_io
00394 
00395 }//orgQhull
00396 
00397 #include "moc/QhullPoint_test.moc"


libqhull-ours
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:11