1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:17:35 +00:00

LibWeb: Use CSSPixels only when calculating radial gradient sizes

In order to do this, a function `sqrt(CSSPixels)` was added, which
currently just converts to floating point to run `AK::sqrt()`.
This commit is contained in:
Zaggy1024 2023-09-01 17:16:28 -05:00 committed by Alexander Kalenik
parent d9c842a83f
commit 883f44d397
4 changed files with 60 additions and 48 deletions

View file

@ -405,7 +405,7 @@ using DevicePixelSize = Gfx::Size<DevicePixels>;
}
inline Web::CSSPixels abs(Web::CSSPixels const& value)
constexpr Web::CSSPixels abs(Web::CSSPixels const& value)
{
return value.abs();
}
@ -430,11 +430,23 @@ constexpr Web::CSSPixels round(Web::CSSPixels const& value)
return ceil(value - Web::CSSPixels::from_raw(Web::CSSPixels::fixed_point_denominator >> 1 /* 0.5 */));
}
inline Web::CSSPixels sqrt(Web::CSSPixels const& value)
{
return Web::CSSPixels::nearest_value_for(AK::sqrt(value.to_float()));
}
constexpr Web::DevicePixels abs(Web::DevicePixels const& value)
{
return AK::abs(value.value());
}
constexpr Web::CSSPixels square_distance_between(Web::CSSPixelPoint const& a, Web::CSSPixelPoint const& b)
{
auto delta_x = abs(a.x() - b.x());
auto delta_y = abs(a.y() - b.y());
return delta_x * delta_x + delta_y * delta_y;
}
template<>
template<>
[[nodiscard]] ALWAYS_INLINE Web::CSSPixelRect Web::CSSPixelRect::to_rounded<Web::CSSPixels>() const