Fix vector operators to avoid needing overloads

This commit is contained in:
Pavel Krajcevski 2014-02-17 13:02:43 -05:00
parent 0875ee0ddb
commit 4fc75f22dc
2 changed files with 8 additions and 43 deletions

View File

@ -159,41 +159,6 @@ class Pixel : public Vector4<uint16> {
}; };
REGISTER_VECTOR_TYPE(Pixel); REGISTER_VECTOR_TYPE(Pixel);
// Overload operators so that we can preserve bit depths...
template<typename ScalarType>
static inline Pixel ScalarMultiply(const Pixel &p, const ScalarType &s) {
Pixel a(p);
for(int i = 0; i < Pixel::Size; i++)
a(i) = p(i) * s;
return a;
}
template<typename ScalarType>
static inline Pixel ScalarDivide(const Pixel &p, const ScalarType &s) {
Pixel a(p);
for(int i = 0; i < Pixel::Size; i++)
a(i) = p(i) / s;
return a;
}
template<typename VectorType>
static inline Pixel VectorAddition(const Pixel &p, const VectorType &v) {
Pixel a(p);
for(int i = 0; i < Pixel::Size; i++) {
a(i) += v(i);
}
return a;
}
template<typename VectorType>
static inline Pixel VectorSubtraction(const Pixel &p, const VectorType &v) {
Pixel a(p);
for(int i = 0; i < Pixel::Size; i++) {
a(i) -= v(i);
}
return a;
}
} // namespace FasTC } // namespace FasTC
#endif // BASE_INCLUDE_PIXEL_H_ #endif // BASE_INCLUDE_PIXEL_H_

View File

@ -102,9 +102,9 @@ namespace FasTC {
template<typename VectorTypeOne, typename VectorTypeTwo> template<typename VectorTypeOne, typename VectorTypeTwo>
static inline VectorTypeOne VectorAddition(const VectorTypeOne &v1, static inline VectorTypeOne VectorAddition(const VectorTypeOne &v1,
const VectorTypeTwo &v2) { const VectorTypeTwo &v2) {
VectorTypeOne a; VectorTypeOne a(v1);
for(int i = 0; i < VectorTypeOne::Size; i++) { for(int i = 0; i < VectorTypeOne::Size; i++) {
a(i) = v1(i) + v2(i); a(i) += v2(i);
} }
return a; return a;
} }
@ -124,9 +124,9 @@ namespace FasTC {
template<typename VectorTypeOne, typename VectorTypeTwo> template<typename VectorTypeOne, typename VectorTypeTwo>
static inline VectorTypeOne VectorSubtraction(const VectorTypeOne &v1, static inline VectorTypeOne VectorSubtraction(const VectorTypeOne &v1,
const VectorTypeTwo &v2) { const VectorTypeTwo &v2) {
VectorTypeOne a; VectorTypeOne a(v1);
for(int i = 0; i < VectorTypeOne::Size; i++) { for(int i = 0; i < VectorTypeOne::Size; i++) {
a(i) = v1(i) - v2(i); a(i) -= v2(i);
} }
return a; return a;
} }
@ -204,9 +204,9 @@ namespace FasTC {
template<typename VectorType, typename ScalarType> template<typename VectorType, typename ScalarType>
static inline VectorType ScalarMultiply(const VectorType &v, const ScalarType &s) { static inline VectorType ScalarMultiply(const VectorType &v, const ScalarType &s) {
VectorType a; VectorType a(v);
for(int i = 0; i < VectorType::Size; i++) for(int i = 0; i < VectorType::Size; i++)
a(i) = static_cast<typename VectorType::ScalarType>(v(i) * s); a(i) *= static_cast<typename VectorType::ScalarType>(s);
return a; return a;
} }
@ -221,9 +221,9 @@ namespace FasTC {
template<typename VectorType, typename ScalarType> template<typename VectorType, typename ScalarType>
static inline VectorType ScalarDivide(const VectorType &v, const ScalarType &s) { static inline VectorType ScalarDivide(const VectorType &v, const ScalarType &s) {
VectorType a; VectorType a(v);
for(int i = 0; i < VectorType::Size; i++) for(int i = 0; i < VectorType::Size; i++)
a(i) = static_cast<typename VectorType::ScalarType>(v(i) / s); a(i) /= static_cast<typename VectorType::ScalarType>(s);
return a; return a;
} }