From 4fc75f22dc268cb624970ff2421fe26c3bd6e517 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Mon, 17 Feb 2014 13:02:43 -0500 Subject: [PATCH] Fix vector operators to avoid needing overloads --- Base/include/Pixel.h | 35 ----------------------------------- Base/include/VectorBase.h | 16 ++++++++-------- 2 files changed, 8 insertions(+), 43 deletions(-) diff --git a/Base/include/Pixel.h b/Base/include/Pixel.h index 1f6afe2..31833b9 100644 --- a/Base/include/Pixel.h +++ b/Base/include/Pixel.h @@ -159,41 +159,6 @@ class Pixel : public Vector4 { }; REGISTER_VECTOR_TYPE(Pixel); -// Overload operators so that we can preserve bit depths... -template -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 -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 -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 -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 #endif // BASE_INCLUDE_PIXEL_H_ diff --git a/Base/include/VectorBase.h b/Base/include/VectorBase.h index e682377..f1d9413 100644 --- a/Base/include/VectorBase.h +++ b/Base/include/VectorBase.h @@ -102,9 +102,9 @@ namespace FasTC { template static inline VectorTypeOne VectorAddition(const VectorTypeOne &v1, const VectorTypeTwo &v2) { - VectorTypeOne a; + VectorTypeOne a(v1); for(int i = 0; i < VectorTypeOne::Size; i++) { - a(i) = v1(i) + v2(i); + a(i) += v2(i); } return a; } @@ -124,9 +124,9 @@ namespace FasTC { template static inline VectorTypeOne VectorSubtraction(const VectorTypeOne &v1, const VectorTypeTwo &v2) { - VectorTypeOne a; + VectorTypeOne a(v1); for(int i = 0; i < VectorTypeOne::Size; i++) { - a(i) = v1(i) - v2(i); + a(i) -= v2(i); } return a; } @@ -204,9 +204,9 @@ namespace FasTC { template static inline VectorType ScalarMultiply(const VectorType &v, const ScalarType &s) { - VectorType a; + VectorType a(v); for(int i = 0; i < VectorType::Size; i++) - a(i) = static_cast(v(i) * s); + a(i) *= static_cast(s); return a; } @@ -221,9 +221,9 @@ namespace FasTC { template static inline VectorType ScalarDivide(const VectorType &v, const ScalarType &s) { - VectorType a; + VectorType a(v); for(int i = 0; i < VectorType::Size; i++) - a(i) = static_cast(v(i) / s); + a(i) /= static_cast(s); return a; }