aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Utils/Size.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-06-30 21:38:53 -0700
committerrtk0c <[email protected]>2022-06-30 21:38:53 -0700
commit7fe47a9d5b1727a61dc724523b530762f6d6ba19 (patch)
treee95be6e66db504ed06d00b72c579565bab873277 /app/source/Cplt/Utils/Size.hpp
parent2cf952088d375ac8b2f45b144462af0953436cff (diff)
Restructure project
Diffstat (limited to 'app/source/Cplt/Utils/Size.hpp')
-rw-r--r--app/source/Cplt/Utils/Size.hpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/app/source/Cplt/Utils/Size.hpp b/app/source/Cplt/Utils/Size.hpp
new file mode 100644
index 0000000..ae38e8a
--- /dev/null
+++ b/app/source/Cplt/Utils/Size.hpp
@@ -0,0 +1,65 @@
+#pragma once
+
+#include <Cplt/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 };
+}