diff --git a/tempest/vector/C3Vector.cpp b/tempest/vector/C3Vector.cpp index fb4dd33..ea08da7 100644 --- a/tempest/vector/C3Vector.cpp +++ b/tempest/vector/C3Vector.cpp @@ -20,3 +20,11 @@ void C3Vector::Normalize() { float C3Vector::SquaredMag() const { return this->x * this->x + this->y * this->y + this->z * this->z; } + +C3Vector operator+(const C3Vector& l, const C3Vector& r) { + float x = l.x + r.x; + float y = l.y + r.y; + float z = l.z + r.z; + + return { x, y, z }; +} diff --git a/tempest/vector/C3Vector.hpp b/tempest/vector/C3Vector.hpp index 2ae6c8d..2334ef9 100644 --- a/tempest/vector/C3Vector.hpp +++ b/tempest/vector/C3Vector.hpp @@ -20,4 +20,6 @@ class C3Vector { float SquaredMag() const; }; +C3Vector operator+(const C3Vector& l, const C3Vector& r); + #endif diff --git a/test/Vector.cpp b/test/Vector.cpp index 40c537e..2ab6b04 100644 --- a/test/Vector.cpp +++ b/test/Vector.cpp @@ -99,3 +99,14 @@ TEST_CASE("C3Vector::SquaredMag", "[vector]") { REQUIRE(vector.SquaredMag() == 3.0f); } } + +TEST_CASE("C3Vector global operators", "[vector]") { + SECTION("C3Vector + C3Vector") { + auto vector1 = C3Vector(1.0f, 2.0f, 3.0f); + auto vector2 = C3Vector(4.0f, 5.0f, 6.0f); + auto vector3 = vector1 + vector2; + REQUIRE(vector3.x == 5.0f); + REQUIRE(vector3.y == 7.0f); + REQUIRE(vector3.z == 9.0f); + } +}