1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:17:44 +00:00

AK+LibWeb: Round to int in clamp_to_int instead of truncating

This caused inaccuracies in float->CssPixel conversions
This commit is contained in:
Hendiadyoin1 2023-07-29 15:30:57 +02:00 committed by Alexander Kalenik
parent 7b7ba38655
commit af161a8b83
58 changed files with 693 additions and 692 deletions

View file

@ -1017,11 +1017,15 @@ constexpr T pow(T x, T y)
template<typename T>
constexpr int clamp_to_int(T value)
{
if (value >= NumericLimits<int>::max()) {
if (value >= NumericLimits<int>::max())
return NumericLimits<int>::max();
} else if (value <= NumericLimits<int>::min()) {
if (value <= NumericLimits<int>::min())
return NumericLimits<int>::min();
}
if constexpr (IsFloatingPoint<T>)
return round_to<int>(value);
return value;
}