mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-21 18:00:16 +00:00
LibGfx: Add Rect::unite()
The existing `::unite_horizontally()` and `::unite_vertically()` tests did not properly test the edge cases where left/top in the Rect were updated, so they get re-arranged a bit.
This commit is contained in:
parent
c0e861e2fa
commit
7eb4f3da37
Notes:
github-actions[bot]
2025-01-23 08:34:31 +00:00
Author: https://github.com/gmta
Commit: 7eb4f3da37
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3276
Reviewed-by: https://github.com/kalenikaliaksandr ✅
7 changed files with 51 additions and 38 deletions
|
@ -835,6 +835,18 @@ public:
|
|||
return { { point.x() - size.width() / 2, point.y() - size.height() / 2 }, size };
|
||||
}
|
||||
|
||||
void unite(Rect<T> const& other)
|
||||
{
|
||||
if (is_empty()) {
|
||||
*this = other;
|
||||
return;
|
||||
}
|
||||
if (other.is_empty())
|
||||
return;
|
||||
unite_horizontally(other);
|
||||
unite_vertically(other);
|
||||
}
|
||||
|
||||
void unite_horizontally(Rect<T> const& other)
|
||||
{
|
||||
auto new_left = min(left(), other.left());
|
||||
|
@ -853,15 +865,8 @@ public:
|
|||
|
||||
[[nodiscard]] Rect<T> united(Rect<T> const& other) const
|
||||
{
|
||||
if (is_empty())
|
||||
return other;
|
||||
if (other.is_empty())
|
||||
return *this;
|
||||
Rect<T> rect;
|
||||
rect.set_left(min(left(), other.left()));
|
||||
rect.set_top(min(top(), other.top()));
|
||||
rect.set_right(max(right(), other.right()));
|
||||
rect.set_bottom(max(bottom(), other.bottom()));
|
||||
Rect<T> rect = *this;
|
||||
rect.unite(other);
|
||||
return rect;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue