소스 검색

LibGfx: Implement `AK::min/max` for `Gfx::VectorN`

These return a new `Gfx::VectorN` with the minimum or maximum value of
each element.
Jelle Raaijmakers 1 년 전
부모
커밋
55668c3e48
1개의 변경된 파일24개의 추가작업 그리고 0개의 파일을 삭제
  1. 24 0
      Userland/Libraries/LibGfx/VectorN.h

+ 24 - 0
Userland/Libraries/LibGfx/VectorN.h

@@ -300,3 +300,27 @@ private:
 };
 
 }
+
+namespace AK {
+
+template<size_t N, typename T>
+constexpr Gfx::VectorN<N, T> min(Gfx::VectorN<N, T> const& a, Gfx::VectorN<N, T> const& b)
+{
+    Gfx::VectorN<N, T> result;
+    UNROLL_LOOP
+    for (auto i = 0u; i < N; ++i)
+        result[i] = min(a[i], b[i]);
+    return result;
+}
+
+template<size_t N, typename T>
+constexpr Gfx::VectorN<N, T> max(Gfx::VectorN<N, T> const& a, Gfx::VectorN<N, T> const& b)
+{
+    Gfx::VectorN<N, T> result;
+    UNROLL_LOOP
+    for (auto i = 0u; i < N; ++i)
+        result[i] = max(a[i], b[i]);
+    return result;
+}
+
+}