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.
This commit is contained in:
parent
17b4109ba9
commit
ce188c9a9c
Notes:
sideshowbarker
2024-07-17 01:55:29 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/ce188c9a9c Pull-request: https://github.com/SerenityOS/serenity/pull/20427 Reviewed-by: https://github.com/MacDue Reviewed-by: https://github.com/kalenikaliaksandr ✅
2 changed files with 14 additions and 2 deletions
|
@ -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<float>().to_rounded<float>().to_type<CSSPixels>();
|
||||
CSSPixelRect enclosing = absolute_rect().to_rounded<CSSPixels>();
|
||||
auto device_enclosing = context.enclosing_device_rect(enclosing);
|
||||
|
||||
CSSPixels marker_width = enclosing.height() / 2.0;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <AK/Math.h>
|
||||
#include <AK/Traits.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <math.h>
|
||||
|
||||
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<Web::CSSPixels>() const
|
||||
{
|
||||
return {
|
||||
round(x()),
|
||||
round(y()),
|
||||
round(width()),
|
||||
round(height()),
|
||||
};
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<>
|
||||
|
|
Loading…
Add table
Reference in a new issue