#include #include #include #include #include "TRandom3.h" #include "JGeometry2D/JVector2D.hh" #include "JGeometry2D/JGeometry2DToolkit.hh" #include "JGeometry2D/JGeometry2DTestkit.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Example program to test convex hull. * \author mdejong */ int main(int argc, char* argv[]) { using namespace std; int numberOfPoints; UInt_t seed; int debug; try { JParser<> zap("Example program to test convex hull."); zap['n'] = make_field(numberOfPoints) = 10; zap['S'] = make_field(seed) = 0; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } gRandom->SetSeed(seed); using namespace JPP; ASSERT(numberOfPoints > 2); vector buffer; typedef vector::const_iterator const_iterator; typedef vector::iterator iterator; for (int i = 0; i != numberOfPoints; ++i) { buffer.push_back(getRandom()); } for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) { DEBUG(FIXED(9,5) << i->getX() << ' ' << FIXED(9,5) << i->getY() << endl); } pair hull = getConvexHull2D(buffer.begin(), buffer.end()); for (const_iterator k = buffer.begin(), i = k++, j = k++; j != hull.second; ++i, ++j, ++k) { if (k == hull.second) { k = buffer.begin(); } const JVector2D a = *j - *i; const JVector2D b = *k - *j; DEBUG("perpdot " << FIXED(9,5) << i->getX() << ' ' << FIXED(9,5) << i->getY() << ' ' << FIXED(9,5) << j->getX() << ' ' << FIXED(9,5) << j->getY() << ' ' << FIXED(9,5) << k->getX() << ' ' << FIXED(9,5) << k->getY() << ' ' << FIXED(9,5) << a.getPerpDot(b) << endl); ASSERT(a.getPerpDot(b) >= 0.0); } for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) { DEBUG("inside " << FIXED(9,5) << i->getX() << ' ' << FIXED(9,5) << i->getY() << ' ' << (distance(i, hull.second) <= 0) << ' ' << inside2D(buffer.cbegin(), hull.second,*i) << endl); ASSERT(inside2D(buffer.cbegin(), hull.second,*i)); } return 0; }