diff --git a/Base/include/VectorBase.h b/Base/include/VectorBase.h index f1d9413..596df02 100644 --- a/Base/include/VectorBase.h +++ b/Base/include/VectorBase.h @@ -206,7 +206,7 @@ namespace FasTC { static inline VectorType ScalarMultiply(const VectorType &v, const ScalarType &s) { VectorType a(v); for(int i = 0; i < VectorType::Size; i++) - a(i) *= static_cast(s); + a(i) = static_cast(a(i) * s); return a; } @@ -223,7 +223,7 @@ namespace FasTC { static inline VectorType ScalarDivide(const VectorType &v, const ScalarType &s) { VectorType a(v); for(int i = 0; i < VectorType::Size; i++) - a(i) /= static_cast(s); + a(i) = static_cast(a(i) / s); return a; } diff --git a/Base/test/TestVector.cpp b/Base/test/TestVector.cpp index f8173a9..e6637e1 100644 --- a/Base/test/TestVector.cpp +++ b/Base/test/TestVector.cpp @@ -190,16 +190,26 @@ TEST(VectorBase, Scaling) { v2fd = v2f / 3; EXPECT_NEAR(v2fd[0], 1.0f / 3.0f, kEpsilon); EXPECT_NEAR(v2fd[1], 1.0f, kEpsilon); + + unsigned uv[2] = {1, 3}; + FasTC::VectorBase v2u (uv); + FasTC::VectorBase v2ud = v2u * 0.5; + EXPECT_EQ(v2ud[0], 0); + EXPECT_EQ(v2ud[1], 1); + + v2ud = v2u / 0.5f; + EXPECT_EQ(v2ud[0], 2); + EXPECT_EQ(v2ud[1], 6); } TEST(VectorBase, Addition) { float fv[2] = {1.1f, 3.2f}; FasTC::VectorBase v2f (fv); - unsigned uv[2] = {5, 2}; - FasTC::VectorBase v2u (uv); + int uv[2] = {5, 2}; + FasTC::VectorBase v2u (uv); - FasTC::VectorBase au = v2u + v2f; + FasTC::VectorBase au = v2u + v2f; EXPECT_EQ(au[0], 6); EXPECT_EQ(au[1], 5); @@ -209,7 +219,7 @@ TEST(VectorBase, Addition) { au = v2u - v2f; EXPECT_EQ(au[0], 3); - EXPECT_EQ(au[1], 0); + EXPECT_EQ(au[1], -1); af = v2f - v2u; EXPECT_NEAR(af[0], -3.9f, kEpsilon);