diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h index 82534cae6f..9c6f63afaf 100644 --- a/Userland/Libraries/LibGfx/Rect.h +++ b/Userland/Libraries/LibGfx/Rect.h @@ -697,24 +697,46 @@ public: return Rect(*this); } - template + template [[nodiscard]] ALWAYS_INLINE Rect to_rounded() const { + // FIXME: We may get away with `rint[lf]?()` here. + // This would even give us some more control of these internals, + // while the break-tie algorithm does not really matter if constexpr (IsSame) { return { - static_cast(llroundf(x())), - static_cast(llroundf(y())), - static_cast(llroundf(width())), - static_cast(llroundf(height())), - }; - } else { - return { - static_cast(llroundd(x())), - static_cast(llroundd(y())), - static_cast(llroundd(width())), - static_cast(llroundd(height())), + static_cast(roundf(x())), + static_cast(roundf(y())), + static_cast(roundf(width())), + static_cast(roundf(height())), }; } + if constexpr (IsSame) { + return { + static_cast(round(x())), + static_cast(round(y())), + static_cast(round(width())), + static_cast(round(height())), + }; + } + + return { + static_cast(roundl(x())), + static_cast(roundl(y())), + static_cast(roundl(width())), + static_cast(roundl(height())), + }; + } + + template + ALWAYS_INLINE Rect to_rounded() const + { + return { + round_to(x()), + round_to(y()), + round_to(width()), + round_to(height()), + }; } [[nodiscard]] String to_string() const;