From ce188c9a9cec633fe2f1336ff8ca9aa35d560630 Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Tue, 8 Aug 2023 15:59:54 +0200 Subject: [PATCH] LibWeb: Allow direct rouding of CSSPixelRects to CSSPixelRects Preciously we were casting to float, round and cast back, which actually might loose precision and was quite ugly. --- .../Libraries/LibWeb/Painting/MarkerPaintable.cpp | 3 +-- Userland/Libraries/LibWeb/PixelUnits.h | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp b/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp index b2eed28f0f5..14e0f1eee74 100644 --- a/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/MarkerPaintable.cpp @@ -36,8 +36,7 @@ void MarkerPaintable::paint(PaintContext& context, PaintPhase phase) const if (phase != PaintPhase::Foreground) return; - // FIXME: All this does is round to the nearest whole CSS pixel, but it's goofy. - CSSPixelRect enclosing = absolute_rect().to_type().to_rounded().to_type(); + CSSPixelRect enclosing = absolute_rect().to_rounded(); auto device_enclosing = context.enclosing_device_rect(enclosing); CSSPixels marker_width = enclosing.height() / 2.0; diff --git a/Userland/Libraries/LibWeb/PixelUnits.h b/Userland/Libraries/LibWeb/PixelUnits.h index a0bac9313a7..a044b175a72 100644 --- a/Userland/Libraries/LibWeb/PixelUnits.h +++ b/Userland/Libraries/LibWeb/PixelUnits.h @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace Web { @@ -279,6 +280,18 @@ constexpr Web::DevicePixels abs(Web::DevicePixels const& value) return AK::abs(value.value()); } +template<> +template<> +[[nodiscard]] ALWAYS_INLINE Web::CSSPixelRect Web::CSSPixelRect::to_rounded() const +{ + return { + round(x()), + round(y()), + round(width()), + round(height()), + }; +} + namespace AK { template<>