From 7ed5c134059ac2279e35ad90d0639b7f4c7e3720 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Thu, 20 Feb 2014 15:36:59 -0500 Subject: [PATCH] Allow additional indexable types Instead of using operator() to index into the second operand of the VectorAddition function, use operator[]. This way we can add to pointers and std::vector types as well. --- Base/include/VectorBase.h | 4 ++-- Base/test/TestVector.cpp | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Base/include/VectorBase.h b/Base/include/VectorBase.h index 46bc194..c3df4b4 100644 --- a/Base/include/VectorBase.h +++ b/Base/include/VectorBase.h @@ -110,7 +110,7 @@ namespace FasTC { const VectorTypeTwo &v2) { VectorTypeOne a(v1); for(int i = 0; i < VectorTypeOne::Size; i++) { - a(i) += v2(i); + a(i) += v2[i]; } return a; } @@ -132,7 +132,7 @@ namespace FasTC { const VectorTypeTwo &v2) { VectorTypeOne a(v1); for(int i = 0; i < VectorTypeOne::Size; i++) { - a(i) -= v2(i); + a(i) -= v2[i]; } return a; } diff --git a/Base/test/TestVector.cpp b/Base/test/TestVector.cpp index f2f2f53..7735fdc 100644 --- a/Base/test/TestVector.cpp +++ b/Base/test/TestVector.cpp @@ -216,6 +216,10 @@ TEST(VectorBase, Addition) { EXPECT_EQ(au[0], 6); EXPECT_EQ(au[1], 5); + au = v2u + fv + uv; + EXPECT_EQ(au[0], 11); + EXPECT_EQ(au[1], 7); + FasTC::VectorBase af = v2f + v2u; EXPECT_NEAR(af[0], 6.1f, kEpsilon); EXPECT_NEAR(af[1], 5.2f, kEpsilon);