diff --git a/libs/math/Vector4.h b/libs/math/Vector4.h index 8cd2ade20f..a57208798d 100644 --- a/libs/math/Vector4.h +++ b/libs/math/Vector4.h @@ -100,28 +100,6 @@ class BasicVector4 return !(*this == other); } - /* Define the addition operators + and += with any other BasicVector4 of type OtherElement - * The vectors are added to each other element-wise - */ - template - BasicVector4 operator+ (const BasicVector4& other) const { - return BasicVector4( - _v[0] + static_cast(other.x()), - _v[1] + static_cast(other.y()), - _v[2] + static_cast(other.z()), - _v[3] + static_cast(other.w()) - ); - } - - template - BasicVector4& operator+= (const BasicVector4& other) { - _v[0] += static_cast(other.x()); - _v[1] += static_cast(other.y()); - _v[2] += static_cast(other.z()); - _v[3] += static_cast(other.w()); - return *this; - } - /* Define the substraction operators - and -= with any other BasicVector4 of type OtherElement * The vectors are substracted from each other element-wise */ @@ -278,6 +256,26 @@ class BasicVector4 } }; // BasicVector4 +/// Componentwise addition of two vectors +template +BasicVector4 operator+(const BasicVector4& v1, const BasicVector4& v2) +{ + return BasicVector4(v1.x() + v2.x(), + v1.y() + v2.y(), + v1.z() + v2.z(), + v1.w() + v2.w()); +} + +template +BasicVector4& operator+=(BasicVector4& v1, const BasicVector4& v2) +{ + v1.x() += v2.x(); + v1.y() += v2.y(); + v1.z() += v2.z(); + v1.w() += v2.w(); + return v1; +} + /// Multiply BasicVector4 with a scalar template < typename T, typename S,