LibGfx: Add rounded_int_rect() function for Rects

We were seeing a problem in LibWeb, where layout elements would be 1px
larger than they should be, due to layout positions using float values,
and then converting using `enclosing_int_rect()`. `rounded_int_rect()`
replaces that use, by maintaining the original rect's size.
This commit is contained in:
Sam Atkins 2021-09-21 15:32:18 +01:00 committed by Andreas Kling
parent 8817ea83d6
commit 0b7eefd4e5
Notes: sideshowbarker 2024-07-18 03:35:05 +09:00

View file

@ -715,6 +715,11 @@ using FloatRect = Rect<float>;
return Gfx::IntRect::from_two_points({ x1, y1 }, { x2, y2 });
}
[[nodiscard]] ALWAYS_INLINE IntRect rounded_int_rect(FloatRect const& float_rect)
{
return IntRect { floorf(float_rect.x()), floorf(float_rect.y()), roundf(float_rect.width()), roundf(float_rect.height()) };
}
}
namespace AK {