Browse Source

Swapped size and type template parameters in Vector and Matrix.

Long-standing TODO. It is better to have size first, because it is more
significant than type (e.g. because there are Vector4<T> specializations
and not VectorT<4> specializations). It is also IMHO easier for user to
distinguish/read the type than before:

    Vector<float, 4>    ->     Vector4<float> // before
    Vector<4, float>    ->     Vector4<float> // now
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
cc1f9c60c9
  1. 4
      src/AbstractTexture.cpp
  2. 12
      src/AbstractTexture.h
  3. 8
      src/BufferedImage.h
  4. 6
      src/CubeMapTexture.h
  5. 12
      src/Image.h
  6. 78
      src/Math/Matrix.h
  7. 42
      src/Math/Matrix3.h
  8. 44
      src/Math/Matrix4.h
  9. 18
      src/Math/Test/MatrixTest.cpp
  10. 2
      src/Math/Test/Vector2Test.cpp
  11. 4
      src/Math/Test/Vector3Test.cpp
  12. 4
      src/Math/Test/Vector4Test.cpp
  13. 4
      src/Math/Test/VectorTest.cpp
  14. 56
      src/Math/Vector.h
  15. 38
      src/Math/Vector2.h
  16. 40
      src/Math/Vector3.h
  17. 44
      src/Math/Vector4.h
  18. 6
      src/MeshTools/Clean.h
  19. 10
      src/MeshTools/CombineIndexedArrays.h
  20. 4
      src/Texture.h
  21. 8
      src/Trade/ImageData.h
  22. 14
      src/TypeTraits.h

4
src/AbstractTexture.cpp

@ -100,14 +100,14 @@ AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components comp
}
#ifndef DOXYGEN_GENERATING_OUTPUT
void AbstractTexture::DataHelper<2>::setWrapping(GLenum target, const Math::Vector<Wrapping, 2>& wrapping) {
void AbstractTexture::DataHelper<2>::setWrapping(GLenum target, const Math::Vector<2, Wrapping>& wrapping) {
CORRADE_ASSERT(target != GL_TEXTURE_RECTANGLE || ((wrapping[0] == Wrapping::ClampToEdge || wrapping[0] == Wrapping::ClampToBorder) && (wrapping[0] == Wrapping::ClampToEdge || wrapping[1] == Wrapping::ClampToEdge)), "AbstractTexture: rectangle texture wrapping must either clamp to border or to edge", )
glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast<GLint>(wrapping[0]));
glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast<GLint>(wrapping[1]));
}
void AbstractTexture::DataHelper<3>::setWrapping(GLenum target, const Math::Vector<Wrapping, 3>& wrapping) {
void AbstractTexture::DataHelper<3>::setWrapping(GLenum target, const Math::Vector<3, Wrapping>& wrapping) {
glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast<GLint>(wrapping[0]));
glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast<GLint>(wrapping[1]));
glTexParameteri(target, GL_TEXTURE_WRAP_R, static_cast<GLint>(wrapping[2]));

12
src/AbstractTexture.h

