From 357b744d598e173548557bf3e528eea4bc53b1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 22 Aug 2012 13:56:48 +0200 Subject: [PATCH] Vector function and operator reimplementation also for Color. --- src/Color.h | 10 ++++++++++ src/Math/RectangularMatrix.h | 32 ++++++++++++++++---------------- src/Math/Vector.h | 30 +++++++++++++++--------------- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/Color.h b/src/Color.h index 125c820d2..304c5408e 100644 --- a/src/Color.h +++ b/src/Color.h @@ -276,8 +276,13 @@ template class Color3: public Math::Vector3 { inline constexpr FloatingPointType value() const { return Implementation::value(*this); } + + MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Color3, 3) + MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 3, Color3) }; +MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Color3, 3) + /** @brief Four-component (RGBA) color @@ -394,8 +399,13 @@ template class Color4: public Math::Vector4 { inline constexpr FloatingPointType value() const { return Implementation::value(rgb()); } + + MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Color4, 4) + MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 4, Color4) }; +MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Color4, 4) + /** @debugoperator{Magnum::Color3} */ template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Color3& value) { return debug << static_cast&>(value); diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 7d4d2c508..86293fc86 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -369,42 +369,42 @@ template Corrade::Utility::Debug operator<<(C inline constexpr static const __VA_ARGS__& from(const T* data) { \ return *reinterpret_cast(data); \ } \ - template inline constexpr static __VA_ARGS__ from(const Vector& first, const U&... next) { \ - return RectangularMatrix::from(first, next...); \ + template inline constexpr static __VA_ARGS__ from(const Math::Vector& first, const U&... next) { \ + return Math::RectangularMatrix::from(first, next...); \ } \ \ - inline __VA_ARGS__& operator=(const RectangularMatrix& other) { \ - RectangularMatrix::operator=(other); \ + inline __VA_ARGS__& operator=(const Math::RectangularMatrix& other) { \ + Math::RectangularMatrix::operator=(other); \ return *this; \ } #define MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(cols, rows, ...) \ - inline __VA_ARGS__ operator+(const RectangularMatrix& other) const { \ - return RectangularMatrix::operator+(other); \ + inline __VA_ARGS__ operator+(const Math::RectangularMatrix& other) const { \ + return Math::RectangularMatrix::operator+(other); \ } \ - inline __VA_ARGS__& operator+=(const RectangularMatrix& other) { \ - RectangularMatrix::operator+=(other); \ + inline __VA_ARGS__& operator+=(const Math::RectangularMatrix& other) { \ + Math::RectangularMatrix::operator+=(other); \ return *this; \ } \ - inline __VA_ARGS__ operator-(const RectangularMatrix& other) const { \ - return RectangularMatrix::operator-(other); \ + inline __VA_ARGS__ operator-(const Math::RectangularMatrix& other) const { \ + return Math::RectangularMatrix::operator-(other); \ } \ - inline __VA_ARGS__& operator-=(const RectangularMatrix& other) { \ - RectangularMatrix::operator-=(other); \ + inline __VA_ARGS__& operator-=(const Math::RectangularMatrix& other) { \ + Math::RectangularMatrix::operator-=(other); \ return *this; \ } \ template inline typename std::enable_if::value, __VA_ARGS__>::type operator*(U number) const { \ - return RectangularMatrix::operator*(number); \ + return Math::RectangularMatrix::operator*(number); \ } \ template inline typename std::enable_if::value, __VA_ARGS__&>::type operator*=(U number) { \ - RectangularMatrix::operator*=(number); \ + Math::RectangularMatrix::operator*=(number); \ return *this; \ } \ template inline typename std::enable_if::value, __VA_ARGS__>::type operator/(U number) const { \ - return RectangularMatrix::operator/(number); \ + return Math::RectangularMatrix::operator/(number); \ } \ template inline typename std::enable_if::value, __VA_ARGS__&>::type operator/=(U number) { \ - RectangularMatrix::operator/=(number); \ + Math::RectangularMatrix::operator/=(number); \ return *this; \ } #endif diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 8ed2949c1..728ce8029 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -288,39 +288,39 @@ template Corrade::Utility::Debug operator<<(Corrade::Utili inline constexpr static const Type& from(const T* data) { \ return *reinterpret_cast*>(data); \ } \ - template inline constexpr static Type from(const Vector& other) { \ - return Vector::from(other); \ + template inline constexpr static Type from(const Math::Vector& other) { \ + return Math::Vector::from(other); \ } \ \ inline Type& operator=(const Type& other) { \ - Vector::operator=(other); \ + Math::Vector::operator=(other); \ return *this; \ } \ \ - inline Type operator*(const Vector& other) const { \ - return Vector::operator*(other); \ + inline Type operator*(const Math::Vector& other) const { \ + return Math::Vector::operator*(other); \ } \ - inline Type& operator*=(const Vector& other) { \ - Vector::operator*=(other); \ + inline Type& operator*=(const Math::Vector& other) { \ + Math::Vector::operator*=(other); \ return *this; \ } \ - inline Type operator/(const Vector& other) const { \ - return Vector::operator/(other); \ + inline Type operator/(const Math::Vector& other) const { \ + return Math::Vector::operator/(other); \ } \ - inline Type& operator/=(const Vector& other) { \ - Vector::operator/=(other); \ + inline Type& operator/=(const Math::Vector& other) { \ + Math::Vector::operator/=(other); \ return *this; \ } \ \ - inline Type operator-() const { return Vector::operator-(); } \ - inline Type normalized() const { return Vector::normalized(); } + inline Type operator-() const { return Math::Vector::operator-(); } \ + inline Type normalized() const { return Math::Vector::normalized(); } #define MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Type, size) \ template inline Type operator*(U number, const Type& vector) { \ - return number*Vector(vector); \ + return number*Math::Vector(vector); \ } \ template inline Type operator/(U number, const Type& vector) { \ - return number/Vector(vector); \ + return number/Math::Vector(vector); \ } #endif