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
|
int dfsArea(Rectangle * currentRect, int n, vector<Rectangle*> myvector, int & area, Rectangle * root){
currentRect->visited=true;
area+=(currentRect->x2-currentRect->x1)*(currentRect->y2-currentRect->y1);
if(currentRect->parent!=currentRect){
area-=(min(currentRect->x2, currentRect->parent->x2)-max(currentRect->x1, currentRect->parent->x1))*(min(currentRect->y2, currentRect->parent->y2)-max(currentRect->y1, currentRect->parent->y1));
}
// for each rect intersecting with currentRect
for(int k=0; k<n ; k++){
if(myvector[k]->visited==false && currentRect->x2 > myvector[k]->x1 && currentRect->x1 < myvector[k]->x2 && currentRect->y2 > myvector[k]->y1 && currentRect->y1 < myvector[k]->y2)
{
unionSets(currentRect, myvector[k]);
area+=dfsArea(myvector[k], n, myvector, area, root);
}
else if(find(myvector[k])==root && currentRect!=myvector[k]){ // &root?
area+=(currentRect->x2-currentRect->x1)*(currentRect->y2-currentRect->y1);
area-=(min(currentRect->x2, currentRect->parent->x2)-max(currentRect->x1, currentRect->parent->x1))*(min(currentRect->y2, currentRect->parent->y2)-max(currentRect->y1, currentRect->parent->y1));
area-=(min(currentRect->x2, myvector[k]->x2)-max(currentRect->x1, myvector[k]->x1))*(min(currentRect->y2, myvector[k]->y2)-max(currentRect->y1, myvector[k]->y1));
}
}
return area;
}
|