ソースを参照

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.
Sam Atkins 3 年 前
コミット
0b7eefd4e5
1 ファイル変更5 行追加0 行削除
  1. 5 0
      Userland/Libraries/LibGfx/Rect.h

+ 5 - 0
Userland/Libraries/LibGfx/Rect.h

@@ -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 {