From 0b7eefd4e5f297151ff4250ecc77bb8f64c3f63e Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 21 Sep 2021 15:32:18 +0100 Subject: [PATCH] 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. --- Userland/Libraries/LibGfx/Rect.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h index 502fc0d679..ab9370ffce 100644 --- a/Userland/Libraries/LibGfx/Rect.h +++ b/Userland/Libraries/LibGfx/Rect.h @@ -715,6 +715,11 @@ using FloatRect = Rect; 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 {