mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 10:18:13 +00:00
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
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
Add a link
Reference in a new issue