int QuadNode::getItemsInBounds(std::vector<QuadItem*>& itemvec, Bounds2D& bounds) { if(items.size()>0) { int items_added = 0; for(std::list<QuadItem*>::iterator it = items.begin(); it != items.end(); it++) { QuadItem* oi = (*it); itemvec.push_back(oi); items_added++; } return items_added; } if(children.size()==0) return 0; int count = 0; //for each 4 corners for(int i=0;i<4;i++) { if(!children[i]->empty() && bounds.overlaps(children[i]->bounds)) { count += children[i]->getItemsInBounds(itemvec, bounds); } } return count; }
int QuadNode::getItemsInBounds(std::set<QuadItem*>& itemset, Bounds2D& bounds) const{ if(!items.empty()) { int items_added = 0; for(std::list<QuadItem*>::const_iterator it = items.begin(); it != items.end(); it++) { QuadItem* oi = (*it); itemset.insert(oi); items_added++; } return items_added; } if(children.empty()) return 0; int count = 0; //for each 4 corners for(int i=0;i<4;i++) { if(!children[i]->empty() && bounds.overlaps(children[i]->bounds)) { count += children[i]->getItemsInBounds(itemset, bounds); } } return count; }
void QuadNode::visitItemsInBounds(const Bounds2D & bounds, VisitFunctor<QuadItem> & visit){ if(!items.empty()) { for(std::list<QuadItem*>::const_iterator it = items.begin(); it != items.end(); it++) visit(*it); }else if(!children.empty()){ //visit each corner for(int i=0;i<4;i++) if(!children[i]->empty() && bounds.overlaps(children[i]->bounds)) children[i]->visitItemsInBounds(bounds, visit); } }