-
Notifications
You must be signed in to change notification settings - Fork 0
/
smece
210 lines (197 loc) · 3.88 KB
/
smece
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//If node has more bodies, check if desired node exists.
//If it does, InsertToNode there, if not, create 4 subnodes,
//then insert to desired node.
if (NodeBodyCount > 1)
{
cout << size;
int asd;
int quad = GetQuad(NewBody);
switch (quad)
{
case 1 :
{
if (ne == NULL)
{
Vect neCent;
neCent.x = center.x + (size / 2.0);
neCent.y = center.y + (size / 2.0);
ne = new Node(neCent, (size / 2.0));
}
ne->InsertToNode(NewBody);
} break;
case 2 :
{
if (se == NULL)
{
Vect seCent;
seCent.x = center.x - (size / 2.0);
seCent.y = center.y + (size / 2.0);
se = new Node(seCent, (size / 2.0));
}
se->InsertToNode(NewBody);
} break;
case 3 :
{
if (nw == NULL)
{
Vect nwCent;
nwCent.x = center.x + (size / 2.0);
nwCent.y = center.y - (size / 2.0);
nw = new Node(nwCent, (size / 2.0));
}
nw->InsertToNode(NewBody);
} break;
case 4 :
{
if (sw == NULL)
{
Vect swCent;
swCent.x = center.x - (size / 2.0);
swCent.y = center.y - (size / 2.0);
sw = new Node(swCent, (size / 2.0));
}
sw->InsertToNode(NewBody);
} break;
}
}
else
{
//If node has one body, find it's new quadrant. If the new quadrant exists, place it there. If it doesn't,
//create it and place it there.
//Then take the new body and find it's own quadrant and check if it exists. If it does, place it there,
//if not, create it and place it there.
if (NodeBodyCount == 1)
{
int quad = GetQuad(NodeBody);
cout << size;
int asd;
cin >> asd;
switch (quad)
{
case 1 :
{
cout << "quad = 1" << endl;
if (ne == NULL)
{
cout << "InsertElse1 work pls" << endl;
Vect neCent;
neCent.x = center.x + (size / 2.0);
neCent.y = center.y + (size / 2.0);
ne = new Node(neCent, (size / 2.0));
ne->InsertToNode(NodeBody);
}
else
{
cout << "Wat" << endl;
ne->InsertToNode (NodeBody);
}
} break;
case 2 :
{
cout << "quad = 2" << endl;
if (se == NULL)
{
Vect seCent;
seCent.x = center.x - (size / 2.0);
seCent.y = center.y + (size / 2.0);
se = new Node(seCent, (size / 2.0));
se->InsertToNode (NodeBody);
}
else
{
se->InsertToNode (NodeBody);
}
} break;
case 3 :
{
cout << "quad = 3" << endl;
if (nw == NULL)
{
Vect nwCent;
nwCent.x = center.x + (size / 2.0);
nwCent.y = center.y - (size / 2.0);
nw = new Node(nwCent, (size / 2.0));
nw->InsertToNode(NodeBody);
}
else
{
nw->InsertToNode(NodeBody);
}
} break;
case 4 :
{
if (sw == NULL)
{
cout << "quad = 4" << endl;
Vect swCent;
swCent.x = center.x - (size / 2.0);
swCent.y = center.y - (size / 2.0);
sw = new Node(swCent, (size / 2.0));
sw->InsertToNode(NodeBody);
}
else
{
cout << "Ins" << endl;
sw->InsertToNode(NodeBody);
}
} break;
}
quad = GetQuad(NewBody);
switch (quad)
{
case 1 :
{
if (ne == NULL)
{
Vect neCent;
neCent.x = center.x + (size / 2.0);
neCent.y = center.y + (size / 2.0);
ne = new Node(neCent, (size / 2.0));
}
ne->InsertToNode(NewBody);
} break;
case 2 :
{
if (se == NULL)
{
Vect seCent;
seCent.x = center.x - (size / 2.0);
seCent.y = center.y + (size / 2.0);
se = new Node(seCent, (size / 2.0));
}
se->InsertToNode(NewBody);
} break;
case 3 :
{
if (nw == NULL)
{
Vect nwCent;
nwCent.x = center.x + (size / 2.0);
nwCent.y = center.y - (size / 2.0);
nw = new Node(nwCent, (size / 2.0));
}
nw->InsertToNode(NewBody);
} break;
case 4 :
{
if (sw == NULL)
{
Vect swCent;
swCent.x = center.x - (size / 2.0);
swCent.y = center.y - (size / 2.0);
sw = new Node(swCent, (size / 2.0));
}
sw->InsertToNode(NewBody);
} break;
}
}
//If the node is emtpy, store the new body as the Node Body
else
{
cout << "Lone Body" << endl;
cout << size;
int asd;
cin >> asd;
NodeBody = NewBody;
}
}