1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:57:44 +00:00

LibGfx: Add Rect::unite_{horizontally,vertically}()

These functions unite the rect with another rect, but only in one axis.
This commit is contained in:
Andreas Kling 2023-07-12 15:39:33 +02:00
parent 7af7e90e3f
commit d620dd516c
2 changed files with 42 additions and 0 deletions

View file

@ -870,6 +870,22 @@ public:
return { { point.x() - size.width() / 2, point.y() - size.height() / 2 }, size };
}
void unite_horizontally(Rect<T> const& other)
{
auto new_left = min(left(), other.left());
auto new_right = max(right(), other.right());
set_left(new_left);
set_right(new_right);
}
void unite_vertically(Rect<T> const& other)
{
auto new_top = min(top(), other.top());
auto new_bottom = max(bottom(), other.bottom());
set_top(new_top);
set_bottom(new_bottom);
}
[[nodiscard]] Rect<T> united(Rect<T> const& other) const
{
if (is_empty())