mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-12 15:11:26 +00:00
Add get_rect_union() for future usage.
This commit is contained in:
parent
463d153779
commit
f1c73760c9
@ -83,6 +83,29 @@ SDL_Rect intersect_rects(SDL_Rect const &rect1, SDL_Rect const &rect2)
|
||||
return res;
|
||||
}
|
||||
|
||||
SDL_Rect get_rect_union(const SDL_Rect& rect1, const SDL_Rect& 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 };
|
||||
|
@ -57,6 +57,16 @@ bool point_in_rect(int x, int y, const SDL_Rect& rect);
|
||||
bool rects_overlap(const SDL_Rect& rect1, const SDL_Rect& rect2);
|
||||
SDL_Rect intersect_rects(SDL_Rect const &rect1, SDL_Rect const &rect2);
|
||||
|
||||
/**
|
||||
* Returns the union of two rectangles.
|
||||
*
|
||||
* @param rect1 The first rectangle.
|
||||
* @param rect2 The second rectangle.
|
||||
*
|
||||
* @returns The union of rect1 and rect2.
|
||||
*/
|
||||
SDL_Rect get_rect_union(const SDL_Rect& rect1, const SDL_Rect& rect2);
|
||||
|
||||
/**
|
||||
* Creates an empty SDL_Rect.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user