diff --git a/lib/vectorwrapper/include/vectorwrapper/vectorwrapper.hpp b/lib/vectorwrapper/include/vectorwrapper/vectorwrapper.hpp index b41ebb7..98ab6fa 100644 --- a/lib/vectorwrapper/include/vectorwrapper/vectorwrapper.hpp +++ b/lib/vectorwrapper/include/vectorwrapper/vectorwrapper.hpp @@ -161,10 +161,10 @@ namespace vwr { template typename std::enable_if::value, V2>::type& cast ( void ); - template VecBase& operator+= ( const VecBase& parOther ); - template VecBase& operator-= ( const VecBase& parOther ); - template VecBase& operator*= ( const VecBase& parOther ); - template VecBase& operator/= ( const VecBase& parOther ); + template VecBase& operator+= ( const Vec& parOther ); + template VecBase& operator-= ( const Vec& parOther ); + template VecBase& operator*= ( const Vec& parOther ); + template VecBase& operator/= ( const Vec& parOther ); template VecBase& operator+= ( const T& parOther ); template VecBase& operator-= ( const T& parOther ); template VecBase& operator*= ( const T& parOther ); diff --git a/lib/vectorwrapper/include/vectorwrapper/vectorwrapper.inl b/lib/vectorwrapper/include/vectorwrapper/vectorwrapper.inl index 181d0da..143fdcf 100644 --- a/lib/vectorwrapper/include/vectorwrapper/vectorwrapper.inl +++ b/lib/vectorwrapper/include/vectorwrapper/vectorwrapper.inl @@ -97,7 +97,7 @@ namespace vwr { template template - VecBase& VecBase::operator+= (const VecBase& parOther) { + VecBase& VecBase::operator+= (const Vec& parOther) { static_assert(static_cast(VectorWrapperInfo::dimensions) == static_cast(VectorWrapperInfo::dimensions), "Dimensions mismatch"); for (int z = 0; z < VectorWrapperInfo::dimensions; ++z) { (*this)[z] += parOther[z]; @@ -106,7 +106,7 @@ namespace vwr { } template template - VecBase& VecBase::operator-= (const VecBase& parOther) { + VecBase& VecBase::operator-= (const Vec& parOther) { static_assert(static_cast(VectorWrapperInfo::dimensions) == static_cast(VectorWrapperInfo::dimensions), "Dimensions mismatch"); for (int z = 0; z < VectorWrapperInfo::dimensions; ++z) { (*this)[z] -= parOther[z]; @@ -115,7 +115,7 @@ namespace vwr { } template template - VecBase& VecBase::operator*= (const VecBase& parOther) { + VecBase& VecBase::operator*= (const Vec& parOther) { static_assert(static_cast(VectorWrapperInfo::dimensions) == static_cast(VectorWrapperInfo::dimensions), "Dimensions mismatch"); for (int z = 0; z < VectorWrapperInfo::dimensions; ++z) { (*this)[z] *= parOther[z]; @@ -124,7 +124,7 @@ namespace vwr { } template template - VecBase& VecBase::operator/= (const VecBase& parOther) { + VecBase& VecBase::operator/= (const Vec& parOther) { static_assert(static_cast(VectorWrapperInfo::dimensions) == static_cast(VectorWrapperInfo::dimensions), "Dimensions mismatch"); for (int z = 0; z < VectorWrapperInfo::dimensions; ++z) { (*this)[z] /= parOther[z]; diff --git a/test/unit/vector.cpp b/test/unit/vector.cpp index 0534f7b..7cc5898 100644 --- a/test/unit/vector.cpp +++ b/test/unit/vector.cpp @@ -3,8 +3,13 @@ TEST(misc, vector) { typedef dk::Vector<2> coords2; + typedef dk::Vector<3> coords3; typedef dk::Vector<8> coords8; + EXPECT_EQ(coords2::dimensions, 2); + EXPECT_EQ(coords3::dimensions, 3); + EXPECT_EQ(coords8::dimensions, 8); + { const coords2 small(5, 6); EXPECT_EQ(small.x(), 5); @@ -39,4 +44,16 @@ TEST(misc, vector) { EXPECT_LT(small, big); } + + { + coords3 vec(1, 2, 3); + vec += coords3(3, 2, 1); + EXPECT_EQ(vec, coords3(4)); + + vec *= 3; + EXPECT_EQ(vec, coords3(12)); + + vec = coords3(2, 4, 8) / 2; + EXPECT_EQ(vec, coords3(1, 2, 4)); + } }