diff options
author | Levi <L3ehunin@gmail.com> | 2021-01-11 06:09:56 +0100 |
---|---|---|
committer | Levi <L3ehunin@gmail.com> | 2021-01-11 06:09:56 +0100 |
commit | 7a3c884e39fccfbb498b855080bffabc9ce2e7f1 (patch) | |
tree | 5056f9406dec188439cb0deb87603498243a9412 /src/common/vector_math.h | |
parent | More forgetting... duh (diff) | |
parent | Merge pull request #5229 from Morph1984/fullscreen-opt (diff) | |
download | yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.gz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.bz2 yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.lz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.xz yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.zst yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.zip |
Diffstat (limited to 'src/common/vector_math.h')
-rw-r--r-- | src/common/vector_math.h | 75 |
1 files changed, 66 insertions, 9 deletions
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 2a0fcf541..22dba3c2d 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -87,7 +87,13 @@ public: template <typename V> [[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const { - return {x * f, y * f}; + using TV = decltype(T{} * V{}); + using C = std::common_type_t<T, V>; + + return { + static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), + static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), + }; } template <typename V> @@ -98,7 +104,13 @@ public: template <typename V> [[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const { - return {x / f, y / f}; + using TV = decltype(T{} / V{}); + using C = std::common_type_t<T, V>; + + return { + static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), + static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), + }; } template <typename V> @@ -168,7 +180,10 @@ public: template <typename T, typename V> [[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) { - return Vec2<T>(f * vec.x, f * vec.y); + using C = std::common_type_t<T, V>; + + return Vec2<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)), + static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y))); } using Vec2f = Vec2<float>; @@ -237,7 +252,14 @@ public: template <typename V> [[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const { - return {x * f, y * f, z * f}; + using TV = decltype(T{} * V{}); + using C = std::common_type_t<T, V>; + + return { + static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), + static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), + static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)), + }; } template <typename V> @@ -247,7 +269,14 @@ public: } template <typename V> [[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const { - return {x / f, y / f, z / f}; + using TV = decltype(T{} / V{}); + using C = std::common_type_t<T, V>; + + return { + static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), + static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), + static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)), + }; } template <typename V> @@ -367,7 +396,11 @@ public: template <typename T, typename V> [[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) { - return Vec3<T>(f * vec.x, f * vec.y, f * vec.z); + using C = std::common_type_t<T, V>; + + return Vec3<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)), + static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y)), + static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.z))); } template <> @@ -446,7 +479,15 @@ public: template <typename V> [[nodiscard]] constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const { - return {x * f, y * f, z * f, w * f}; + using TV = decltype(T{} * V{}); + using C = std::common_type_t<T, V>; + + return { + static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), + static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), + static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)), + static_cast<TV>(static_cast<C>(w) * static_cast<C>(f)), + }; } template <typename V> @@ -457,7 +498,15 @@ public: template <typename V> [[nodiscard]] constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const { - return {x / f, y / f, z / f, w / f}; + using TV = decltype(T{} / V{}); + using C = std::common_type_t<T, V>; + + return { + static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), + static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), + static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)), + static_cast<TV>(static_cast<C>(w) / static_cast<C>(f)), + }; } template <typename V> @@ -582,7 +631,15 @@ public: template <typename T, typename V> [[nodiscard]] constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) { - return {f * vec.x, f * vec.y, f * vec.z, f * vec.w}; + using TV = decltype(V{} * T{}); + using C = std::common_type_t<T, V>; + + return { + static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.x)), + static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.y)), + static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.z)), + static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.w)), + }; } using Vec4f = Vec4<float>; |