@ -571,7 +571,7 @@ template<> struct AbstractTexture::DataHelper<1> {
inline constexpr static Target target() { return Target::Texture1D; }
inline static void setWrapping(GLenum target, const Math::Vector<Wrapping, 1>& wrapping) {
inline static void setWrapping(GLenum target, const Math::Vector<1, Wrapping>& wrapping) {
glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast<GLint>(wrapping[0]));
}
@ -579,7 +579,7 @@ template<> struct AbstractTexture::DataHelper<1> {
glTexImage1D(target, mipLevel, internalFormat, image->dimensions()[0], 0, static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
template<class T> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<GLint, 1>& offset, T* image) {
template<class T> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<1, GLint>& offset, T* image) {
glTexSubImage1D(target, mipLevel, offset[0], image->dimensions()[0], static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
};
@ -592,13 +592,13 @@ template<> struct AbstractTexture::DataHelper<2> {
inline constexpr static Target target() { return Target::Texture2D; }
static void setWrapping(GLenum target, const Math::Vector<Wrapping, 2>& wrapping);
static void setWrapping(GLenum target, const Math::Vector<2, Wrapping>& wrapping);
template<class T> inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, T* image) {
glTexImage2D(target, mipLevel, internalFormat, image->dimensions()[0], image->dimensions()[1], 0, static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
template<class T> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<GLint, 2>& offset, T* image) {
template<class T> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<2, GLint>& offset, T* image) {
glTexSubImage2D(target, mipLevel, offset[0], offset[1], image->dimensions()[0], image->dimensions()[1], static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
};
@ -610,13 +610,13 @@ template<> struct AbstractTexture::DataHelper<3> {
inline constexpr static Target target() { return Target::Texture3D; }
static void setWrapping(GLenum target, const Math::Vector<Wrapping, 3>& wrapping);
static void setWrapping(GLenum target, const Math::Vector<3, Wrapping>& wrapping);
template<class T> inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, T* image) {
glTexImage3D(target, mipLevel, internalFormat, image->dimensions()[0], image->dimensions()[1], image->dimensions()[2], 0, static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
template<class T> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<GLint, 3>& offset, T* image) {
template<class T> inline static void setSub(GLenum target, GLint mipLevel, const Math::Vector<3, GLint>& offset, T* image) {
glTexSubImage3D(target, mipLevel, offset[0], offset[1], offset[2], image->dimensions()[0], image->dimensions()[1], image->dimensions()[2], static_cast<GLenum>(image->components()), static_cast<GLenum>(image->type()), image->data());
}
};

8
src/BufferedImage.h

@ -46,7 +46,7 @@ template<size_t imageDimensions> class BufferedImage: public AbstractImage {
BufferedImage(Components components, ComponentType type): AbstractImage(components, type), _buffer(Buffer::Target::PixelPack) {}
/** @brief %Image dimensions */
inline Math::Vector<GLsizei, Dimensions> dimensions() const { return _dimensions; }
inline Math::Vector<Dimensions, GLsizei> dimensions() const { return _dimensions; }
/**
* @brief Data
@ -74,7 +74,7 @@ template<size_t imageDimensions> class BufferedImage: public AbstractImage {
* Updates the image buffer with given data. The data are not deleted
* after filling the buffer.
*/
template<class T> inline void setData(const Math::Vector<GLsizei, Dimensions>& dimensions, Components components, const T* data, Buffer::Usage usage) {
template<class T> inline void setData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, const T* data, Buffer::Usage usage) {
setData(dimensions, components, TypeTraits<T>::imageType(), data, usage);
}
@ -89,7 +89,7 @@ template<size_t imageDimensions> class BufferedImage: public AbstractImage {
* Updates the image buffer with given data. The data are not deleted
* after filling the buffer.
*/
void setData(const Math::Vector<GLsizei, Dimensions>& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) {
void setData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) {
_components = components;
_type = type;
_dimensions = dimensions;
@ -97,7 +97,7 @@ template<size_t imageDimensions> class BufferedImage: public AbstractImage {
}
protected:
Math::Vector<GLsizei, Dimensions> _dimensions; /**< @brief %Image dimensions */
Math::Vector<Dimensions, GLsizei> _dimensions; /**< @brief %Image dimensions */
Buffer _buffer; /**< @brief %Image buffer */
};

6
src/CubeMapTexture.h

@ -77,7 +77,7 @@ class CubeMapTexture: public AbstractTexture {
/**
* @copydoc Texture::setWrapping()
*/
inline void setWrapping(const Math::Vector<Wrapping, 3>& wrapping) {
inline void setWrapping(const Math::Vector<3, Wrapping>& wrapping) {
bind();
DataHelper<3>::setWrapping(GL_TEXTURE_CUBE_MAP, wrapping);
}
@ -92,10 +92,10 @@ class CubeMapTexture: public AbstractTexture {
}
/**
* @copydoc Texture::setSubData(GLint, const Math::Vector<GLint, Dimensions>&, T*)
* @copydoc Texture::setSubData(GLint, const Math::Vector<Dimensions, GLint>&, T*)
* @param coordinate Coordinate
*/
template<class T> inline void setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<GLint, 2>& offset, const T* image) {
template<class T> inline void setSubData(Coordinate coordinate, GLint mipLevel, const Math::Vector<2, GLint>& offset, const T* image) {
bind();
DataHelper<2>::setSub(static_cast<GLenum>(coordinate), mipLevel, offset, image);
}

12
src/Image.h

@ -45,7 +45,7 @@ template<size_t imageDimensions> class Image: public AbstractImage {
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
template<class T> inline Image(const Math::Vector<GLsizei, Dimensions>& dimensions, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _dimensions(dimensions), _data(data) {}
template<class T> inline Image(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _dimensions(dimensions), _data(data) {}
/**
* @brief Constructor
@ -57,7 +57,7 @@ template<size_t imageDimensions> class Image: public AbstractImage {
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
inline Image(const Math::Vector<GLsizei, Dimensions>& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _dimensions(dimensions), _data(reinterpret_cast<char*>(data)) {}
inline Image(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _dimensions(dimensions), _data(reinterpret_cast<char*>(data)) {}
/**
* @brief Constructor
@ -73,7 +73,7 @@ template<size_t imageDimensions> class Image: public AbstractImage {
inline ~Image() { delete[] _data; }
/** @brief %Image dimensions */
inline const Math::Vector<GLsizei, Dimensions>& dimensions() const { return _dimensions; }
inline const Math::Vector<Dimensions, GLsizei>& dimensions() const { return _dimensions; }
/** @brief Pointer to raw data */
inline const void* data() const { return _data; }
@ -88,7 +88,7 @@ template<size_t imageDimensions> class Image: public AbstractImage {
* Deletes previous data and replaces them with new. Note that the
* data are not copied, but they are deleted on destruction.
*/
template<class T> inline void setData(const Math::Vector<GLsizei, Dimensions>& dimensions, Components components, T* data) {
template<class T> inline void setData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, T* data) {
setData(dimensions, components, TypeTraits<T>::imageType(), data);
}
@ -102,7 +102,7 @@ template<size_t imageDimensions> class Image: public AbstractImage {
* Deletes previous data and replaces them with new. Note that the
* data are not copied, but they are deleted on destruction.
*/
void setData(const Math::Vector<GLsizei, Dimensions>& dimensions, Components components, ComponentType type, GLvoid* data) {
void setData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type, GLvoid* data) {
delete _data;
_components = components;
_type = type;
@ -111,7 +111,7 @@ template<size_t imageDimensions> class Image: public AbstractImage {
}
protected:
Math::Vector<GLsizei, Dimensions> _dimensions; /**< @brief %Image dimensions */
Math::Vector<Dimensions, GLsizei> _dimensions; /**< @brief %Image dimensions */
char* _data; /**< @brief %Image data */
};

78
src/Math/Matrix.h

@ -25,7 +25,7 @@ namespace Magnum { namespace Math {
#ifndef DOXYGEN_GENERATING_OUTPUT
namespace Implementation {
template<class T, size_t size> class MatrixDeterminant;
template<size_t size, class T> class MatrixDeterminant;
template<size_t ...> struct Sequence {};
@ -42,11 +42,11 @@ namespace Implementation {
/**
* @brief %Matrix
*
* @todo @c PERFORMANCE - loop unrolling for Matrix<T, 3> and Matrix<T, 4>
* @todo @c PERFORMANCE - loop unrolling for Matrix<3, T> and Matrix<4, T>
* @todo first col, then row (cache adjacency)
*/
template<class T, size_t size> class Matrix {
friend class Matrix<T, size+1>; /* for ij() */
template<size_t size, class T> class Matrix {
friend class Matrix<size+1, T>; /* for ij() */
public:
/**
@ -57,13 +57,13 @@ template<class T, size_t size> class Matrix {
* @attention Use with caution, the function doesn't check whether the
* array is long enough.
*/
inline constexpr static Matrix<T, size>& from(T* data) {
return *reinterpret_cast<Matrix<T, size>*>(data);
inline constexpr static Matrix<size, T>& from(T* data) {
return *reinterpret_cast<Matrix<size, T>*>(data);
}
/** @copydoc from(T*) */
inline constexpr static const Matrix<T, size>& from(const T* data) {
return *reinterpret_cast<const Matrix<T, size>*>(data);
inline constexpr static const Matrix<size, T>& from(const T* data) {
return *reinterpret_cast<const Matrix<size, T>*>(data);
}
/**
@ -71,7 +71,7 @@ template<class T, size_t size> class Matrix {
* @param first First column vector
* @param next Next column vectors
*/
template<class ...U> inline constexpr static Matrix<T, size> from(const Vector<T, size>& first, const U&... next) {
template<class ...U> inline constexpr static Matrix<size, T> from(const Vector<size, T>& first, const U&... next) {
return from(typename Implementation::GenerateSequence<size>::Type(), first, next...);
}
@ -118,10 +118,10 @@ template<class T, size_t size> class Matrix {
#endif
/** @brief Copy constructor */
inline constexpr Matrix(const Matrix<T, size>& other) = default;
inline constexpr Matrix(const Matrix<size, T>& other) = default;
/** @brief Assignment operator */
inline Matrix<T, size>& operator=(const Matrix<T, size>& other) = default;
inline Matrix<size, T>& operator=(const Matrix<size, T>& other) = default;
/**
* @brief Raw data
@ -132,17 +132,17 @@ template<class T, size_t size> class Matrix {
inline constexpr const T* data() const { return _data; } /**< @copydoc data() */
/** @brief %Matrix column */
inline Vector<T, size>& operator[](size_t col) {
return Vector<T, size>::from(_data+col*size);
inline Vector<size, T>& operator[](size_t col) {
return Vector<size, T>::from(_data+col*size);
}
/** @copydoc operator[]() */
inline constexpr const Vector<T, size>& operator[](size_t col) const {
return Vector<T, size>::from(_data+col*size);
inline constexpr const Vector<size, T>& operator[](size_t col) const {
return Vector<size, T>::from(_data+col*size);
}
/** @brief Equality operator */
inline bool operator==(const Matrix<T, size>& other) const {
inline bool operator==(const Matrix<size, T>& other) const {
for(size_t i = 0; i != size*size; ++i)
if(!TypeTraits<T>::equals(_data[i], other._data[i])) return false;
@ -150,13 +150,13 @@ template<class T, size_t size> class Matrix {
}
/** @brief Non-equality operator */
inline constexpr bool operator!=(const Matrix<T, size>& other) const {
inline constexpr bool operator!=(const Matrix<size, T>& other) const {
return !operator==(other);
}
/** @brief Multiply matrix operator */
Matrix<T, size> operator*(const Matrix<T, size>& other) const {
Matrix<T, size> out(Zero);
Matrix<size, T> operator*(const Matrix<size, T>& other) const {
Matrix<size, T> out(Zero);
for(size_t row = 0; row != size; ++row)
for(size_t col = 0; col != size; ++col)
@ -167,13 +167,13 @@ template<class T, size_t size> class Matrix {
}
/** @brief Multiply and assign matrix operator */
inline Matrix<T, size>& operator*=(const Matrix<T, size>& other) {
inline Matrix<size, T>& operator*=(const Matrix<size, T>& other) {
return (*this = *this*other);
}
/** @brief Multiply vector operator */
Vector<T, size> operator*(const Vector<T, size>& other) const {
Vector<T, size> out;
Vector<size, T> operator*(const Vector<size, T>& other) const {
Vector<size, T> out;
for(size_t row = 0; row != size; ++row)
for(size_t pos = 0; pos != size; ++pos)
@ -183,8 +183,8 @@ template<class T, size_t size> class Matrix {
}
/** @brief Transposed matrix */
Matrix<T, size> transposed() const {
Matrix<T, size> out(Zero);
Matrix<size, T> transposed() const {
Matrix<size, T> out(Zero);
for(size_t row = 0; row != size; ++row)
for(size_t col = 0; col != size; ++col)
@ -194,8 +194,8 @@ template<class T, size_t size> class Matrix {
}
/** @brief %Matrix without given column and row */
Matrix<T, size-1> ij(size_t skipCol, size_t skipRow) const {
Matrix<T, size-1> out(Matrix<T, size-1>::Zero);
Matrix<size-1, T> ij(size_t skipCol, size_t skipRow) const {
Matrix<size-1, T> out(Matrix<size-1, T>::Zero);
for(size_t row = 0; row != size-1; ++row)
for(size_t col = 0; col != size-1; ++col)
@ -219,7 +219,7 @@ template<class T, size_t size> class Matrix {
* \det(A) = a_{0, 0} a_{1, 1} - a_{1, 0} a_{0, 1}
* @f]
*/
inline T determinant() const { return Implementation::MatrixDeterminant<T, size>()(*this); }
inline T determinant() const { return Implementation::MatrixDeterminant<size, T>()(*this); }
/**
* @brief Inverted matrix
@ -229,8 +229,8 @@ template<class T, size_t size> class Matrix {
* A^{-1} = \frac{1}{\det(A)} Adj(A)
* @f]
*/
Matrix<T, size> inverted() const {
Matrix<T, size> out(Zero);
Matrix<size, T> inverted() const {
Matrix<size, T> out(Zero);
T _determinant = determinant();
@ -242,12 +242,12 @@ template<class T, size_t size> class Matrix {
}
private:
template<size_t ...sequence, class ...U> inline constexpr static Matrix<T, size> from(Implementation::Sequence<sequence...> s, const Vector<T, size>& first, U... next) {
template<size_t ...sequence, class ...U> inline constexpr static Matrix<size, T> from(Implementation::Sequence<sequence...> s, const Vector<size, T>& first, U... next) {
return from(s, next..., first[sequence]...);
}
template<size_t ...sequence, class ...U> inline constexpr static Matrix<T, size> from(Implementation::Sequence<sequence...> s, T first, U... next) {
return Matrix<T, size>(first, next...);
template<size_t ...sequence, class ...U> inline constexpr static Matrix<size, T> from(Implementation::Sequence<sequence...> s, T first, U... next) {
return Matrix<size, T>(first, next...);
}
/* Used internally instead of [][], because GCC does some heavy
@ -265,10 +265,10 @@ template<class T, size_t size> class Matrix {
#ifndef DOXYGEN_GENERATING_OUTPUT
namespace Implementation {
template<class T, size_t size> class MatrixDeterminant {
template<size_t size, class T> class MatrixDeterminant {
public:
/** @brief Functor */
T operator()(const Matrix<T, size>& m) {
T operator()(const Matrix<size, T>& m) {
T out(0);
for(size_t col = 0; col != size; ++col)
@ -278,25 +278,25 @@ template<class T, size_t size> class MatrixDeterminant {
}
};
template<class T> class MatrixDeterminant<T, 2> {
template<class T> class MatrixDeterminant<2, T> {
public:
/** @brief Functor */
inline constexpr T operator()(const Matrix<T, 2>& m) {
inline constexpr T operator()(const Matrix<2, T>& m) {
return m[0][0]*m[1][1] - m[1][0]*m[0][1];
}
};
template<class T> class MatrixDeterminant<T, 1> {
template<class T> class MatrixDeterminant<1, T> {
public:
/** @brief Functor */
inline constexpr T operator()(const Matrix<T, 1>& m) {
inline constexpr T operator()(const Matrix<1, T>& m) {
return m[0][0];
}
};
}
template<class T, size_t size> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix<T, size>& value) {
template<class T, size_t size> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix<size, T>& value) {
debug << "Matrix(";
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false);
for(size_t row = 0; row != size; ++row) {

42
src/Math/Matrix3.h

@ -25,7 +25,7 @@
namespace Magnum { namespace Math {
/** @brief 3x3 matrix */
template<class T> class Matrix3: public Matrix<T, 3> {
template<class T> class Matrix3: public Matrix<3, T> {
public:
/** @copydoc Matrix::from(T*) */
inline constexpr static Matrix3<T>& from(T* data) {
@ -37,16 +37,16 @@ template<class T> class Matrix3: public Matrix<T, 3> {
return *reinterpret_cast<const Matrix3<T>*>(data);
}
/** @copydoc Matrix::from(const Vector<T, size>&, const U&...) */
template<class ...U> inline constexpr static Matrix3<T> from(const Vector<T, 3>& first, const U&... next) {
return Matrix<T, 3>::from(first, next...);
/** @copydoc Matrix::from(const Vector<size, T>&, const U&...) */
template<class ...U> inline constexpr static Matrix3<T> from(const Vector<3, T>& first, const U&... next) {
return Matrix<3, T>::from(first, next...);
}
/** @copydoc Matrix::Matrix(ZeroType) */
inline constexpr explicit Matrix3(typename Matrix<T, 3>::ZeroType): Matrix<T, 3>(Matrix<T, 3>::Zero) {}
inline constexpr explicit Matrix3(typename Matrix<3, T>::ZeroType): Matrix<3, T>(Matrix<3, T>::Zero) {}
/** @copydoc Matrix::Matrix(IdentityType, T) */
inline constexpr explicit Matrix3(typename Matrix<T, 3>::IdentityType = Matrix<T, 3>::Identity, T value = T(1)): Matrix<T, 3>(
inline constexpr explicit Matrix3(typename Matrix<3, T>::IdentityType = Matrix<3, T>::Identity, T value = T(1)): Matrix<3, T>(
value, 0.0f, 0.0f,
0.0f, value, 0.0f,
0.0f, 0.0f, value
@ -58,48 +58,48 @@ template<class T> class Matrix3: public Matrix<T, 3> {
/** @copydoc Matrix::Matrix(T, U...) */
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class ...U> inline constexpr Matrix3(T first, U... next): Matrix<T, 3>(first, next...) {}
template<class ...U> inline constexpr Matrix3(T first, U... next): Matrix<3, T>(first, next...) {}
#else
template<class ...U> inline constexpr Matrix3(T first, U... next) {}
#endif
/** @copydoc Matrix::Matrix(const Matrix<T, size>&) */
inline constexpr Matrix3(const Matrix<T, 3>& other): Matrix<T, 3>(other) {}
/** @copydoc Matrix::Matrix(const Matrix<size, T>&) */
inline constexpr Matrix3(const Matrix<3, T>& other): Matrix<3, T>(other) {}
/** @copydoc Matrix::operator=() */
inline Matrix3<T>& operator=(const Matrix3<T>& other) {
Matrix<T, 3>::operator=(other);
Matrix<3, T>::operator=(other);
return *this;
}
/** @copydoc Matrix::operator[](size_t) */
inline Vector3<T>& operator[](size_t col) { return Vector3<T>::from(Matrix<T, 3>::data()+col*3); }
inline Vector3<T>& operator[](size_t col) { return Vector3<T>::from(Matrix<3, T>::data()+col*3); }
/** @copydoc Matrix::operator[](size_t) const */
inline constexpr const Vector3<T>& operator[](size_t col) const { return Vector3<T>::from(Matrix<T, 3>::data()+col*3); }
inline constexpr const Vector3<T>& operator[](size_t col) const { return Vector3<T>::from(Matrix<3, T>::data()+col*3); }
/** @copydoc Matrix::operator*(const Matrix<T, size>&) const */
inline Matrix3<T> operator*(const Matrix<T, 3>& other) const { return Matrix<T, 3>::operator*(other); }
/** @copydoc Matrix::operator*(const Matrix<size, T>&) const */
inline Matrix3<T> operator*(const Matrix<3, T>& other) const { return Matrix<3, T>::operator*(other); }
/** @copydoc Matrix::operator*=() */
inline Matrix3<T>& operator*=(const Matrix<T, 3>& other) {
Matrix<T, 3>::operator*=(other);
inline Matrix3<T>& operator*=(const Matrix<3, T>& other) {
Matrix<3, T>::operator*=(other);
return *this;
}
/** @copydoc Matrix::operator*(const Vector<T, size>&) const */
inline Vector3<T> operator*(const Vector<T, 3>& other) const { return Matrix<T, 3>::operator*(other); }
/** @copydoc Matrix::operator*(const Vector<size, T>&) const */
inline Vector3<T> operator*(const Vector<3, T>& other) const { return Matrix<3, T>::operator*(other); }
/** @copydoc Matrix::transposed() */
inline Matrix3<T> transposed() const { return Matrix<T, 3>::transposed(); }
inline Matrix3<T> transposed() const { return Matrix<3, T>::transposed(); }
/** @copydoc Matrix::inverted() */
inline Matrix3<T> inverted() const { return Matrix<T, 3>::inverted(); }
inline Matrix3<T> inverted() const { return Matrix<3, T>::inverted(); }
};
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix3<T>& value) {
return debug << static_cast<const Magnum::Math::Matrix<T, 3>&>(value);
return debug << static_cast<const Magnum::Math::Matrix<3, T>&>(value);
}
#endif

44
src/Math/Matrix4.h

@ -30,7 +30,7 @@ namespace Magnum { namespace Math {
@todo Shearing
@todo Reflection
*/
template<class T> class Matrix4: public Matrix<T, 4> {
template<class T> class Matrix4: public Matrix<4, T> {
public:
/** @copydoc Matrix::from(T*) */
inline constexpr static Matrix4<T>& from(T* data) {
@ -42,9 +42,9 @@ template<class T> class Matrix4: public Matrix<T, 4> {
return *reinterpret_cast<const Matrix4<T>*>(data);
}
/** @copydoc Matrix::from(const Vector<T, size>&, const U&...) */
template<class ...U> inline constexpr static Matrix4<T> from(const Vector<T, 4>& first, const U&... next) {
return Matrix<T, 4>::from(first, next...);
/** @copydoc Matrix::from(const Vector<size, T>&, const U&...) */
template<class ...U> inline constexpr static Matrix4<T> from(const Vector<4, T>& first, const U&... next) {
return Matrix<4, T>::from(first, next...);
}
/**
@ -110,10 +110,10 @@ template<class T> class Matrix4: public Matrix<T, 4> {
}
/** @copydoc Matrix::Matrix(ZeroType) */
inline constexpr explicit Matrix4(typename Matrix<T, 4>::ZeroType): Matrix<T, 4>(Matrix<T, 4>::Zero) {}
inline constexpr explicit Matrix4(typename Matrix<4, T>::ZeroType): Matrix<4, T>(Matrix<4, T>::Zero) {}
/** @copydoc Matrix::Matrix(IdentityType, T) */
inline constexpr explicit Matrix4(typename Matrix<T, 4>::IdentityType = Matrix<T, 4>::Identity, T value = T(1)): Matrix<T, 4>(
inline constexpr explicit Matrix4(typename Matrix<4, T>::IdentityType = Matrix<4, T>::Identity, T value = T(1)): Matrix<4, T>(
value, 0.0f, 0.0f, 0.0f,
0.0f, value, 0.0f, 0.0f,
0.0f, 0.0f, value, 0.0f,
@ -126,46 +126,46 @@ template<class T> class Matrix4: public Matrix<T, 4> {
/** @copydoc Matrix::Matrix(T, U...) */
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class ...U> inline constexpr Matrix4(T first, U... next): Matrix<T, 4>(first, next...) {}
template<class ...U> inline constexpr Matrix4(T first, U... next): Matrix<4, T>(first, next...) {}
#else
template<class ...U> inline constexpr Matrix4(T first, U... next) {}
#endif
/** @copydoc Matrix::Matrix(const Matrix<T, size>&) */
inline constexpr Matrix4(const Matrix<T, 4>& other): Matrix<T, 4>(other) {}
/** @copydoc Matrix::Matrix(const Matrix<size, T>&) */
inline constexpr Matrix4(const Matrix<4, T>& other): Matrix<4, T>(other) {}
/** @copydoc Matrix::operator=() */
inline Matrix4<T>& operator=(const Matrix4<T>& other) {
Matrix<T, 4>::operator=(other);
Matrix<4, T>::operator=(other);
return *this;
}
/** @copydoc Matrix::operator[](size_t) */
inline Vector4<T>& operator[](size_t col) { return Vector4<T>::from(Matrix<T, 4>::data()+col*4); }
inline Vector4<T>& operator[](size_t col) { return Vector4<T>::from(Matrix<4, T>::data()+col*4); }
/** @copydoc Matrix::operator[](size_t) const */
inline constexpr const Vector4<T>& operator[](size_t col) const { return Vector4<T>::from(Matrix<T, 4>::data()+col*4); }
inline constexpr const Vector4<T>& operator[](size_t col) const { return Vector4<T>::from(Matrix<4, T>::data()+col*4); }
/** @copydoc Matrix::operator*(const Matrix<T, size>&) const */
inline Matrix4<T> operator*(const Matrix<T, 4>& other) const { return Matrix<T, 4>::operator*(other); }
/** @copydoc Matrix::operator*(const Matrix<size, T>&) const */
inline Matrix4<T> operator*(const Matrix<4, T>& other) const { return Matrix<4, T>::operator*(other); }
/** @copydoc Matrix::operator*=() */
inline Matrix4<T>& operator*=(const Matrix<T, 4>& other) {
Matrix<T, 4>::operator*=(other);
inline Matrix4<T>& operator*=(const Matrix<4, T>& other) {
Matrix<4, T>::operator*=(other);
return *this;
}
/** @copydoc Matrix::operator*(const Vector<T, size>&) const */
inline Vector4<T> operator*(const Vector<T, 4>& other) const { return Matrix<T, 4>::operator*(other); }
/** @copydoc Matrix::operator*(const Vector<size, T>&) const */
inline Vector4<T> operator*(const Vector<4, T>& other) const { return Matrix<4, T>::operator*(other); }
/** @copydoc Matrix::transposed() */
inline Matrix4<T> transposed() const { return Matrix<T, 4>::transposed(); }
inline Matrix4<T> transposed() const { return Matrix<4, T>::transposed(); }
/** @copydoc Matrix::ij() */
inline Matrix3<T> ij(size_t skipRow, size_t skipCol) const { return Matrix<T, 4>::ij(skipRow, skipCol); }
inline Matrix3<T> ij(size_t skipRow, size_t skipCol) const { return Matrix<4, T>::ij(skipRow, skipCol); }
/** @copydoc Matrix::inverted() */
inline Matrix4<T> inverted() const { return Matrix<T, 4>::inverted(); }
inline Matrix4<T> inverted() const { return Matrix<4, T>::inverted(); }
/** @brief Rotation and scaling part of the matrix */
inline Matrix3<T> rotationScaling() const {
@ -186,7 +186,7 @@ template<class T> class Matrix4: public Matrix<T, 4> {
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Matrix4<T>& value) {
return debug << static_cast<const Magnum::Math::Matrix<T, 4>&>(value);
return debug << static_cast<const Magnum::Math::Matrix<4, T>&>(value);
}
#endif

18
src/Math/Test/MatrixTest.cpp

@ -27,9 +27,9 @@ using namespace Corrade::Utility;
namespace Magnum { namespace Math { namespace Test {
typedef Matrix<float, 4> Matrix4;
typedef Matrix<float, 3> Matrix3;
typedef Vector<float, 4> Vector4;
typedef Matrix<4, float> Matrix4;
typedef Matrix<3, float> Matrix3;
typedef Vector<4, float> Vector4;
void MatrixTest::construct() {
float m[] = {
@ -158,7 +158,7 @@ void MatrixTest::multiplyIdentity() {
}
void MatrixTest::multiply() {
Matrix<int, 5> left(
Matrix<5, int> left(
-3, -3, -1, 3, -5,
-1, -3, -5, 2, 3,
-1, -4, 3, -1, -2,
@ -166,7 +166,7 @@ void MatrixTest::multiply() {
1, 3, -3, -4, -1
);
Matrix<int, 5> right(
Matrix<5, int> right(
0, 5, 3, 4, 4,
5, 5, 0, 0, -2,
3, 2, -4, -3, 0,
@ -174,7 +174,7 @@ void MatrixTest::multiply() {
0, -1, -4, 4, 3
);
Matrix<int, 5> expected(
Matrix<5, int> expected(
-24, -35, -32, -25, 1,
-22, -36, -24, 33, -8,
8, 16, -22, 29, 2,
@ -186,7 +186,7 @@ void MatrixTest::multiply() {
}
void MatrixTest::multiplyVector() {
Matrix<int, 5> matrix(
Matrix<5, int> matrix(
-3, -3, -1, 3, -5,
-1, -3, -5, 2, 3,
-1, -4, 3, -1, -2,
@ -194,7 +194,7 @@ void MatrixTest::multiplyVector() {
1, 3, -3, -4, -1
);
bool is = (matrix*Vector<int, 5>(0, 5, 3, 4, 4) == Vector<int, 5>(-24, -35, -32, -25, 1));
bool is = (matrix*Vector<5, int>(0, 5, 3, 4, 4) == Vector<5, int>(-24, -35, -32, -25, 1));
QVERIFY(is);
}
@ -235,7 +235,7 @@ void MatrixTest::ij() {
}
void MatrixTest::determinant() {
Matrix<int, 5> m(
Matrix<5, int> m(
1, 2, 2, 1, 0,
2, 3, 2, 1, -2,
1, 1, 1, 1, 0,

2
src/Math/Test/Vector2Test.cpp

@ -30,7 +30,7 @@ namespace Magnum { namespace Math { namespace Test {
typedef Math::Vector2<float> Vector2;
void Vector2Test::construct() {
QVERIFY((Vector2(1, 2) == Vector<float, 2>(1.0f, 2.0f)));
QVERIFY((Vector2(1, 2) == Vector<2, float>(1.0f, 2.0f)));
}
void Vector2Test::debug() {

4
src/Math/Test/Vector3Test.cpp

@ -30,8 +30,8 @@ namespace Magnum { namespace Math { namespace Test {
typedef Math::Vector3<float> Vector3;
void Vector3Test::construct() {
QVERIFY((Vector3(1, 2, 3) == Vector<float, 3>(1.0f, 2.0f, 3.0f)));
QVERIFY((Vector3(Vector<float, 2>(1.0f, 2.0f), 3) == Vector<float, 3>(1.0f, 2.0f, 3.0f)));
QVERIFY((Vector3(1, 2, 3) == Vector<3, float>(1.0f, 2.0f, 3.0f)));
QVERIFY((Vector3(Vector<2, float>(1.0f, 2.0f), 3) == Vector<3, float>(1.0f, 2.0f, 3.0f)));
}
void Vector3Test::cross() {

4
src/Math/Test/Vector4Test.cpp

@ -32,8 +32,8 @@ typedef Math::Vector3<float> Vector3;
void Vector4Test::construct() {
QVERIFY(Vector4() == Vector4(0.0f, 0.0f, 0.0f, 1.0f));
QVERIFY((Vector4(1, 2, 3, 4) == Vector<float, 4>(1.0f, 2.0f, 3.0f, 4.0f)));
QVERIFY((Vector4(Vector<float, 3>(1.0f, 2.0f, 3.0f), 4) == Vector<float, 4>(1.0f, 2.0f, 3.0f, 4.0f)));
QVERIFY((Vector4(1, 2, 3, 4) == Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f)));
QVERIFY((Vector4(Vector<3, float>(1.0f, 2.0f, 3.0f), 4) == Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f)));
}
void Vector4Test::threeComponent() {

4
src/Math/Test/VectorTest.cpp

@ -28,8 +28,8 @@ using namespace Corrade::Utility;
namespace Magnum { namespace Math { namespace Test {
typedef Vector<float, 4> Vector4;
typedef Vector<float, 3> Vector3;
typedef Vector<4, float> Vector4;
typedef Vector<3, float> Vector3;
void VectorTest::construct() {
QVERIFY((Vector4() == Vector4(0.0f, 0.0f, 0.0f, 0.0f)));

56
src/Math/Vector.h

@ -31,10 +31,10 @@ namespace Magnum { namespace Math {
@todo Swizzling
*/
template<class T, size_t size> class Vector {
template<size_t size, class T> class Vector {
public:
typedef T Type; /**< @brief %Vector data type */
const static size_t Size = size; /**< @brief %Vector size */
typedef T Type; /**< @brief %Vector data type */
/**
* @brief %Vector from array
@ -44,13 +44,13 @@ template<class T, size_t size> class Vector {
* @attention Use with caution, the function doesn't check whether the
* array is long enough.
*/
inline constexpr static Vector<T, size>& from(T* data) {
return *reinterpret_cast<Vector<T, size>*>(data);
inline constexpr static Vector<size, T>& from(T* data) {
return *reinterpret_cast<Vector<size, T>*>(data);
}
/** @copydoc from(T*) */
inline constexpr static const Vector<T, size>& from(const T* data) {
return *reinterpret_cast<const Vector<T, size>*>(data);
inline constexpr static const Vector<size, T>& from(const T* data) {
return *reinterpret_cast<const Vector<size, T>*>(data);
}
/**
@ -60,7 +60,7 @@ template<class T, size_t size> class Vector {
* a \cdot b = \sum_{i=0}^{n-1} a_ib_i
* @f]
*/
static T dot(const Vector<T, size>& a, const Vector<T, size>& b) {
static T dot(const Vector<size, T>& a, const Vector<size, T>& b) {
T out(0);
for(size_t i = 0; i != size; ++i)
@ -78,7 +78,7 @@ template<class T, size_t size> class Vector {
*
* @todo optimize - Assume the vectors are normalized?
*/
inline static T angle(const Vector<T, size>& a, const Vector<T, size>& b) {
inline static T angle(const Vector<size, T>& a, const Vector<size, T>& b) {
return acos(dot(a, b)/(a.length()*b.length()));
}
@ -106,10 +106,10 @@ template<class T, size_t size> class Vector {
}
/** @brief Copy constructor */
inline constexpr Vector(const Vector<T, size>& other) = default;
inline constexpr Vector(const Vector<size, T>& other) = default;
/** @brief Assignment operator */
inline Vector<T, size>& operator=(const Vector<T, size>& other) = default;
inline Vector<size, T>& operator=(const Vector<size, T>& other) = default;
/**
* @brief Raw data
@ -123,7 +123,7 @@ template<class T, size_t size> class Vector {
inline constexpr T operator[](size_t pos) const { return _data[pos]; } /**< @copydoc operator[]() */
/** @brief Equality operator */
inline bool operator==(const Vector<T, size>& other) const {
inline bool operator==(const Vector<size, T>& other) const {
for(size_t pos = 0; pos != size; ++pos)
if(!TypeTraits<T>::equals((*this)[pos], other[pos])) return false;
@ -131,13 +131,13 @@ template<class T, size_t size> class Vector {
}
/** @brief Non-equality operator */
inline bool operator!=(const Vector<T, size>& other) const {
inline bool operator!=(const Vector<size, T>& other) const {
return !operator==(other);
}
/** @brief Multiply vector */
inline Vector<T, size> operator*(T number) const {
return Vector<T, size>(*this)*=number;
inline Vector<size, T> operator*(T number) const {
return Vector<size, T>(*this)*=number;
}
/**
@ -146,7 +146,7 @@ template<class T, size_t size> class Vector {
* More efficient than operator*(), because it does the computation
* in-place.
*/
Vector<T, size>& operator*=(T number) {
Vector<size, T>& operator*=(T number) {
for(size_t i = 0; i != size; ++i)
(*this)[i] *= number;
@ -154,8 +154,8 @@ template<class T, size_t size> class Vector {
}
/** @brief Divide vector */
inline Vector<T, size> operator/(T number) const {
return Vector<T, size>(*this)/=number;
inline Vector<size, T> operator/(T number) const {
return Vector<size, T>(*this)/=number;
}
/**
@ -164,7 +164,7 @@ template<class T, size_t size> class Vector {
* More efficient than operator/(), because it does the computation
* in-place.
*/
Vector<T, size>& operator/=(T number) {
Vector<size, T>& operator/=(T number) {
for(size_t i = 0; i != size; ++i)
(*this)[i] /= number;
@ -172,8 +172,8 @@ template<class T, size_t size> class Vector {
}
/** @brief Add two vectors */
inline Vector<T, size> operator+(const Vector<T, size>& other) const {
return Vector<T, size>(*this)+=other;
inline Vector<size, T> operator+(const Vector<size, T>& other) const {
return Vector<size, T>(*this)+=other;
}
/**
@ -182,7 +182,7 @@ template<class T, size_t size> class Vector {
* More efficient than operator+(), because it does the computation
* in-place.
*/
Vector<T, size>& operator+=(const Vector<T, size>& other) {
Vector<size, T>& operator+=(const Vector<size, T>& other) {
for(size_t i = 0; i != size; ++i)
(*this)[i] += other[i];
@ -190,8 +190,8 @@ template<class T, size_t size> class Vector {
}
/** @brief Substract two vectors */
inline Vector<T, size> operator-(const Vector<T, size>& other) const {
return Vector<T, size>(*this)-=other;
inline Vector<size, T> operator-(const Vector<size, T>& other) const {
return Vector<size, T>(*this)-=other;
}
/**
@ -200,7 +200,7 @@ template<class T, size_t size> class Vector {
* More efficient than operator-(), because it does the computation
* in-place.
*/
Vector<T, size>& operator-=(const Vector<T, size>& other) {
Vector<size, T>& operator-=(const Vector<size, T>& other) {
for(size_t i = 0; i != size; ++i)
(*this)[i] -= other[i];
@ -208,8 +208,8 @@ template<class T, size_t size> class Vector {
}
/** @brief Negative vector */
Vector<T, size> operator-() const {
Vector<T, size> out;
Vector<size, T> operator-() const {
Vector<size, T> out;
for(size_t i = 0; i != size; ++i)
out[i] = -(*this)[i];
@ -239,7 +239,7 @@ template<class T, size_t size> class Vector {
}
/** @brief Normalized vector (of length 1) */
inline Vector<T, size> normalized() const {
inline Vector<size, T> normalized() const {
return *this/length();
}
@ -258,7 +258,7 @@ template<class T, size_t size> class Vector {
};
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class T, size_t size> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector<T, size>& value) {
template<class T, size_t size> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector<size, T>& value) {
debug << "Vector(";
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false);
for(size_t i = 0; i != size; ++i) {

38
src/Math/Vector2.h

@ -24,7 +24,7 @@
namespace Magnum { namespace Math {
/** @brief Two-component vector */
template<class T> class Vector2: public Vector<T, 2> {
template<class T> class Vector2: public Vector<2, T> {
public:
/** @copydoc Vector::from(T*) */
inline constexpr static Vector2<T>& from(T* data) {
@ -37,17 +37,17 @@ template<class T> class Vector2: public Vector<T, 2> {
}
/** @copydoc Vector::Vector(T) */
inline constexpr explicit Vector2(T value = T()): Vector<T, 2>(value, value) {}
inline constexpr explicit Vector2(T value = T()): Vector<2, T>(value, value) {}
/** @copydoc Vector::Vector(const Vector&) */
inline constexpr Vector2(const Vector<T, 2>& other): Vector<T, 2>(other) {}
inline constexpr Vector2(const Vector<2, T>& other): Vector<2, T>(other) {}
/**
* @brief Constructor
* @param x X value
* @param y Y value
*/
inline constexpr Vector2(T x, T y): Vector<T, 2>(x, y) {}
inline constexpr Vector2(T x, T y): Vector<2, T>(x, y) {}
inline constexpr T x() const { return (*this)[0]; } /**< @brief X component */
inline constexpr T y() const { return (*this)[1]; } /**< @brief Y component */
@ -57,56 +57,56 @@ template<class T> class Vector2: public Vector<T, 2> {
/** @copydoc Vector::operator=() */
inline Vector2<T>& operator=(const Vector2<T>& other) {
Vector<T, 2>::operator=(other);
Vector<2, T>::operator=(other);
return *this;
}
/** @copydoc Vector::operator*(T) const */
inline Vector2<T> operator*(T number) const { return Vector<T, 2>::operator*(number); }
inline Vector2<T> operator*(T number) const { return Vector<2, T>::operator*(number); }
/** @copydoc Vector::operator*=() */
inline Vector2<T>& operator*=(T number) {
Vector<T, 2>::operator*=(number);
Vector<2, T>::operator*=(number);
return *this;
}
/** @copydoc Vector::operator/() */
inline Vector2<T> operator/(T number) const { return Vector<T, 2>::operator/(number); }
inline Vector2<T> operator/(T number) const { return Vector<2, T>::operator/(number); }
/** @copydoc Vector::operator/=() */
inline Vector2<T>& operator/=(T number) {
Vector<T, 2>::operator/=(number);
Vector<2, T>::operator/=(number);
return *this;
}
/** @copydoc Vector::operator+() */
inline Vector2<T> operator+(const Vector<T, 2>& other) const { return Vector<T, 2>::operator+(other); }
inline Vector2<T> operator+(const Vector<2, T>& other) const { return Vector<2, T>::operator+(other); }
/** @copydoc Vector::operator+=() */
inline Vector2<T>& operator+=(const Vector<T, 2>& other) {
Vector<T, 2>::operator+=(other);
inline Vector2<T>& operator+=(const Vector<2, T>& other) {
Vector<2, T>::operator+=(other);
return *this;
}
/** @copydoc Vector::operator-(const Vector<T, size>&) const */
inline Vector2<T> operator-(const Vector<T, 2>& other) const { return Vector<T, 2>::operator-(other); }
/** @copydoc Vector::operator-(const Vector<size, T>&) const */
inline Vector2<T> operator-(const Vector<2, T>& other) const { return Vector<2, T>::operator-(other); }
/** @copydoc Vector::operator-=() */
inline Vector2<T>& operator-=(const Vector<T, 2>& other) {
Vector<T, 2>::operator-=(other);
inline Vector2<T>& operator-=(const Vector<2, T>& other) {
Vector<2, T>::operator-=(other);
return *this;
}
/** @copydoc Vector::operator-() */
inline Vector2<T> operator-() const { return Vector<T, 2>::operator-(); }
inline Vector2<T> operator-() const { return Vector<2, T>::operator-(); }
/** @copydoc Vector::normalized() */
inline Vector2<T> normalized() const { return Vector<T, 2>::normalized(); }
inline Vector2<T> normalized() const { return Vector<2, T>::normalized(); }
};
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector2<T>& value) {
return debug << static_cast<const Magnum::Math::Vector<T, 2>&>(value);
return debug << static_cast<const Magnum::Math::Vector<2, T>&>(value);
}
#endif

40
src/Math/Vector3.h

@ -24,7 +24,7 @@
namespace Magnum { namespace Math {
/** @brief Three-component vector */
template<class T> class Vector3: public Vector<T, 3> {
template<class T> class Vector3: public Vector<3, T> {
public:
/** @copydoc Vector::from(T*) */
inline constexpr static Vector3<T>& from(T* data) {
@ -60,10 +60,10 @@ template<class T> class Vector3: public Vector<T, 3> {
}
/** @copydoc Vector::Vector(T) */
inline constexpr explicit Vector3(T value = T()): Vector<T, 3>(value, value, value) {}
inline constexpr explicit Vector3(T value = T()): Vector<3, T>(value, value, value) {}
/** @copydoc Vector::Vector(const Vector&) */
inline constexpr Vector3(const Vector<T, 3>& other): Vector<T, 3>(other) {}
inline constexpr Vector3(const Vector<3, T>& other): Vector<3, T>(other) {}
/**
* @brief Constructor
@ -71,14 +71,14 @@ template<class T> class Vector3: public Vector<T, 3> {
* @param y Y / G value
* @param z Z / B value
*/
inline constexpr Vector3(T x, T y, T z): Vector<T, 3>(x, y, z) {}
inline constexpr Vector3(T x, T y, T z): Vector<3, T>(x, y, z) {}
/**
* @brief Constructor
* @param other Two component vector
* @param z Z / B value
*/
inline constexpr Vector3(const Vector<T, 2>& other, T z = T(0)): Vector<T, 3>(other[0], other[1], z) {}
inline constexpr Vector3(const Vector<2, T>& other, T z = T(0)): Vector<3, T>(other[0], other[1], z) {}
inline constexpr T x() const { return (*this)[0]; } /**< @brief X component */
inline constexpr T y() const { return (*this)[1]; } /**< @brief Y component */
@ -98,56 +98,56 @@ template<class T> class Vector3: public Vector<T, 3> {
/** @copydoc Vector::operator=() */
inline Vector3<T>& operator=(const Vector3<T>& other) {
Vector<T, 3>::operator=(other);
Vector<3, T>::operator=(other);
return *this;
}
/** @copydoc Vector::operator*(T) const */
inline Vector3<T> operator*(T number) const { return Vector<T, 3>::operator*(number); }
inline Vector3<T> operator*(T number) const { return Vector<3, T>::operator*(number); }
/** @copydoc Vector::operator*=() */
inline Vector3<T>& operator*=(T number) {
Vector<T, 3>::operator*=(number);
Vector<3, T>::operator*=(number);
return *this;
}
/** @copydoc Vector::operator/() */
inline Vector3<T> operator/(T number) const { return Vector<T, 3>::operator/(number); }
inline Vector3<T> operator/(T number) const { return Vector<3, T>::operator/(number); }
/** @copydoc Vector::operator/=() */
inline Vector3<T>& operator/=(T number) {
Vector<T, 3>::operator/=(number);
Vector<3, T>::operator/=(number);
return *this;
}
/** @copydoc Vector::operator+() */
inline Vector3<T> operator+(const Vector<T, 3>& other) const { return Vector<T, 3>::operator+(other); }
inline Vector3<T> operator+(const Vector<3, T>& other) const { return Vector<3, T>::operator+(other); }
/** @copydoc Vector::operator+=() */
inline Vector3<T>& operator+=(const Vector<T, 3>& other) {
Vector<T, 3>::operator+=(other);
inline Vector3<T>& operator+=(const Vector<3, T>& other) {
Vector<3, T>::operator+=(other);
return *this;
}
/** @copydoc Vector::operator-(const Vector<T, size>&) const */
inline Vector3<T> operator-(const Vector<T, 3>& other) const { return Vector<T, 3>::operator-(other); }
/** @copydoc Vector::operator-(const Vector<size, T>&) const */
inline Vector3<T> operator-(const Vector<3, T>& other) const { return Vector<3, T>::operator-(other); }
/** @copydoc Vector::operator-=() */
inline Vector3<T>& operator-=(const Vector<T, 3>& other) {
Vector<T, 3>::operator-=(other);
inline Vector3<T>& operator-=(const Vector<3, T>& other) {
Vector<3, T>::operator-=(other);
return *this;
}
/** @copydoc Vector::operator-() */
inline Vector3<T> operator-() const { return Vector<T, 3>::operator-(); }
inline Vector3<T> operator-() const { return Vector<3, T>::operator-(); }
/** @copydoc Vector::normalized() */
inline Vector3<T> normalized() const { return Vector<T, 3>::normalized(); }
inline Vector3<T> normalized() const { return Vector<3, T>::normalized(); }
};
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector3<T>& value) {
return debug << static_cast<const Magnum::Math::Vector<T, 3>&>(value);
return debug << static_cast<const Magnum::Math::Vector<3, T>&>(value);
}
#endif

44
src/Math/Vector4.h

@ -24,7 +24,7 @@
namespace Magnum { namespace Math {
/** @brief Four-component vector */
template<class T> class Vector4: public Vector<T, 4> {
template<class T> class Vector4: public Vector<4, T> {
public:
/** @copydoc Vector::from(T*) */
inline constexpr static Vector4<T>& from(T* data) {
@ -41,13 +41,13 @@ template<class T> class Vector4: public Vector<T, 4> {
*
* W / A component is set to one.
*/
inline constexpr Vector4(): Vector<T, 4>(T(0), T(0), T(0), T(1)) {}
inline constexpr Vector4(): Vector<4, T>(T(0), T(0), T(0), T(1)) {}
/** @copydoc Vector::Vector(T) */
inline constexpr explicit Vector4(T value): Vector<T, 4>(value, value, value, value) {}
inline constexpr explicit Vector4(T value): Vector<4, T>(value, value, value, value) {}
/** @copydoc Vector::Vector(const Vector&) */
inline constexpr Vector4(const Vector<T, 4>& other): Vector<T, 4>(other) {}
inline constexpr Vector4(const Vector<4, T>& other): Vector<4, T>(other) {}
/**
* @brief Constructor
@ -56,14 +56,14 @@ template<class T> class Vector4: public Vector<T, 4> {
* @param z Z / B value
* @param w W / A value
*/
inline constexpr Vector4(T x, T y, T z, T w = T(1)): Vector<T, 4>(x, y, z, w) {}
inline constexpr Vector4(T x, T y, T z, T w = T(1)): Vector<4, T>(x, y, z, w) {}
/**
* @brief Constructor
* @param other Three component vector
* @param w W / A value
*/
inline constexpr Vector4(const Vector<T, 3>& other, T w = T(1)): Vector<T, 4>(other[0], other[1], other[2], w) {}
inline constexpr Vector4(const Vector<3, T>& other, T w = T(1)): Vector<4, T>(other[0], other[1], other[2], w) {}
inline constexpr T x() const { return (*this)[0]; } /**< @brief X component */
inline constexpr T y() const { return (*this)[1]; } /**< @brief Y component */
@ -79,7 +79,7 @@ template<class T> class Vector4: public Vector<T, 4> {
* @brief XYZ part of the vector
* @return First three components of the vector
*/
inline constexpr Vector3<T> xyz() const { return Vector3<T>::from(Vector<T, 4>::data()); }
inline constexpr Vector3<T> xyz() const { return Vector3<T>::from(Vector<4, T>::data()); }
inline constexpr T r() const { return x(); } /**< @brief R component */
inline constexpr T g() const { return y(); } /**< @brief G component */
@ -99,56 +99,56 @@ template<class T> class Vector4: public Vector<T, 4> {
/** @copydoc Vector::operator=() */
inline Vector4<T>& operator=(const Vector4<T>& other) {
Vector<T, 4>::operator=(other);
Vector<4, T>::operator=(other);
return *this;
}
/** @copydoc Vector::operator*(T) const */
inline Vector4<T> operator*(T number) const { return Vector<T, 4>::operator*(number); }
inline Vector4<T> operator*(T number) const { return Vector<4, T>::operator*(number); }
/** @copydoc Vector::operator*=() */
inline Vector4<T>& operator*=(T number) {
Vector<T, 4>::operator*=(number);
Vector<4, T>::operator*=(number);
return *this;
}
/** @copydoc Vector::operator/() */
inline Vector4<T> operator/(T number) const { return Vector<T, 4>::operator/(number); }
inline Vector4<T> operator/(T number) const { return Vector<4, T>::operator/(number); }
/** @copydoc Vector::operator/=() */
inline Vector4<T>& operator/=(T number) {
Vector<T, 4>::operator/=(number);
Vector<4, T>::operator/=(number);
return *this;
}
/** @copydoc Vector::operator+() */
inline Vector4<T> operator+(const Vector<T, 4>& other) const { return Vector<T, 4>::operator+(other); }
inline Vector4<T> operator+(const Vector<4, T>& other) const { return Vector<4, T>::operator+(other); }
/** @copydoc Vector::operator+=() */
inline Vector4<T>& operator+=(const Vector<T, 4>& other) {
Vector<T, 4>::operator+=(other);
inline Vector4<T>& operator+=(const Vector<4, T>& other) {
Vector<4, T>::operator+=(other);
return *this;
}
/** @copydoc Vector::operator-(const Vector<T, size>&) const */
inline Vector4<T> operator-(const Vector<T, 4>& other) const { return Vector<T, 4>::operator-(other); }
/** @copydoc Vector::operator-(const Vector<size, T>&) const */
inline Vector4<T> operator-(const Vector<4, T>& other) const { return Vector<4, T>::operator-(other); }
/** @copydoc Vector::operator-=() */
inline Vector4<T>& operator-=(const Vector<T, 4>& other) {
Vector<T, 4>::operator-=(other);
inline Vector4<T>& operator-=(const Vector<4, T>& other) {
Vector<4, T>::operator-=(other);
return *this;
}
/** @copydoc Vector::operator-() */
inline Vector4<T> operator-() const { return Vector<T, 4>::operator-(); }
inline Vector4<T> operator-() const { return Vector<4, T>::operator-(); }
/** @copydoc Vector::normalized() */
inline Vector4<T> normalized() const { return Vector<T, 4>::normalized(); }
inline Vector4<T> normalized() const { return Vector<4, T>::normalized(); }
};
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector4<T>& value) {
return debug << static_cast<const Magnum::Math::Vector<T, 4>&>(value);
return debug << static_cast<const Magnum::Math::Vector<4, T>&>(value);
}
#endif

6
src/MeshTools/Clean.h

@ -64,7 +64,7 @@ template<class Vertex, size_t vertexSize = Vertex::Size> class Clean {
/* Under each index is pointer to face which contains given vertex
and index of vertex in the face. */
std::unordered_map<Math::Vector<size_t, vertexSize>, HashedVertex, IndexHash> table;
std::unordered_map<Math::Vector<vertexSize, size_t>, HashedVertex, IndexHash> table;
/* Reserve space for all vertices */
table.reserve(vertices.size());
@ -80,7 +80,7 @@ template<class Vertex, size_t vertexSize = Vertex::Size> class Clean {
exists, change vertex pointer of the face to already
existing vertex */
HashedVertex v(*it, table.size());
auto result = table.insert(std::pair<Math::Vector<size_t, vertexSize>, HashedVertex>(Math::Vector<size_t, vertexSize>::from(index), v));
auto result = table.insert(std::pair<Math::Vector<vertexSize, size_t>, HashedVertex>(Math::Vector<vertexSize, size_t>::from(index), v));
*it = result.first->second.newIndex;
}
@ -101,7 +101,7 @@ template<class Vertex, size_t vertexSize = Vertex::Size> class Clean {
private:
class IndexHash {
public:
inline size_t operator()(const Math::Vector<size_t, vertexSize>& data) const {
inline size_t operator()(const Math::Vector<vertexSize, size_t>& data) const {
return *reinterpret_cast<const size_t*>(Corrade::Utility::MurmurHash2()(reinterpret_cast<const char*>(&data), sizeof(data)).byteArray());
}
};

10
src/MeshTools/CombineIndexedArrays.h

@ -43,7 +43,7 @@ class CombineIndexedArrays {
std::iota(result.begin(), result.end(), 0);
/* All index combinations */
std::vector<Math::Vector<unsigned int, sizeof...(indexedArrays)> > indexCombinations(_indexCount);
std::vector<Math::Vector<sizeof...(indexedArrays), unsigned int> > indexCombinations(_indexCount);
writeCombinedIndices(indexCombinations, std::get<0>(indexedArrays)...);
/* Make the combinations unique */
@ -62,7 +62,7 @@ class CombineIndexedArrays {
return first.size();
}
template<size_t size, class ...T> static void writeCombinedIndices(std::vector<Math::Vector<unsigned int, size>>& output, const std::vector<unsigned int>& first, const std::vector<T>&... next) {
template<size_t size, class ...T> static void writeCombinedIndices(std::vector<Math::Vector<size, unsigned int>>& output, const std::vector<unsigned int>& first, const std::vector<T>&... next) {
/* Copy the data to output */
for(size_t i = 0; i != output.size(); ++i)
output[i][size-sizeof...(next)-1] = first[i];
@ -70,7 +70,7 @@ class CombineIndexedArrays {
writeCombinedIndices(output, next...);
}
template<size_t size, class T, class ...U> static void writeCombinedArrays(const std::vector<Math::Vector<unsigned int, size>>& combinedIndices, std::vector<T>& first, std::vector<U>&... next) {
template<size_t size, class T, class ...U> static void writeCombinedArrays(const std::vector<Math::Vector<size, unsigned int>>& combinedIndices, std::vector<T>& first, std::vector<U>&... next) {
/* Rewrite output array */
std::vector<T> output;
for(size_t i = 0; i != combinedIndices.size(); ++i)
@ -82,8 +82,8 @@ class CombineIndexedArrays {
/* Terminator functions for recursive calls */
inline static size_t indexCount() { return 0; }
template<size_t size> inline static void writeCombinedIndices(std::vector<Math::Vector<unsigned int, size>>&) {}
template<size_t size> inline static void writeCombinedArrays(const std::vector<Math::Vector<unsigned int, size>>&) {}
template<size_t size> inline static void writeCombinedIndices(std::vector<Math::Vector<size, unsigned int>>&) {}
template<size_t size> inline static void writeCombinedArrays(const std::vector<Math::Vector<size, unsigned int>>&) {}
};
}

4
src/Texture.h

@ -120,7 +120,7 @@ template<size_t textureDimensions> class Texture: public AbstractTexture {
* see @ref AbstractTexture::Wrapping "Wrapping" documentation for
* more information.
*/
inline void setWrapping(const Math::Vector<Wrapping, Dimensions>& wrapping) {
inline void setWrapping(const Math::Vector<Dimensions, Wrapping>& wrapping) {
bind();
DataHelper<Dimensions>::setWrapping(_target, wrapping);
}
@ -150,7 +150,7 @@ template<size_t textureDimensions> class Texture: public AbstractTexture {
* Sets texture subdata from given image. The image is not deleted
* afterwards.
*/
template<class T> inline void setSubData(GLint mipLevel, const Math::Vector<GLint, Dimensions>& offset, T* image) {
template<class T> inline void setSubData(GLint mipLevel, const Math::Vector<Dimensions, GLint>& offset, T* image) {
bind();
DataHelper<Dimensions>::setSub(_target, mipLevel, offset, image);
}

8
src/Trade/ImageData.h

@ -44,7 +44,7 @@ template<size_t imageDimensions> class ImageData: public AbstractImage {
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
template<class T> inline ImageData(const Math::Vector<GLsizei, Dimensions>& dimensions, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _dimensions(dimensions), _data(reinterpret_cast<char*>(data)) {}
template<class T> inline ImageData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, T* data): AbstractImage(components, TypeTraits<T>::imageType()), _dimensions(dimensions), _data(reinterpret_cast<char*>(data)) {}
/**
* @brief Constructor
@ -56,19 +56,19 @@ template<size_t imageDimensions> class ImageData: public AbstractImage {
* Note that the image data are not copied on construction, but they
* are deleted on class destruction.
*/
inline ImageData(const Math::Vector<GLsizei, Dimensions>& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _dimensions(dimensions), _data(reinterpret_cast<char*>(data)) {}
inline ImageData(const Math::Vector<Dimensions, GLsizei>& dimensions, Components components, ComponentType type, GLvoid* data): AbstractImage(components, type), _dimensions(dimensions), _data(reinterpret_cast<char*>(data)) {}
/** @brief Destructor */
inline virtual ~ImageData() { delete[] _data; }
/** @brief %Image dimensions */
inline const Math::Vector<GLsizei, Dimensions>& dimensions() const { return _dimensions; }
inline const Math::Vector<Dimensions, GLsizei>& dimensions() const { return _dimensions; }
/** @brief Pointer to raw data */
inline const void* data() const { return _data; }
private:
Math::Vector<GLsizei, Dimensions> _dimensions;
Math::Vector<Dimensions, GLsizei> _dimensions;
char* _data;
};

14
src/TypeTraits.h

@ -210,7 +210,7 @@ template<> struct TypeTraits<GLdouble>: public Math::TypeTraits<double> {
inline constexpr static size_t count() { return 1; }
};
template<class T, size_t vectorSize> struct TypeTraits<Math::Vector<T, vectorSize>> {
template<class T, size_t vectorSize> struct TypeTraits<Math::Vector<vectorSize, T>> {
inline constexpr static Type type() { return TypeTraits<T>::type(); }
/* Can not be used for indices */
/* Can not be used for images */
@ -218,11 +218,11 @@ template<class T, size_t vectorSize> struct TypeTraits<Math::Vector<T, vectorSiz
inline constexpr static size_t count() { return vectorSize; }
};
template<class T> struct TypeTraits<Math::Vector2<T>>: public TypeTraits<Math::Vector<T, 2>> {};
template<class T> struct TypeTraits<Math::Vector3<T>>: public TypeTraits<Math::Vector<T, 3>> {};
template<class T> struct TypeTraits<Math::Vector4<T>>: public TypeTraits<Math::Vector<T, 4>> {};
template<class T> struct TypeTraits<Math::Vector2<T>>: public TypeTraits<Math::Vector<2, T>> {};
template<class T> struct TypeTraits<Math::Vector3<T>>: public TypeTraits<Math::Vector<3, T>> {};
template<class T> struct TypeTraits<Math::Vector4<T>>: public TypeTraits<Math::Vector<4, T>> {};
template<class T, size_t matrixSize> struct TypeTraits<Math::Matrix<T, matrixSize>> {
template<class T, size_t matrixSize> struct TypeTraits<Math::Matrix<matrixSize, T>> {
inline constexpr static Type type() { return TypeTraits<T>::type(); }
/* Can not be used for indices */
/* Can not be used for images */
@ -230,8 +230,8 @@ template<class T, size_t matrixSize> struct TypeTraits<Math::Matrix<T, matrixSiz
inline constexpr static size_t count() { return matrixSize*matrixSize; }
};
template<class T> struct TypeTraits<Math::Matrix3<T>>: public TypeTraits<Math::Matrix<T, 3>> {};
template<class T> struct TypeTraits<Math::Matrix4<T>>: public TypeTraits<Math::Matrix<T, 4>> {};
template<class T> struct TypeTraits<Math::Matrix3<T>>: public TypeTraits<Math::Matrix<3, T>> {};
template<class T> struct TypeTraits<Math::Matrix4<T>>: public TypeTraits<Math::Matrix<4, T>> {};
#endif
}

Loading…
Cancel
Save