diff options
author | rtk0c <[email protected]> | 2022-06-30 21:38:53 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-30 21:38:53 -0700 |
commit | 7fe47a9d5b1727a61dc724523b530762f6d6ba19 (patch) | |
tree | e95be6e66db504ed06d00b72c579565bab873277 /app/source/Cplt/Utils/Vector.hpp | |
parent | 2cf952088d375ac8b2f45b144462af0953436cff (diff) |
Restructure project
Diffstat (limited to 'app/source/Cplt/Utils/Vector.hpp')
-rw-r--r-- | app/source/Cplt/Utils/Vector.hpp | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/app/source/Cplt/Utils/Vector.hpp b/app/source/Cplt/Utils/Vector.hpp new file mode 100644 index 0000000..79f4ea2 --- /dev/null +++ b/app/source/Cplt/Utils/Vector.hpp @@ -0,0 +1,144 @@ +#pragma once + +#include <Cplt/Utils/IO/DataStream.hpp> + +template <class T> +struct Vec2 +{ + T x = 0; + T y = 0; + + template <class TTarget> + Vec2<TTarget> Cast() const + { + return { + static_cast<TTarget>(x), + static_cast<TTarget>(y), + }; + } + + void ReadFromDataStream(InputDataStream& stream) + { + stream.Value(x); + stream.Value(y); + } + + void WriteToDataStream(OutputDataStream& stream) const + { + stream.Value(x); + stream.Value(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 }; } + friend constexpr Vec2 operator-(const Vec2& a, const Vec2& b) { return { a.x - b.x, a.y - b.y }; } + friend constexpr Vec2 operator*(const Vec2& a, const Vec2& b) { return { a.x * b.x, a.y * b.y }; } + friend constexpr Vec2 operator/(const Vec2& a, const Vec2& b) { return { a.x / b.x, a.y / b.y }; } + + friend constexpr Vec2 operator+(const Vec2& a, T n) { return { a.x + n, a.y + n }; } + friend constexpr Vec2 operator-(const Vec2& a, T n) { return { a.x - n, a.y - n }; } + friend constexpr Vec2 operator*(const Vec2& a, T n) { return { a.x * n, a.y * n }; } + friend constexpr Vec2 operator/(const Vec2& a, T n) { return { a.x / n, a.y / n }; } +}; + +using Vec2i = Vec2<int>; +using Vec2f = Vec2<float>; + +template <class T> +struct Vec3 +{ + T x = 0; + 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), + }; + } + + void ReadFromDataStream(InputDataStream& stream) + { + stream.Value(x); + stream.Value(y); + stream.Value(z); + } + + void WriteToDataStream(OutputDataStream& stream) const + { + stream.Value(x); + stream.Value(y); + stream.Value(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 }; } + friend constexpr Vec3 operator-(const Vec3& a, const Vec3& b) { return { a.x - b.x, a.y - b.y, a.z - b.z }; } + friend constexpr Vec3 operator*(const Vec3& a, const Vec3& b) { return { a.x * b.x, a.y * b.y, a.z * b.z }; } + friend constexpr Vec3 operator/(const Vec3& a, const Vec3& b) { return { a.x / b.x, a.y / b.y, a.z / b.z }; } + + friend constexpr Vec3 operator+(const Vec3& a, T n) { return { a.x + n, a.y + n, a.z + n }; } + friend constexpr Vec3 operator-(const Vec3& a, T n) { return { a.x - n, a.y - n, a.z - n }; } + friend constexpr Vec3 operator*(const Vec3& a, T n) { return { a.x * n, a.y * n, a.z * n }; } + friend constexpr Vec3 operator/(const Vec3& a, T n) { return { a.x / n, a.y / n, a.z / n }; } +}; + +using Vec3i = Vec3<int>; +using Vec3f = Vec3<float>; + +template <class T> +struct Vec4 +{ + T x = 0; + T y = 0; + 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), + }; + } + + void ReadFromDataStream(InputDataStream& stream) + { + stream.Value(x); + stream.Value(y); + stream.Value(z); + stream.Value(w); + } + + void WriteToDataStream(OutputDataStream& stream) const + { + stream.Value(x); + stream.Value(y); + stream.Value(z); + stream.Value(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 }; } + 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 }; } + 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 }; } + 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 }; } + + friend constexpr Vec4 operator+(const Vec4& a, T n) { return { a.x + n, a.y + n, a.z + n, a.w + n }; } + friend constexpr Vec4 operator-(const Vec4& a, T n) { return { a.x - n, a.y - n, a.z - n, a.w - n }; } + friend constexpr Vec4 operator*(const Vec4& a, T n) { return { a.x * n, a.y * n, a.z * n, a.w * n }; } + friend constexpr Vec4 operator/(const Vec4& a, T n) { return { a.x / n, a.y / n, a.z / n, a.w / n }; } +}; + +using Vec4i = Vec4<int>; +using Vec4f = Vec4<float>; |