summaryrefslogtreecommitdiff
path: root/Size.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-05-26 15:31:12 -0700
committerrtk0c <[email protected]>2021-05-29 13:34:43 -0700
commitf957f4094a8d98ad0de294c3e6325ce9a860994e (patch)
treedb5caa6fbefa1699149e974448fd4dab6b2535b1 /Size.hpp
parenta611b22650d1e40593db4fb1bce29d925e49e932 (diff)
More work on TableTemplate
Diffstat (limited to 'Size.hpp')
-rwxr-xr-xSize.hpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/Size.hpp b/Size.hpp
new file mode 100755
index 0000000..f737f9c
--- /dev/null
+++ b/Size.hpp
@@ -0,0 +1,61 @@
+#pragma once
+
+#include <glm/glm.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(glm::vec<2, T> vec)
+ : width{ vec.x }, height{ vec.y } {
+ }
+
+ operator glm::vec<2, T>() const {
+ return { width, height };
+ }
+
+ glm::vec<2, 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 };
+}