#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(7,3) << i->getX() << ' ' << FIXED(7,3) << 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; ASSERT(a.getPerpDot(b) >= 0.0); } for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) { ASSERT(inside2D(buffer.begin(), hull.second,*i)); } return 0; }