Browse Source

Vector function and operator reimplementation also for Color.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
357b744d59
  1. 10
      src/Color.h
  2. 32
      src/Math/RectangularMatrix.h
  3. 30
      src/Math/Vector.h

10
src/Color.h

@ -276,8 +276,13 @@ template<class T> class Color3: public Math::Vector3<T> {
inline constexpr FloatingPointType value() const {
return Implementation::value<T>(*this);
}
MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Color3, 3)
MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 3, Color3<T>)
};
MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Color3, 3)
/**
@brief Four-component (RGBA) color
@ -394,8 +399,13 @@ template<class T> class Color4: public Math::Vector4<T> {
inline constexpr FloatingPointType value() const {
return Implementation::value<T>(rgb());
}
MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(Color4, 4)
MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(1, 4, Color4<T>)
};
MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Color4, 4)
/** @debugoperator{Magnum::Color3} */
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Color3<T>& value) {
return debug << static_cast<const Magnum::Math::Vector3<T>&>(value);

32
src/Math/RectangularMatrix.h

@ -369,42 +369,42 @@ template<size_t cols, size_t rows, class T> Corrade::Utility::Debug operator<<(C
inline constexpr static const __VA_ARGS__& from(const T* data) { \
return *reinterpret_cast<const __VA_ARGS__*>(data); \
} \
template<class ...U> inline constexpr static __VA_ARGS__ from(const Vector<rows, T>& first, const U&... next) { \
return RectangularMatrix<cols, rows, T>::from(first, next...); \
template<class ...U> inline constexpr static __VA_ARGS__ from(const Math::Vector<rows, T>& first, const U&... next) { \
return Math::RectangularMatrix<cols, rows, T>::from(first, next...); \
} \
\
inline __VA_ARGS__& operator=(const RectangularMatrix<cols, rows, T>& other) { \
RectangularMatrix<cols, rows, T>::operator=(other); \
inline __VA_ARGS__& operator=(const Math::RectangularMatrix<cols, rows, T>& other) { \
Math::RectangularMatrix<cols, rows, T>::operator=(other); \
return *this; \
}
#define MAGNUM_RECTANGULARMATRIX_SUBCLASS_OPERATOR_IMPLEMENTATION(cols, rows, ...) \
inline __VA_ARGS__ operator+(const RectangularMatrix<cols, rows, T>& other) const { \
return RectangularMatrix<cols, rows, T>::operator+(other); \
inline __VA_ARGS__ operator+(const Math::RectangularMatrix<cols, rows, T>& other) const { \
return Math::RectangularMatrix<cols, rows, T>::operator+(other); \
} \
inline __VA_ARGS__& operator+=(const RectangularMatrix<cols, rows, T>& other) { \
RectangularMatrix<cols, rows, T>::operator+=(other); \
inline __VA_ARGS__& operator+=(const Math::RectangularMatrix<cols, rows, T>& other) { \
Math::RectangularMatrix<cols, rows, T>::operator+=(other); \
return *this; \
} \
inline __VA_ARGS__ operator-(const RectangularMatrix<cols, rows, T>& other) const { \
return RectangularMatrix<cols, rows, T>::operator-(other); \
inline __VA_ARGS__ operator-(const Math::RectangularMatrix<cols, rows, T>& other) const { \
return Math::RectangularMatrix<cols, rows, T>::operator-(other); \
} \
inline __VA_ARGS__& operator-=(const RectangularMatrix<cols, rows, T>& other) { \
RectangularMatrix<cols, rows, T>::operator-=(other); \
inline __VA_ARGS__& operator-=(const Math::RectangularMatrix<cols, rows, T>& other) { \
Math::RectangularMatrix<cols, rows, T>::operator-=(other); \
return *this; \
} \
template<class U> inline typename std::enable_if<std::is_arithmetic<U>::value, __VA_ARGS__>::type operator*(U number) const { \
return RectangularMatrix<cols, rows, T>::operator*(number); \
return Math::RectangularMatrix<cols, rows, T>::operator*(number); \
} \
template<class U> inline typename std::enable_if<std::is_arithmetic<U>::value, __VA_ARGS__&>::type operator*=(U number) { \
RectangularMatrix<cols, rows, T>::operator*=(number); \
Math::RectangularMatrix<cols, rows, T>::operator*=(number); \
return *this; \
} \
template<class U> inline typename std::enable_if<std::is_arithmetic<U>::value, __VA_ARGS__>::type operator/(U number) const { \
return RectangularMatrix<cols, rows, T>::operator/(number); \
return Math::RectangularMatrix<cols, rows, T>::operator/(number); \
} \
template<class U> inline typename std::enable_if<std::is_arithmetic<U>::value, __VA_ARGS__&>::type operator/=(U number) { \
RectangularMatrix<cols, rows, T>::operator/=(number); \
Math::RectangularMatrix<cols, rows, T>::operator/=(number); \
return *this; \
}
#endif

30
src/Math/Vector.h

@ -288,39 +288,39 @@ template<size_t size, class T> Corrade::Utility::Debug operator<<(Corrade::Utili
inline constexpr static const Type<T>& from(const T* data) { \
return *reinterpret_cast<const Type<T>*>(data); \
} \
template<class U> inline constexpr static Type<T> from(const Vector<size, U>& other) { \
return Vector<size, T>::from(other); \
template<class U> inline constexpr static Type<T> from(const Math::Vector<size, U>& other) { \
return Math::Vector<size, T>::from(other); \
} \
\
inline Type<T>& operator=(const Type<T>& other) { \
Vector<size, T>::operator=(other); \
Math::Vector<size, T>::operator=(other); \
return *this; \
} \
\
inline Type<T> operator*(const Vector<size, T>& other) const { \
return Vector<size, T>::operator*(other); \
inline Type<T> operator*(const Math::Vector<size, T>& other) const { \
return Math::Vector<size, T>::operator*(other); \
} \
inline Type<T>& operator*=(const Vector<size, T>& other) { \
Vector<size, T>::operator*=(other); \
inline Type<T>& operator*=(const Math::Vector<size, T>& other) { \
Math::Vector<size, T>::operator*=(other); \
return *this; \
} \
inline Type<T> operator/(const Vector<size, T>& other) const { \
return Vector<size, T>::operator/(other); \
inline Type<T> operator/(const Math::Vector<size, T>& other) const { \
return Math::Vector<size, T>::operator/(other); \
} \
inline Type<T>& operator/=(const Vector<size, T>& other) { \
Vector<size, T>::operator/=(other); \
inline Type<T>& operator/=(const Math::Vector<size, T>& other) { \
Math::Vector<size, T>::operator/=(other); \
return *this; \
} \
\
inline Type<T> operator-() const { return Vector<size, T>::operator-(); } \
inline Type<T> normalized() const { return Vector<size, T>::normalized(); }
inline Type<T> operator-() const { return Math::Vector<size, T>::operator-(); } \
inline Type<T> normalized() const { return Math::Vector<size, T>::normalized(); }
#define MAGNUM_VECTOR_SUBCLASS_OPERATOR_IMPLEMENTATION(Type, size) \
template<class T, class U> inline Type<T> operator*(U number, const Type<T>& vector) { \
return number*Vector<size, T>(vector); \
return number*Math::Vector<size, T>(vector); \
} \
template<class T, class U> inline Type<T> operator/(U number, const Type<T>& vector) { \
return number/Vector<size, T>(vector); \
return number/Math::Vector<size, T>(vector); \
}
#endif

Loading…
Cancel
Save