From 0d48cfe8c003095c6f47598accfdbb5a62c686f4 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 31 Jul 2023 00:22:56 -0700 Subject: [PATCH] fix: Nipoint3 Operator+= (#1172) * fix operator += * fix operator += --- dCommon/NiPoint3.cpp | 8 +++++--- dCommon/NiPoint3.h | 2 +- tests/dCommonTests/TestNiPoint3.cpp | 9 +++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/dCommon/NiPoint3.cpp b/dCommon/NiPoint3.cpp index b2ffa0d1..20780815 100644 --- a/dCommon/NiPoint3.cpp +++ b/dCommon/NiPoint3.cpp @@ -129,11 +129,13 @@ NiPoint3 NiPoint3::operator+(const NiPoint3& point) const { } //! Operator for addition of vectors -NiPoint3 NiPoint3::operator+=(const NiPoint3& point) const { - return NiPoint3(this->x + point.x, this->y + point.y, this->z + point.z); +NiPoint3& NiPoint3::operator+=(const NiPoint3& point) { + this->x += point.x; + this->y += point.y; + this->z += point.z; + return *this; } - //! Operator for subtraction of vectors NiPoint3 NiPoint3::operator-(const NiPoint3& point) const { return NiPoint3(this->x - point.x, this->y - point.y, this->z - point.z); diff --git a/dCommon/NiPoint3.h b/dCommon/NiPoint3.h index f76b9269..c956b654 100644 --- a/dCommon/NiPoint3.h +++ b/dCommon/NiPoint3.h @@ -136,7 +136,7 @@ public: NiPoint3 operator+(const NiPoint3& point) const; //! Operator for addition of vectors - NiPoint3 operator+=(const NiPoint3& point) const; + NiPoint3& operator+=(const NiPoint3& point); //! Operator for subtraction of vectors NiPoint3 operator-(const NiPoint3& point) const; diff --git a/tests/dCommonTests/TestNiPoint3.cpp b/tests/dCommonTests/TestNiPoint3.cpp index 33cd51d2..fbc98eb0 100644 --- a/tests/dCommonTests/TestNiPoint3.cpp +++ b/tests/dCommonTests/TestNiPoint3.cpp @@ -12,3 +12,12 @@ TEST(dCommonTests, NiPoint3Test) { // Check what unitize does to a vector of length 0 ASSERT_EQ(NiPoint3::ZERO.Unitize(), NiPoint3::ZERO); } + +TEST(dCommonTests, NiPoint3OperatorTest) { + NiPoint3 a(1, 2, 3); + NiPoint3 b(4, 5, 6); + a += b; + EXPECT_FLOAT_EQ(a.x, 5); + EXPECT_FLOAT_EQ(a.y, 7); + EXPECT_FLOAT_EQ(a.z, 9); +}