From 7fe47a9d5b1727a61dc724523b530762f6d6ba19 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Thu, 30 Jun 2022 21:38:53 -0700 Subject: Restructure project --- app/source/Cplt/Utils/Size.hpp | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 app/source/Cplt/Utils/Size.hpp (limited to 'app/source/Cplt/Utils/Size.hpp') 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 + +template +class Size2 { +public: + T width; + T height; + +public: + Size2() + : width{ 0 }, height{ 0 } { + } + + Size2(T width, T height) + : width{ width }, height{ height } { + } + + Size2(Vec2 vec) + : width{ vec.x }, height{ vec.y } + { + } + + operator Vec2() const + { + return { width, height }; + } + + Vec2 AsVec() const + { + return { width, height }; + } + + friend bool operator==(const Size2&, const Size2&) = default; + + template + Size2 Cast() const + { + return { + static_cast(width), + static_cast(height), + }; + } +}; + +template +Size2 operator+(Size2 a, Size2 b) { + return { a.width + b.width, a.height + b.height }; +} + +template +Size2 operator-(Size2 a, Size2 b) { + return { a.width - b.width, a.height - b.height }; +} + +template +auto operator*(Size2 a, N mult) -> Size2 { + return { a.width * mult, a.height * mult }; +} + +template +auto operator/(Size2 a, N mult) -> Size2 { + return { a.width / mult, a.height / mult }; +} -- cgit v1.2.3-70-g09d2