diff --git a/include/misc/Maths.h b/include/misc/Maths.h index edc0792..66f4c75 100644 --- a/include/misc/Maths.h +++ b/include/misc/Maths.h @@ -4,10 +4,9 @@ #include namespace td { -namespace maths { ////////////////////////////////////////////////////////////////// -// Vectors // +// Operators // ////////////////////////////////////////////////////////////////// template @@ -16,13 +15,18 @@ Vec2 operator+(const Vec2& vect, const Vec2& other) { } template -Vec3 operator- (const Vec3& vect) { - return { -vect.x, -vect.y, -vect.z }; +Vec2 operator- (const Vec2& vect) { + return { -vect.x, -vect.y }; } template -Vec4 operator- (const Vec4& vect) { - return { -vect.x, -vect.y, -vect.z, -vect.w }; +Vec2 operator- (const Vec2& vect, const Vec2& other) { + return vect + (-other); +} + +template +Vec3 operator- (const Vec3& vect) { + return { -vect.x, -vect.y, -vect.z }; } template @@ -35,6 +39,27 @@ Vec3 operator- (const Vec3& vect, const Vec3& other) { return vect + (-other); } +template +Vec4 operator- (const Vec4& vect) { + return { -vect.x, -vect.y, -vect.z, -vect.w }; +} + +template +Vec4 operator+ (const Vec4& vect, const Vec4& other) { + return { vect.x + other.x, vect.y + other.y, vect.z + other.y, vect.w + other.w }; +} + +template +Vec4 operator- (const Vec4& vect, const Vec4& other) { + return vect + (-other); +} + +////////////////////////////////////////////////////////////////// +// Vectors // +////////////////////////////////////////////////////////////////// + +namespace maths { + template T Length(const Vec3& vect) { return std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z);