31int main(
int argc,
char* argv[])
43 JParser<> zap(
"Example program to find smallest distance between two points.");
53 catch(
const exception &error) {
54 FATAL(error.what() << endl);
57 gRandom->SetSeed(seed);
64 typedef vector<JVector2D>::const_iterator const_iterator;
67 if (inputFile !=
"") {
69 ifstream in(inputFile.c_str());
71 for (
double x, y; in >> x >> y; ) {
79 NOTICE(
"Seed: " << gRandom->GetSeed() << endl);
83 buffer.push_back(
JVector2D(gRandom->Uniform(-1.0, +1.0),
84 gRandom->Uniform(-1.0, +1.0)));
91 for (const_iterator i = buffer.begin(); i != buffer.end(); ++i)
92 out << setw(7) << i->getX() <<
' '
93 << setw(7) << i->getY() << endl;
99 if (buffer.size() < 2) {
100 FATAL(
"Not enough points." << endl);
103 for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
104 DEBUG(i->getX() <<
' ' << i->getY() << endl);
113 double dmin = numeric_limits<double>::max();
115 for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
116 for (const_iterator j = i; ++j != buffer.end(); ) {
118 const double d = i->getDistance(*j);
128 cout <<
"Minimal distance " <<
SCIENTIFIC(12,5) << dmin << endl;
133 JTimer timer(
"O(n log(n))");
137 const double dmin = getSmallestDistance2D(buffer.begin(), buffer.end());
141 cout <<
"Minimal distance " <<
SCIENTIFIC(12,5) << dmin << endl;
148 <<
"(" <<
FIXED(7,5) << result.first ->getX() <<
"," <<
FIXED(7,5) << result.first ->getY() <<
")" <<
' '
149 <<
"(" <<
FIXED(7,5) << result.second->getX() <<
"," <<
FIXED(7,5) << result.second->getY() <<
")" << endl;
150 cout <<
"Distance " <<
SCIENTIFIC(12,5) << result.first->getDistance(*result.second) << endl;
153 TApplication* tp =
new TApplication(
"user", NULL, NULL);
155 TCanvas cv(
"cv",
"", 400, 400);
157 cv.SetFillStyle(4000);
164 const Int_t MAX_BUFFER_SIZE = buffer.size() + 1;
166 Double_t x[MAX_BUFFER_SIZE];
167 Double_t y[MAX_BUFFER_SIZE];
171 for (const_iterator i = buffer.begin(); i != buffer.end(); ++i, ++N) {
177 Double_t xmin = -1.1;
178 Double_t xmax = +1.1;
179 Double_t ymin = -1.1;
180 Double_t ymax = +1.1;
182 TH2D h2(
"h2",
"", 1000, xmin, xmax, 1000, ymin, ymax);
190 g.SetMarkerStyle(20);
191 g.SetMarkerColor(kBlack);
192 g.SetMarkerSize(0.7);
195 TMarker m1(result.first ->getX(), result.first ->getY(), 20);
196 TMarker m2(result.second->getX(), result.second->getY(), 20);
198 m1.SetMarkerColor(kRed);
199 m2.SetMarkerColor(kRed);
201 m1.SetMarkerSize(0.7);
202 m2.SetMarkerSize(0.7);