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.
This commit is contained in:
Pavel Krajcevski 2014-02-20 15:36:59 -05:00
parent 1b7691993d
commit 7ed5c13405
2 changed files with 6 additions and 2 deletions

View file

@ -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;
}

View file

@ -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<float, 2> af = v2f + v2u;
EXPECT_NEAR(af[0], 6.1f, kEpsilon);
EXPECT_NEAR(af[1], 5.2f, kEpsilon);