-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
105 lines (100 loc) · 3.34 KB
/
Copy pathmain.cpp
File metadata and controls
105 lines (100 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <bits/stdc++.h>
#include "quadTree.cpp"
#include <random>
#include <time.h>
using namespace std;
void help(){
cout<<left<<setw(32)<<"Functions"<<"command"<<endl;
cout<<left<<setw(32)<<"insertion"<<"i"<<endl;
cout<<left<<setw(32)<<"multiple insertion(bulkload)"<<"mi"<<endl;
cout<<left<<setw(32)<<"enter 10 random points: "<<"rand"<<endl;
cout<<left<<setw(32)<<"range Query"<<"rquery"<<endl;
cout<<left<<setw(32)<<"k nearest element"<<"knn"<<endl;
cout<<left<<setw(32)<<"help"<<"help"<<endl;
cout<<left<<setw(32)<<"exit"<<"exit"<<endl;
}
int main()
{
Rectangle region(100, 100, 200, 200); // x-cordinate, y-cordinate, width, height
quadTree qt(region, 4);
string choice;
cout<<"\nQuad Tree is created of size 200 * 200\n\n";
help();
cout<<endl;
while(1){
cout<<"enter your choice: ";
cin>>choice;
if(choice == "i"){
double x, y;
cout<<"enter x: ";cin>>x;
cout<<"enter y: ";cin>>y;
qt.insert(Point(x, y));
cout<<"Point ("<<x<<", "<<y<<") inserted successfully\n\n";
}
else if(choice == "mi"){
vector<Point> bulk;
int n;
double x, y;
cout<<"enter number of points to enter: ";cin>>n;
while(n--){
cout<<"enter x: ";cin>>x;
cout<<"enter y: ";cin>>y;
bulk.push_back(Point(x, y));
}
qt.bulkLoadquadTree(bulk);
cout<<"Bulkloading done successfully\n\n";
}
else if(choice == "rquery"){
double x, y, w, h;
cout<<"define the region for query: \n";
cout<<"enter x: ";cin>>x;
cout<<"enter y: ";cin>>y;
cout<<"enter w: ";cin>>w;
cout<<"enter h: ";cin>>h;
Rectangle rquery = Rectangle(x, y, w, h);
vector<Point> ans = qt.rangeQuery(rquery);
cout<<"Points lie in the region are: \n";
if(ans.empty()) cout<<"No points found\n";
else
for(auto point: ans){
cout<<"x: "<<point.x<<"\t"<<"y: "<<point.y<<endl;
}
}
else if(choice == "rand"){
srand(time(0));
vector<Point> input;
for (int i = 0; i < 10; i++){
Point x = Point(rand()%200, rand()%200);
input.push_back(x);
}
qt.bulkLoadquadTree(input);
cout<<"10 random points are inserted\n\n";
}
else if(choice == "knn"){
Point p;int n;
cout<<"enter x: ";cin>>p.x;
cout<<"enter y: ";cin>>p.y;
cout<<"enter number of points: ";cin>>n;
vector<Point> ans = qt.knnSearch(p, n);
if(ans.empty()) cout<<"there are no points\n\n";
else{
cout<<n<<" points nearest to point ("<< p.x<<", "<<p.y<<") are: \n";
for(auto point: ans){
cout<<"x: "<<point.x<<"\ty: "<<point.y<<endl;
}
cout<<endl;
}
}
else if(choice == "help"){
help();
cout<<endl;
}
else if(choice == "exit") break;
else {
cout<<"\'"<<choice<<"\'"<<" command not found\n";
help();
cout<<endl;
}
}
return 0;
}