sdl/rect: Add contains(rect) overload to check for contained subrect

This commit is contained in:
Tommy 2022-07-03 18:12:33 +12:00
parent 65515848ef
commit 635bdd8c3e
2 changed files with 13 additions and 2 deletions

View File

@ -62,10 +62,18 @@ bool rect::contains(const point& point) const
return SDL_PointInRect(&point, this) != SDL_FALSE;
}
bool rect::contains(const SDL_Rect& r) const
{
if(this->x > r.x) return false;
if(this->y > r.y) return false;
if(this->x + this->w < r.x + r.w) return false;
if(this->y + this->h < r.y + r.h) return false;
return true;
}
bool rect::overlaps(const SDL_Rect& r) const
{
return (r.x < x + w && x < r.x + r.w &&
r.y < y + h && y < r.y + r.h);
return SDL_HasIntersection(this, &r);
}
rect rect::minimal_cover(const SDL_Rect& other) const

View File

@ -77,6 +77,9 @@ public:
bool contains(int x, int y) const;
bool contains(const point& p) const;
/** Whether the given rectangle is completely contained by this one. */
bool contains(const SDL_Rect& r) const;
/** Whether the given rectangle and this rectangle overlap. */
bool overlaps(const SDL_Rect& r) const;