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:
parent
7b7ba38655
commit
af161a8b83
58 changed files with 693 additions and 692 deletions
10
AK/Math.h
10
AK/Math.h
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue