Sfoglia il codice sorgente

LibGfx: Add `VectorN::to_type<T>()`

Jelle Raaijmakers 3 anni fa
parent
commit
878111abf6
1 ha cambiato i file con 10 aggiunte e 0 eliminazioni
  1. 10 0
      Userland/Libraries/LibGfx/VectorN.h

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

@@ -224,6 +224,16 @@ public:
             return String::formatted("[{},{},{},{}]", x(), y(), z(), w());
     }
 
+    template<typename U>
+    [[nodiscard]] VectorN<N, U> to_type() const
+    {
+        VectorN<N, U> result;
+        UNROLL_LOOP
+        for (auto i = 0u; i < N; ++i)
+            result.data()[i] = static_cast<U>(m_data[i]);
+        return result;
+    }
+
     template<typename U>
     [[nodiscard]] VectorN<N, U> to_rounded() const
     {