/**************************************************************************** ** ** Copyright (c) 2009-2015 C.B. Barber. All rights reserved. ** $Id: //main/2015/qhull/src/libqhullcpp/QhullPoints.cpp#3 $$Change: 2066 $ ** $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $ ** ****************************************************************************/ #include "libqhullcpp/QhullPoints.h" #include "libqhullcpp/Qhull.h" #include #ifndef QHULL_NO_STL #include #endif #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4 #endif namespace orgQhull { #//!\name Constructors QhullPoints:: QhullPoints(const Qhull &q) : point_first(0) , point_end(0) , qh_qh(q.qh()) , point_dimension(q.hullDimension()) { }//QhullPoints Qhull QhullPoints:: QhullPoints(const Qhull &q, countT coordinateCount2, coordT *c) : point_first(c) , point_end(c+coordinateCount2) , qh_qh(q.qh()) , point_dimension(q.hullDimension()) { QHULL_ASSERT(q.hullDimension()); QHULL_ASSERT(coordinateCount2>=0); }//QhullPoints Qhull dim QhullPoints:: QhullPoints(const Qhull &q, int pointDimension, countT coordinateCount2, coordT *c) : point_first(c) , point_end(c+coordinateCount2) , qh_qh(q.qh()) , point_dimension(pointDimension) { QHULL_ASSERT(pointDimension>=0); QHULL_ASSERT(coordinateCount2>=0); }//QhullPoints Qhull dim coordT QhullPoints:: QhullPoints(QhullQh *qqh, int pointDimension, countT coordinateCount2, coordT *c) : point_first(c) , point_end(c+coordinateCount2) , qh_qh(qqh) , point_dimension(pointDimension) { QHULL_ASSERT(pointDimension>=0); QHULL_ASSERT(coordinateCount2>=0); }//QhullPoints QhullQh dim coordT #//!\name Conversions // See qt-qhull.cpp for QList conversion #ifndef QHULL_NO_STL std::vector QhullPoints:: toStdVector() const { QhullPointsIterator i(*this); std::vector vs; while(i.hasNext()){ vs.push_back(i.next()); } return vs; }//toStdVector #endif //QHULL_NO_STL #//!\name GetSet countT QhullPoints:: extraCoordinatesCount() const { if(point_dimension>0){ return (countT)((point_end-point_first)%(size_t)point_dimension); } return 0; }//extraCoordinatesCount //! QhullPoints is equal if the same address, or if the coordinates are identical //! Use QhullPoint.operator==() for DISTround equality bool QhullPoints:: operator==(const QhullPoints &other) const { if((point_end-point_first) != (other.point_end-other.point_first)){ return false; } if(point_dimension!=other.point_dimension){ return false; } if(point_first==other.point_first){ return true; } if(!qh_qh || qh_qh->hull_dim==0){ const coordT *c= point_first; const coordT *c2= other.point_first; while(chull_dim : 0); point_first= 0; point_end= 0; }//resetQhullQh QhullPoint QhullPoints:: value(countT idx) const { QhullPoint p(qh_qh); if(idx>=0 && idx=0 && idx=n){ n= 0; }else if(length<0 || idx+length>=n){ n -= idx; }else{ n -= idx+length; } return QhullPoints(qh_qh, point_dimension, n*point_dimension, point_first+idx*point_dimension); }//mid #//!\name QhullPointsIterator bool QhullPointsIterator:: findNext(const QhullPoint &p) { while(i!=ps->constEnd()){ if(*i++ == p){ return true; } } return false; }//findNext bool QhullPointsIterator:: findPrevious(const QhullPoint &p) { while(i!=ps->constBegin()){ if(*--i == p){ return true; } } return false; }//findPrevious }//namespace orgQhull #//!\name Global functions using std::ostream; using orgQhull::QhullPoint; using orgQhull::QhullPoints; using orgQhull::QhullPointsIterator; ostream & operator<<(ostream &os, const QhullPoints &p) { QhullPointsIterator i(p); while(i.hasNext()){ os << i.next(); } return os; }//operator<