vector<Unit> query(Rectangle &range, vector<Unit> &found) {
if (!Boundary.Intersects(range)) {
return found;
}
else {
for (size_t i = 0; i < Points.size(); i++) {
if (range.Contains(Points[i])) {
found.push_back(Points[i]);
}
}
if (NorthWest == nullptr) {
return found;
}
if (Divided) {
vector <Unit> NWfound = NorthWest->query(range,found);
//found.insert(found.end(), NWfound.begin(), NWfound.end());
vector <Unit> NEfound = NorthEast->query(range,found);
//found.insert(found.end(), NEfound.begin(), NEfound.end());
vector <Unit> SWfound = SouthWest->query(range,found);
//found.insert(found.end(), SWfound.begin(), SWfound.end());
vector <Unit> SEfound = SouthEast->query(range,found);
//found.insert(found.end(), SEfound.begin(), SEfound.end());
}
}
return found;
}
vector<Unit> unitInRangeView;
quadTree.query(range, unitInRangeView);//Все юниты,которые находятся в радиусе обзора юнита
vector<Unit> query(Rectangle range, vector<Unit> found = vector<Unit>(0)) {
if (!Boundary.Intersects(range)) {
return found;
}
else {
for (size_t i = 0; i < Points.size(); i++) {
if (range.Contains(Points[i])) {
found.push_back(Points[i]);
}
}
if (NorthWest == nullptr) {
return found;
}
if (Divided) {
vector <Unit> NWfound = NorthWest->query(range,found);
//found.insert(found.end(), NWfound.begin(), NWfound.end());
vector <Unit> NEfound = NorthEast->query(range,found);
//found.insert(found.end(), NEfound.begin(), NEfound.end());
vector <Unit> SWfound = SouthWest->query(range,found);
//found.insert(found.end(), SWfound.begin(), SWfound.end());
vector <Unit> SEfound = SouthEast->query(range,found);
//found.insert(found.end(), SEfound.begin(), SEfound.end());
}
}
return found;
}
};