From 55668c3e48bbf23bf12ba2f17b33965e18522ade Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Thu, 15 Feb 2024 22:35:37 +0100 Subject: [PATCH] LibGfx: Implement `AK::min/max` for `Gfx::VectorN` These return a new `Gfx::VectorN` with the minimum or maximum value of each element. --- Userland/Libraries/LibGfx/VectorN.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Userland/Libraries/LibGfx/VectorN.h b/Userland/Libraries/LibGfx/VectorN.h index a2a5807c5c..7f6ad2a82d 100644 --- a/Userland/Libraries/LibGfx/VectorN.h +++ b/Userland/Libraries/LibGfx/VectorN.h @@ -300,3 +300,27 @@ private: }; } + +namespace AK { + +template +constexpr Gfx::VectorN min(Gfx::VectorN const& a, Gfx::VectorN const& b) +{ + Gfx::VectorN result; + UNROLL_LOOP + for (auto i = 0u; i < N; ++i) + result[i] = min(a[i], b[i]); + return result; +} + +template +constexpr Gfx::VectorN max(Gfx::VectorN const& a, Gfx::VectorN const& b) +{ + Gfx::VectorN result; + UNROLL_LOOP + for (auto i = 0u; i < N; ++i) + result[i] = max(a[i], b[i]); + return result; +} + +}