undo delete of get_rect_union

This commit is contained in:
Chris Hopman 2009-05-07 18:08:51 +00:00
parent 7c4c366713
commit 8bf8327563
2 changed files with 29 additions and 0 deletions

View file

@ -96,7 +96,27 @@ SDL_Rect union_rects(const SDL_Rect& rect1, const SDL_Rect& rect2)
return result;
}
SDL_Rect get_rect_union(SDL_Rect const &rect1, SDL_Rect const& rect2) {
const int left_side = std::max(rect1.x, rect2.x);
const int right_side = std::min(rect1.x + rect1.w, rect2.x + rect2.w);
if(left_side > right_side) {
return empty_rect;
}
const int top_side = std::max(rect1.y, rect2.y);
const int bottom_side = std::min(rect1.y + rect1.h, rect2.y + rect2.h);
if(top_side > bottom_side) {
return empty_rect;
}
SDL_Rect result = {
left_side,
top_side,
right_side - left_side,
bottom_side - top_side};
return result;
}
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
{
SDL_Rect rect = { x, y, w, h };

View file

@ -67,6 +67,15 @@ SDL_Rect intersect_rects(SDL_Rect const &rect1, SDL_Rect const &rect2);
*/
SDL_Rect union_rects(const SDL_Rect& rect1, const SDL_Rect& rect2);
/**
* Returns the intersection of two rectangles...
*
* @param rect1 The first rectangle.
* @param rect2 The second rectangle.
*
* @returns The intersection of the two rectangles
*/
SDL_Rect get_rect_union(const SDL_Rect& rect1, const SDL_Rect& rect2);
/**
* Creates an empty SDL_Rect.
*