diff options
author | rtk0c <[email protected]> | 2021-05-26 15:31:12 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-05-29 13:34:43 -0700 |
commit | f957f4094a8d98ad0de294c3e6325ce9a860994e (patch) | |
tree | db5caa6fbefa1699149e974448fd4dab6b2535b1 /core/src/Utils | |
parent | a611b22650d1e40593db4fb1bce29d925e49e932 (diff) |
More work on TableTemplate
Diffstat (limited to 'core/src/Utils')
-rwxr-xr-x | core/src/Utils/Size.hpp | 65 | ||||
-rw-r--r-- | core/src/Utils/Vector.hpp | 30 |
2 files changed, 95 insertions, 0 deletions
diff --git a/core/src/Utils/Size.hpp b/core/src/Utils/Size.hpp new file mode 100755 index 0000000..98be41a --- /dev/null +++ b/core/src/Utils/Size.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include "Utils/Vector.hpp" + +template <class T> +class Size2 { +public: + T width; + T height; + +public: + Size2() + : width{ 0 }, height{ 0 } { + } + + Size2(T width, T height) + : width{ width }, height{ height } { + } + + Size2(Vec2<T> vec) + : width{ vec.x }, height{ vec.y } + { + } + + operator Vec2<T>() const + { + return { width, height }; + } + + Vec2<T> AsVec() const + { + return { width, height }; + } + + friend bool operator==(const Size2<T>&, const Size2<T>&) = default; + + template <class TTarget> + Size2<TTarget> Cast() const + { + return { + static_cast<TTarget>(width), + static_cast<TTarget>(height), + }; + } +}; + +template <class T> +Size2<T> operator+(Size2<T> a, Size2<T> b) { + return { a.width + b.width, a.height + b.height }; +} + +template <class T> +Size2<T> operator-(Size2<T> a, Size2<T> b) { + return { a.width - b.width, a.height - b.height }; +} + +template <class T, class N> +auto operator*(Size2<T> a, N mult) -> Size2<decltype(a.width * mult)> { + return { a.width * mult, a.height * mult }; +} + +template <class T, class N> +auto operator/(Size2<T> a, N mult) -> Size2<decltype(a.width / mult)> { + return { a.width / mult, a.height / mult }; +} diff --git a/core/src/Utils/Vector.hpp b/core/src/Utils/Vector.hpp index f49965e..7e71b73 100644 --- a/core/src/Utils/Vector.hpp +++ b/core/src/Utils/Vector.hpp @@ -6,6 +6,15 @@ struct Vec2 T x = 0; T y = 0; + template <class TTarget> + Vec2<TTarget> Cast() const + { + return { + static_cast<TTarget>(x), + static_cast<TTarget>(y), + }; + } + friend constexpr bool operator==(const Vec2& a, const Vec2& b) = default; friend constexpr Vec2 operator+(const Vec2& a, const Vec2& b) { return { a.x + b.x, a.y + b.y }; } @@ -29,6 +38,16 @@ struct Vec3 T y = 0; T z = 0; + template <class TTarget> + Vec3<TTarget> Cast() const + { + return { + static_cast<TTarget>(x), + static_cast<TTarget>(y), + static_cast<TTarget>(z), + }; + } + friend constexpr bool operator==(const Vec3& a, const Vec3& b) = default; friend constexpr Vec3 operator+(const Vec3& a, const Vec3& b) { return { a.x + b.x, a.y + b.y, a.z + b.z }; } @@ -53,6 +72,17 @@ struct Vec4 T z = 0; T w = 0; + template <class TTarget> + Vec4<TTarget> Cast() const + { + return { + static_cast<TTarget>(x), + static_cast<TTarget>(y), + static_cast<TTarget>(z), + static_cast<TTarget>(w), + }; + } + friend constexpr bool operator==(const Vec4& a, const Vec4& b) = default; friend constexpr Vec4 operator+(const Vec4& a, const Vec4& b) { return { a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w }; } |