From 5fd49b9d9f01f2ea7083bf04e1e29b55c8d416fb Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Wed, 13 Apr 2022 21:55:07 +0200 Subject: [PATCH] LibGfx: Avoid some unnecessary Rounding in AffineTransform and Color Casts suffice in these cases. (Assuming standard rounding mode) --- Userland/Libraries/LibGfx/AffineTransform.cpp | 6 +++--- Userland/Libraries/LibGfx/Color.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibGfx/AffineTransform.cpp b/Userland/Libraries/LibGfx/AffineTransform.cpp index 3e33b4f718..70da1c749b 100644 --- a/Userland/Libraries/LibGfx/AffineTransform.cpp +++ b/Userland/Libraries/LibGfx/AffineTransform.cpp @@ -158,7 +158,7 @@ IntPoint AffineTransform::map(IntPoint const& point) const float mapped_x; float mapped_y; map(static_cast(point.x()), static_cast(point.y()), mapped_x, mapped_y); - return { roundf(mapped_x), roundf(mapped_y) }; + return { round_to(mapped_x), round_to(mapped_y) }; } template<> @@ -174,8 +174,8 @@ template<> IntSize AffineTransform::map(IntSize const& size) const { return { - roundf(static_cast(size.width()) * x_scale()), - roundf(static_cast(size.height()) * y_scale()), + round_to(static_cast(size.width()) * x_scale()), + round_to(static_cast(size.height()) * y_scale()), }; } diff --git a/Userland/Libraries/LibGfx/Color.h b/Userland/Libraries/LibGfx/Color.h index e4bc258c6d..67a18b9b5a 100644 --- a/Userland/Libraries/LibGfx/Color.h +++ b/Userland/Libraries/LibGfx/Color.h @@ -200,10 +200,10 @@ public: Color interpolate(Color const& other, float weight) const noexcept { - u8 r = red() + roundf(static_cast(other.red() - red()) * weight); - u8 g = green() + roundf(static_cast(other.green() - green()) * weight); - u8 b = blue() + roundf(static_cast(other.blue() - blue()) * weight); - u8 a = alpha() + roundf(static_cast(other.alpha() - alpha()) * weight); + u8 r = red() + round_to(static_cast(other.red() - red()) * weight); + u8 g = green() + round_to(static_cast(other.green() - green()) * weight); + u8 b = blue() + round_to(static_cast(other.blue() - blue()) * weight); + u8 a = alpha() + round_to(static_cast(other.alpha() - alpha()) * weight); return Color(r, g, b, a); }