Vladimír Vondruš 13 years ago
parent
commit
e2180ee85b
  1. 17
      src/Array.h
  2. 15
      src/Color.h
  3. 19
      src/Math/RectangularMatrix.h
  4. 39
      src/Math/Vector.h

17
src/Array.h

@ -33,6 +33,10 @@
#include "Math/BoolVector.h" /* for Math::Implementation::Sequence */ #include "Math/BoolVector.h" /* for Math::Implementation::Sequence */
#include "Magnum.h" #include "Magnum.h"
#ifdef CORRADE_MSVC2013_COMPATIBILITY
#include <array>
#endif
namespace Magnum { namespace Magnum {
/** /**
@ -107,9 +111,18 @@ template<UnsignedInt dimensions, class T> class Array {
private: private:
/* Implementation for Array<dimensions, T>::Array(U) */ /* Implementation for Array<dimensions, T>::Array(U) */
template<std::size_t ...sequence> constexpr explicit Array(Math::Implementation::Sequence<sequence...>, T value): _data{Math::Implementation::repeat(value, sequence)...} {} template<std::size_t ...sequence> constexpr explicit Array(Math::Implementation::Sequence<sequence...>, T value):
#ifndef CORRADE_MSVC2013_COMPATIBILITY
_data{Math::Implementation::repeat(value, sequence)...} {}
#else
_data({Math::Implementation::repeat(value, sequence)...}) {}
#endif
#ifndef CORRADE_MSVC2013_COMPATIBILITY
T _data[dimensions]; T _data[dimensions];
#else
std::array<T, dimensions> _data;
#endif
}; };
/** /**

15
src/Color.h

@ -441,7 +441,12 @@ class BasicColor4: public Math::Vector4<T> {
* @param alpha Alpha value, defaults to 1.0 for floating-point types * @param alpha Alpha value, defaults to 1.0 for floating-point types
* and maximum positive value for integral types. * and maximum positive value for integral types.
*/ */
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr explicit BasicColor4(T rgb, T alpha = Implementation::fullChannel<T>()): Math::Vector4<T>(rgb, rgb, rgb, alpha) {} constexpr explicit BasicColor4(T rgb, T alpha = Implementation::fullChannel<T>()): Math::Vector4<T>(rgb, rgb, rgb, alpha) {}
#else
template<class U = T, class = typename std::enable_if<std::is_floating_point<T>::value, T>::type> constexpr explicit BasicColor4(T rgb, T alpha = T(1)): Math::Vector4<T>(rgb, rgb, rgb, alpha) {}
template<class U = T, class V = T, class = typename std::enable_if<std::is_integral<T>::value, T>::type> constexpr explicit BasicColor4(T rgb, T alpha = std::numeric_limits<T>::max()): Math::Vector4<T>(rgb, rgb, rgb, alpha) {}
#endif
/** /**
* @brief Constructor * @brief Constructor
@ -451,7 +456,12 @@ class BasicColor4: public Math::Vector4<T> {
* @param a A value, defaults to 1.0 for floating-point types and * @param a A value, defaults to 1.0 for floating-point types and
* maximum positive value for integral types. * maximum positive value for integral types.
*/ */
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr /*implicit*/ BasicColor4(T r, T g, T b, T a = Implementation::fullChannel<T>()): Math::Vector4<T>(r, g, b, a) {} constexpr /*implicit*/ BasicColor4(T r, T g, T b, T a = Implementation::fullChannel<T>()): Math::Vector4<T>(r, g, b, a) {}
#else
template<class U = T, class = typename std::enable_if<std::is_floating_point<T>::value, T>::type> constexpr /*implicit*/ BasicColor4(T r, T g, T b, T a = T(1)): Math::Vector4<T>(r, g, b, a) {}
template<class U = T, class V = T, class = typename std::enable_if<std::is_integral<T>::value, T>::type> constexpr /*implicit*/ BasicColor4(T r, T g, T b, T a = std::numeric_limits<T>::max()): Math::Vector4<T>(r, g, b, a) {}
#endif
/** /**
* @brief Constructor * @brief Constructor
@ -460,7 +470,12 @@ class BasicColor4: public Math::Vector4<T> {
*/ */
/* Not marked as explicit, because conversion from BasicColor3 to BasicColor4 /* Not marked as explicit, because conversion from BasicColor3 to BasicColor4
is fairly common, nearly always with A set to 1 */ is fairly common, nearly always with A set to 1 */
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr /*implicit*/ BasicColor4(const Math::Vector3<T>& rgb, T a = Implementation::fullChannel<T>()): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {} constexpr /*implicit*/ BasicColor4(const Math::Vector3<T>& rgb, T a = Implementation::fullChannel<T>()): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {}
#else
template<class U = T, class = typename std::enable_if<std::is_floating_point<T>::value, T>::type> constexpr /*implicit*/ BasicColor4(const Math::Vector3<T>& rgb, T a = T(1)): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {}
template<class U = T, class V = T, class = typename std::enable_if<std::is_integral<T>::value, T>::type> constexpr /*implicit*/ BasicColor4(const Math::Vector3<T>& rgb, T a = std::numeric_limits<T>::max()): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {}
#endif
/** /**
* @copydoc Math::Vector::Vector(const Vector<size, U>&) * @copydoc Math::Vector::Vector(const Vector<size, U>&)

19
src/Math/RectangularMatrix.h

@ -114,7 +114,13 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
* @todo Creating matrix from arbitrary combination of matrices with n rows * @todo Creating matrix from arbitrary combination of matrices with n rows
*/ */
#ifndef CORRADE_GCC45_COMPATIBILITY #ifndef CORRADE_GCC45_COMPATIBILITY
template<class ...U> constexpr /*implicit*/ RectangularMatrix(const Vector<rows, T>& first, const U&... next): _data{first, next...} { template<class ...U> constexpr /*implicit*/ RectangularMatrix(const Vector<rows, T>& first, const U&... next):
#ifndef CORRADE_MSVC2013_COMPATIBILITY
_data{first, next...}
#else
_data({first, next...})
#endif
{
#else #else
template<class ...U> /*implicit*/ RectangularMatrix(const Vector<rows, T>& first, const U&... next): _data() { template<class ...U> /*implicit*/ RectangularMatrix(const Vector<rows, T>& first, const U&... next): _data() {
constructInternal({first, next...}); constructInternal({first, next...});
@ -389,7 +395,12 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
private: private:
/* Implementation for RectangularMatrix<cols, rows, T>::RectangularMatrix(const RectangularMatrix<cols, rows, U>&) */ /* Implementation for RectangularMatrix<cols, rows, T>::RectangularMatrix(const RectangularMatrix<cols, rows, U>&) */
#ifndef CORRADE_GCC45_COMPATIBILITY #ifndef CORRADE_GCC45_COMPATIBILITY
template<class U, std::size_t ...sequence> constexpr explicit RectangularMatrix(Implementation::Sequence<sequence...>, const RectangularMatrix<cols, rows, U>& matrix): _data{Vector<rows, T>(matrix[sequence])...} {} template<class U, std::size_t ...sequence> constexpr explicit RectangularMatrix(Implementation::Sequence<sequence...>, const RectangularMatrix<cols, rows, U>& matrix):
#ifndef CORRADE_MSVC2013_COMPATIBILITY
_data{Vector<rows, T>(matrix[sequence])...} {}
#else
_data({Vector<rows, T>(matrix[sequence])...}) {}
#endif
#else #else
template<class U, std::size_t ...sequence> explicit RectangularMatrix(Implementation::Sequence<sequence...>, const RectangularMatrix<cols, rows, U>& matrix): _data() { template<class U, std::size_t ...sequence> explicit RectangularMatrix(Implementation::Sequence<sequence...>, const RectangularMatrix<cols, rows, U>& matrix): _data() {
constructInternal({Vector<rows, T>(matrix[sequence])...}); constructInternal({Vector<rows, T>(matrix[sequence])...});
@ -404,7 +415,11 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
} }
#endif #endif
#ifndef CORRADE_MSVC2013_COMPATIBILITY
Vector<rows, T> _data[cols]; Vector<rows, T> _data[cols];
#else
std::array<Vector<rows, T>, cols> _data;
#endif
}; };
#ifndef CORRADE_GCC46_COMPATIBILITY #ifndef CORRADE_GCC46_COMPATIBILITY

39
src/Math/Vector.h

@ -40,6 +40,10 @@
#include "magnumVisibility.h" #include "magnumVisibility.h"
#ifdef CORRADE_MSVC2013_COMPATIBILITY
#include <array>
#endif
namespace Magnum { namespace Math { namespace Magnum { namespace Math {
namespace Implementation { namespace Implementation {
@ -122,7 +126,12 @@ template<std::size_t size, class T> class Vector {
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT
template<class ...U> constexpr /*implicit*/ Vector(T first, U... next); template<class ...U> constexpr /*implicit*/ Vector(T first, U... next);
#else #else
template<class ...U, class V = typename std::enable_if<sizeof...(U)+1 == size, T>::type> constexpr /*implicit*/ Vector(T first, U... next): _data{first, next...} {} template<class ...U, class V = typename std::enable_if<sizeof...(U)+1 == size, T>::type> constexpr /*implicit*/ Vector(T first, U... next):
#ifndef CORRADE_MSVC2013_COMPATIBILITY
_data{first, next...} {}
#else
_data({first, next...}) {}
#endif
#endif #endif
/** @brief Construct vector with one value for all fields */ /** @brief Construct vector with one value for all fields */
@ -198,7 +207,11 @@ template<std::size_t size, class T> class Vector {
#if !defined(CORRADE_GCC47_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY) #if !defined(CORRADE_GCC47_COMPATIBILITY) && !defined(CORRADE_MSVC2013_COMPATIBILITY)
& &
#endif #endif
#ifndef CORRADE_MSVC2013_COMPATIBILITY
{ return _data; } { return _data; }
#else
{ return _data.data(); }
#endif
/** @overload */ /** @overload */
constexpr const T* data() constexpr const T* data()
@ -207,7 +220,11 @@ template<std::size_t size, class T> class Vector {
#else #else
const const
#endif #endif
#ifndef CORRADE_MSVC2013_COMPATIBILITY
{ return _data; } { return _data; }
#else
{ return _data.data(); }
#endif
/** /**
* @brief Value at given position * @brief Value at given position
@ -537,12 +554,26 @@ template<std::size_t size, class T> class Vector {
private: private:
/* Implementation for Vector<size, T>::Vector(const Vector<size, U>&) */ /* Implementation for Vector<size, T>::Vector(const Vector<size, U>&) */
template<class U, std::size_t ...sequence> constexpr explicit Vector(Implementation::Sequence<sequence...>, const Vector<sizeof...(sequence), U>& vector): _data{T(vector._data[sequence])...} {} template<class U, std::size_t ...sequence> constexpr explicit Vector(Implementation::Sequence<sequence...>, const Vector<sizeof...(sequence), U>& vector):
#ifndef CORRADE_MSVC2013_COMPATIBILITY
_data{T(vector._data[sequence])...} {}
#else
_data({T(vector._data[sequence])...}) {}
#endif
/* Implementation for Vector<size, T>::Vector(U) */ /* Implementation for Vector<size, T>::Vector(U) */
template<std::size_t ...sequence> constexpr explicit Vector(Implementation::Sequence<sequence...>, T value): _data{Implementation::repeat(value, sequence)...} {} template<std::size_t ...sequence> constexpr explicit Vector(Implementation::Sequence<sequence...>, T value):
#ifndef CORRADE_MSVC2013_COMPATIBILITY
_data{Implementation::repeat(value, sequence)...} {}
#else
_data({Implementation::repeat(value, sequence)...}) {}
#endif
#ifndef CORRADE_MSVC2013_COMPATIBILITY
T _data[size]; T _data[size];
#else
std::array<T, size> _data;
#endif
}; };
/** @relates Vector /** @relates Vector

Loading…
Cancel
Save