Browse Source

Math: more explicit default zero/identity constructors.

Some classes are by default constructed zero-filled while other are set
to identity and the only way to to check this is to look into the
documentation. This changes the default constructor of all classes to
take an optional "tag" which acts as documentation about how the type is
constructed. Note that this result in no behavioral changes, just
ability to be more explicit when writing the code. Example:

    // These two are equivalent
    Quaternion q1;
    Quaternion q2{Math::IdentityInit};

    // These two are equivalent
    Vector4 vec1;
    Vector4 vec2{Math::ZeroInit};

    Matrix4 a{Math::IdentityInit, 2}; // 2 on diagonal
    Matrix4 b{Math::ZeroInit};        // all zero

This functionality was already present in some ugly form in Matrix,
Matrix3 and Matrix4 classes. It was long and ugly to write, so it is
now generalized into the new Math::IdentityInit and Math::ZeroInit tags,
the original Matrix::IdentityType, Matrix::Identity, Matrix::ZeroType
and Matrix::Zero are deprecated and will be removed in the future
release.

    Math::Matrix<7, Int> m{Math::Matrix<7, Int>::Identity}; // before
    Math::Matrix<7, Int> m{Math::IdentityInit};             // now
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
3a8ac02909
  1. 2
      src/Magnum/Color.h
  2. 4
      src/Magnum/Math/Algorithms/Svd.h
  3. 8
      src/Magnum/Math/Algorithms/Test/SvdTest.cpp
  4. 6
      src/Magnum/Math/Angle.h
  5. 3
      src/Magnum/Math/BoolVector.h
  6. 2
      src/Magnum/Math/Complex.h
  7. 4
      src/Magnum/Math/DualComplex.h
  8. 4
      src/Magnum/Math/DualQuaternion.h
  9. 39
      src/Magnum/Math/Matrix.h
  10. 13
      src/Magnum/Math/Matrix3.h
  11. 13
      src/Magnum/Math/Matrix4.h
  12. 2
      src/Magnum/Math/Quaternion.h
  13. 12
      src/Magnum/Math/Range.h
  14. 5
      src/Magnum/Math/RectangularMatrix.h
  15. 18
      src/Magnum/Math/Test/AngleTest.cpp
  16. 2
      src/Magnum/Math/Test/BoolVectorTest.cpp
  17. 9
      src/Magnum/Math/Test/ComplexTest.cpp
  18. 9
      src/Magnum/Math/Test/DualComplexTest.cpp
  19. 9
      src/Magnum/Math/Test/DualQuaternionTest.cpp
  20. 6
      src/Magnum/Math/Test/Matrix3Test.cpp
  21. 6
      src/Magnum/Math/Test/Matrix4Test.cpp
  22. 6
      src/Magnum/Math/Test/MatrixTest.cpp
  23. 9
      src/Magnum/Math/Test/QuaternionTest.cpp
  24. 20
      src/Magnum/Math/Test/RangeTest.cpp
  25. 5
      src/Magnum/Math/Test/RectangularMatrixTest.cpp
  26. 2
      src/Magnum/Math/Test/Vector2Test.cpp
  27. 2
      src/Magnum/Math/Test/Vector3Test.cpp
  28. 2
      src/Magnum/Math/Test/Vector4Test.cpp
  29. 2
      src/Magnum/Math/Test/VectorTest.cpp
  30. 5
      src/Magnum/Math/Unit.h
  31. 2
      src/Magnum/Math/Vector.h
  32. 4
      src/Magnum/Math/Vector2.h
  33. 4
      src/Magnum/Math/Vector3.h
  34. 4
      src/Magnum/Math/Vector4.h
  35. 12
      src/Magnum/SceneGraph/Test/ObjectTest.cpp
  36. 2
      src/Magnum/Shapes/Box.h
  37. 6
      src/Magnum/Test/ColorTest.cpp

2
src/Magnum/Color.h

@ -254,7 +254,7 @@ template<class T> class BasicColor3: public Math::Vector3<T> {
*
* All components are set to zero.
*/
constexpr /*implicit*/ BasicColor3() {}
constexpr /*implicit*/ BasicColor3(Math::ZeroInitT = Math::ZeroInit): Math::Vector3<T>{Math::ZeroInit} {}
/**
* @brief Gray constructor

4
src/Magnum/Math/Algorithms/Svd.h

@ -102,7 +102,7 @@ template<std::size_t cols, std::size_t rows, class T> std::tuple<RectangularMatr
static_assert(tol > T(0), "Tol too small");
constexpr std::size_t maxIterations = 50;
Matrix<cols, T> v(Matrix<cols, T>::Zero);
Matrix<cols, T> v{ZeroInit};
Vector<cols, T> e, q;
/* Householder's reduction to bidiagonal form */
@ -270,7 +270,7 @@ template<std::size_t cols, std::size_t rows, class T> std::tuple<RectangularMatr
/* Exceeded iteration count, done */
} else if(iteration >= maxIterations-1) {
Corrade::Utility::Error() << "Magnum::Math::Algorithms::svd(): no convergence";
return std::make_tuple(RectangularMatrix<cols, rows, T>(), Vector<cols, T>(), Matrix<cols, T>(Matrix<cols, T>::Zero));
return std::make_tuple(RectangularMatrix<cols, rows, T>{}, Vector<cols, T>{}, Matrix<cols, T>{ZeroInit});
}
/* Shift from bottom 2x2 minor */

8
src/Magnum/Math/Algorithms/Test/SvdTest.cpp

@ -88,8 +88,8 @@ void SvdTest::testDouble() {
CORRADE_COMPARE(u2*w2*v.transposed(), ad);
/* Test that V is unitary */
CORRADE_COMPARE(v*v.transposed(), Matrix5d(Matrix5d::Identity));
CORRADE_COMPARE(v.transposed()*v, Matrix5d(Matrix5d::Identity));
CORRADE_COMPARE(v*v.transposed(), Matrix5d{IdentityInit});
CORRADE_COMPARE(v.transposed()*v, Matrix5d{IdentityInit});
/* Test W */
CORRADE_COMPARE(w, expectedd);
@ -110,8 +110,8 @@ void SvdTest::testFloat() {
CORRADE_VERIFY(Math::abs((u2*w2*v.transposed()-af).toVector()).max() < 1.0e-5f);
/* Test that V is unitary */
CORRADE_COMPARE(v*v.transposed(), Matrix5f(Matrix5f::Identity));
CORRADE_COMPARE(v.transposed()*v, Matrix5f(Matrix5f::Identity));
CORRADE_COMPARE(v*v.transposed(), Matrix5f{IdentityInit});
CORRADE_COMPARE(v.transposed()*v, Matrix5f{IdentityInit});
/* Test W (single precision is not enough, test for similarity) */
CORRADE_VERIFY(Math::abs(w-expectedf).max() < 1.0e-5f);

6
src/Magnum/Math/Angle.h

@ -123,8 +123,8 @@ std::sin(Float(Rad<Float>(b)); // required explicit conversion hints to user
*/
template<class T> class Deg: public Unit<Deg, T> {
public:
/** @brief Default constructor */
constexpr /*implicit*/ Deg() {}
/** @brief Construct zero angle */
constexpr /*implicit*/ Deg(ZeroInitT = ZeroInit): Unit<Deg, T>{ZeroInit} {}
/** @brief Explicit constructor from unitless type */
constexpr explicit Deg(T value): Unit<Math::Deg, T>(value) {}
@ -182,7 +182,7 @@ See @ref Deg for more information.
template<class T> class Rad: public Unit<Rad, T> {
public:
/** @brief Default constructor */
constexpr /*implicit*/ Rad() {}
constexpr /*implicit*/ Rad(ZeroInitT = ZeroInit): Unit<Rad, T>{ZeroInit} {}
/** @brief Construct from unitless type */
constexpr explicit Rad(T value): Unit<Math::Rad, T>(value) {}

3
src/Magnum/Math/BoolVector.h

@ -33,6 +33,7 @@
#include <Corrade/Utility/Debug.h>
#include "Magnum/Types.h"
#include "Magnum/Math/Tags.h"
namespace Magnum { namespace Math {
@ -70,7 +71,7 @@ template<std::size_t size> class BoolVector {
static const std::size_t DataSize = (size-1)/8+1; /**< @brief Vector storage size */
/** @brief Construct zero-filled boolean vector */
constexpr BoolVector(): _data() {}
constexpr /*implicit*/ BoolVector(ZeroInitT = ZeroInit): _data{} {}
/**
* @brief Construct boolean vector from segment values

2
src/Magnum/Math/Complex.h

@ -140,7 +140,7 @@ template<class T> class Complex {
* c = 1 + i0
* @f]
*/
constexpr /*implicit*/ Complex(): _real(T(1)), _imaginary(T(0)) {}
constexpr /*implicit*/ Complex(IdentityInitT = IdentityInit): _real(T(1)), _imaginary(T(0)) {}
/**
* @brief Construct complex number from real and imaginary part

4
src/Magnum/Math/DualComplex.h

@ -104,9 +104,9 @@ template<class T> class DualComplex: public Dual<Complex<T>> {
* @f]
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
constexpr /*implicit*/ DualComplex();
constexpr /*implicit*/ DualComplex(IdentityInitT = IdentityInit);
#else
constexpr /*implicit*/ DualComplex(): Dual<Complex<T>>({}, {T(0), T(0)}) {}
constexpr /*implicit*/ DualComplex(IdentityInitT = IdentityInit): Dual<Complex<T>>({}, {T(0), T(0)}) {}
#endif
/**

4
src/Magnum/Math/DualQuaternion.h

@ -110,9 +110,9 @@ template<class T> class DualQuaternion: public Dual<Quaternion<T>> {
* @f]
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
constexpr /*implicit*/ DualQuaternion();
constexpr /*implicit*/ DualQuaternion(IdentityInitT = IdentityInit);
#else
constexpr /*implicit*/ DualQuaternion(): Dual<Quaternion<T>>({}, {{}, T(0)}) {}
constexpr /*implicit*/ DualQuaternion(IdentityInitT = IdentityInit): Dual<Quaternion<T>>({}, {{}, T(0)}) {}
#endif
/**

39
src/Magnum/Math/Matrix.h

@ -51,27 +51,40 @@ template<std::size_t size, class T> class Matrix: public RectangularMatrix<size,
public:
const static std::size_t Size = size; /**< @brief Matrix size */
/** @brief Pass to constructor to create zero-filled matrix */
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Pass to constructor to create zero-filled matrix
* @deprecated Use @ref ZeroInitT and @ref ZeroInit instead.
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
enum ZeroType { Zero };
#else
CORRADE_DEPRECATED("use Math::ZeroInitT instead") typedef ZeroInitT ZeroType;
CORRADE_DEPRECATED("use Math::ZeroInit instead") constexpr static ZeroInitT Zero{};
#endif
/**
* @brief Zero-filled matrix constructor
*
* Use this constructor by calling `Matrix m(Matrix::Zero);`.
* @brief Pass to constructor to create identity matrix
* @deprecated Use @ref IdentityInitT and @ref IdentityInit instead.
*/
constexpr explicit Matrix(ZeroType) {}
/** @brief Pass to constructor to create identity matrix */
#ifdef DOXYGEN_GENERATING_OUTPUT
enum IdentityType { Identity };
#else
CORRADE_DEPRECATED("use Math::IdentityInitT instead") typedef IdentityInitT IdentityType;
CORRADE_DEPRECATED("use Math::IdentityInit instead") constexpr static IdentityInitT Identity{};
#endif
#endif
/**
* @brief Default constructor
*
* You can also explicitly call this constructor with
* `Matrix m(Matrix::Identity);`. Optional parameter @p value allows
* you to specify value on diagonal.
* Creates identity matrix. @p value allows you to specify value on
* diagonal.
*/
constexpr /*implicit*/ Matrix(IdentityType = Identity, T value = T(1)): RectangularMatrix<size, size, T>(typename Implementation::GenerateSequence<size>::Type(), Vector<size, T>(value)) {}
constexpr /*implicit*/ Matrix(IdentityInitT = IdentityInit, T value = T(1)): RectangularMatrix<size, size, T>(typename Implementation::GenerateSequence<size>::Type(), Vector<size, T>(value)) {}
/** @copydoc RectangularMatrix::RectangularMatrix(ZeroInitT) */
constexpr explicit Matrix(ZeroInitT): RectangularMatrix<size, size, T>{ZeroInit} {}
/**
* @brief Matrix from column vectors
@ -291,7 +304,7 @@ template<std::size_t size, class T> bool Matrix<size, T>::isOrthogonal() const {
}
template<std::size_t size, class T> Matrix<size-1, T> Matrix<size, T>::ij(const std::size_t skipCol, const std::size_t skipRow) const {
Matrix<size-1, T> out(Matrix<size-1, T>::Zero);
Matrix<size-1, T> out{ZeroInit};
for(std::size_t col = 0; col != size-1; ++col)
for(std::size_t row = 0; row != size-1; ++row)
@ -302,7 +315,7 @@ template<std::size_t size, class T> Matrix<size-1, T> Matrix<size, T>::ij(const
}
template<std::size_t size, class T> Matrix<size, T> Matrix<size, T>::inverted() const {
Matrix<size, T> out(Zero);
Matrix<size, T> out{ZeroInit};
const T _determinant = determinant();

13
src/Magnum/Math/Matrix3.h

@ -153,17 +153,16 @@ template<class T> class Matrix3: public Matrix3x3<T> {
{ translation, T(1)}};
}
/** @copydoc Matrix::Matrix(ZeroType) */
constexpr explicit Matrix3(typename Matrix3x3<T>::ZeroType): Matrix3x3<T>(Matrix3x3<T>::Zero) {}
/**
* @brief Default constructor
*
* Creates identity matrix. You can also explicitly call this
* constructor with `Matrix3 m(Matrix3::Identity);`. Optional
* parameter @p value allows you to specify value on diagonal.
* Creates identity matrix. @p value allows you to specify value on
* diagonal.
*/
constexpr /*implicit*/ Matrix3(typename Matrix3x3<T>::IdentityType = (Matrix3x3<T>::Identity), T value = T(1)): Matrix3x3<T>(Matrix3x3<T>::Identity, value) {}
constexpr /*implicit*/ Matrix3(IdentityInitT = IdentityInit, T value = T{1}): Matrix3x3<T>{IdentityInit, value} {}
/** @copydoc Matrix::Matrix(ZeroInitT) */
constexpr explicit Matrix3(ZeroInitT): Matrix3x3<T>{ZeroInit} {}
/** @brief Matrix from column vectors */
constexpr /*implicit*/ Matrix3(const Vector3<T>& first, const Vector3<T>& second, const Vector3<T>& third): Matrix3x3<T>(first, second, third) {}

13
src/Magnum/Math/Matrix4.h

@ -249,17 +249,16 @@ template<class T> class Matrix4: public Matrix4x4<T> {
{ translation, T(1)}};
}
/** @copydoc Matrix::Matrix(ZeroType) */
constexpr explicit Matrix4(typename Matrix4x4<T>::ZeroType): Matrix4x4<T>(Matrix4x4<T>::Zero) {}
/**
* @brief Default constructor
*
* Creates identity matrix. You can also explicitly call this
* constructor with `Matrix4 m(Matrix4::Identity);`. Optional
* parameter @p value allows you to specify value on diagonal.
* Creates identity matrix. @p value allows you to specify value on
* diagonal.
*/
constexpr /*implicit*/ Matrix4(typename Matrix4x4<T>::IdentityType = (Matrix4x4<T>::Identity), T value = T(1)): Matrix4x4<T>(Matrix4x4<T>::Identity, value) {}
constexpr /*implicit*/ Matrix4(IdentityInitT = IdentityInit, T value = T{1}): Matrix4x4<T>{IdentityInit, value} {}
/** @copydoc Matrix::Matrix(ZeroInitT) */
constexpr explicit Matrix4(ZeroInitT): Matrix4x4<T>{ZeroInit} {}
/** @brief Matrix from column vectors */
constexpr /*implicit*/ Matrix4(const Vector4<T>& first, const Vector4<T>& second, const Vector4<T>& third, const Vector4<T>& fourth): Matrix4x4<T>(first, second, third, fourth) {}

2
src/Magnum/Math/Quaternion.h

@ -197,7 +197,7 @@ template<class T> class Quaternion {
* q = [\boldsymbol 0, 1]
* @f]
*/
constexpr /*implicit*/ Quaternion(): _scalar(T(1)) {}
constexpr /*implicit*/ Quaternion(IdentityInitT = IdentityInit): _vector{T(0)}, _scalar{T(1)} {}
/**
* @brief Construct quaternion from vector and scalar

12
src/Magnum/Math/Range.h

@ -75,10 +75,10 @@ template<UnsignedInt dimensions, class T> class Range {
*
* Construct zero-size range positioned at origin.
*/
constexpr Range(): _min{}, _max{} {}
constexpr /*implicit*/ Range(ZeroInitT = ZeroInit): _min{ZeroInit}, _max{ZeroInit} {}
/** @brief Construct range from minimal and maximal coordinates */
constexpr Range(const VectorType& min, const VectorType& max): _min(min), _max(max) {}
constexpr /*implicit*/ Range(const VectorType& min, const VectorType& max): _min{min}, _max{max} {}
/** @brief Copy constructor */
constexpr Range(const Range<dimensions, T>&) = default;
@ -218,8 +218,8 @@ See @ref Range for more information.
*/
template<class T> class Range2D: public Range<2, T> {
public:
/** @copydoc Range() */
constexpr /*implicit*/ Range2D() {}
/** @copydoc Range(ZeroInitT) */
constexpr /*implicit*/ Range2D(ZeroInitT = ZeroInit): Range<2, T>{ZeroInit} {}
/** @copydoc Range(const VectorType&, const VectorType&) */
constexpr /*implicit*/ Range2D(const Vector2<T>& min, const Vector2<T>& max): Range<2, T>(min, max) {}
@ -329,8 +329,8 @@ See @ref Range for more information.
*/
template<class T> class Range3D: public Range<3, T> {
public:
/** @copydoc Range() */
constexpr /*implicit*/ Range3D() {}
/** @copydoc Range(ZeroInitT) */
constexpr /*implicit*/ Range3D(ZeroInitT = ZeroInit): Range<3, T>{ZeroInit} {}
/** @copydoc Range(const VectorType&, const VectorType&) */
constexpr /*implicit*/ Range3D(const Vector3<T>& min, const Vector3<T>& max): Range<3, T>(min, max) {}

5
src/Magnum/Math/RectangularMatrix.h

@ -106,7 +106,7 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
}
/** @brief Construct zero-filled matrix */
constexpr /*implicit*/ RectangularMatrix() {}
constexpr /*implicit*/ RectangularMatrix(ZeroInitT = ZeroInit): RectangularMatrix<cols, rows, T>{typename Implementation::GenerateSequence<cols>::Type{}, ZeroInit} {}
/**
* @brief Construct matrix from column vectors
@ -361,6 +361,9 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
/* Implementation for RectangularMatrix<cols, rows, T>::RectangularMatrix(const RectangularMatrix<cols, rows, U>&) */
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])...} {}
/* Implementation for RectangularMatrix<cols, rows, T>::RectangularMatrix(ZeroInitT) */
template<class U, std::size_t ...sequence> constexpr explicit RectangularMatrix(Implementation::Sequence<sequence...>, U): _data{Vector<rows, T>{(static_cast<void>(sequence), U{})}...} {}
template<std::size_t ...sequence> constexpr Vector<DiagonalSize, T> diagonalInternal(Implementation::Sequence<sequence...>) const;
Vector<rows, T> _data[cols];

18
src/Magnum/Math/Test/AngleTest.cpp

@ -59,14 +59,20 @@ AngleTest::AngleTest() {
void AngleTest::construct() {
/* Default constructor */
constexpr Deg m;
CORRADE_COMPARE(Float(m), 0.0f);
constexpr Deg m1;
constexpr Deg m2{ZeroInit};
CORRADE_COMPARE(Float(m1), 0.0f);
CORRADE_COMPARE(Float(m2), 0.0f);
#ifndef MAGNUM_TARGET_GLES
constexpr Degd a;
CORRADE_COMPARE(Double(a), 0.0);
constexpr Radd a1;
constexpr Radd a2{ZeroInit};
CORRADE_COMPARE(Double(a1), 0.0);
CORRADE_COMPARE(Double(a2), 0.0);
#else
constexpr Deg a;
CORRADE_COMPARE(Float(a), 0.0f);
constexpr Rad a1;
constexpr Rad a2{ZeroInit};
CORRADE_COMPARE(Float(a1), 0.0f);
CORRADE_COMPARE(Float(a2), 0.0f);
#endif
/* Value constructor */

2
src/Magnum/Math/Test/BoolVectorTest.cpp

@ -85,7 +85,9 @@ void BoolVectorTest::construct() {
void BoolVectorTest::constructDefault() {
constexpr BoolVector19 a;
constexpr BoolVector19 b{ZeroInit};
CORRADE_COMPARE(a, BoolVector19(0x00, 0x00, 0x00));
CORRADE_COMPARE(b, BoolVector19(0x00, 0x00, 0x00));
}
void BoolVectorTest::constructOneValue() {

9
src/Magnum/Math/Test/ComplexTest.cpp

@ -58,7 +58,7 @@ struct ComplexTest: Corrade::TestSuite::Tester {
explicit ComplexTest();
void construct();
void constructDefault();
void constructIdentity();
void constructFromVector();
void constructCopy();
void convert();
@ -90,7 +90,7 @@ struct ComplexTest: Corrade::TestSuite::Tester {
ComplexTest::ComplexTest() {
addTests({&ComplexTest::construct,
&ComplexTest::constructDefault,
&ComplexTest::constructIdentity,
&ComplexTest::constructFromVector,
&ComplexTest::constructCopy,
&ComplexTest::convert,
@ -137,10 +137,13 @@ void ComplexTest::construct() {
CORRADE_COMPARE(c, -3.7f);
}
void ComplexTest::constructDefault() {
void ComplexTest::constructIdentity() {
constexpr Complex a;
constexpr Complex b{IdentityInit};
CORRADE_COMPARE(a, Complex(1.0f, 0.0f));
CORRADE_COMPARE(b, Complex(1.0f, 0.0f));
CORRADE_COMPARE(a.length(), 1.0f);
CORRADE_COMPARE(b.length(), 1.0f);
}
void ComplexTest::constructFromVector() {

9
src/Magnum/Math/Test/DualComplexTest.cpp

@ -58,7 +58,7 @@ struct DualComplexTest: Corrade::TestSuite::Tester {
explicit DualComplexTest();
void construct();
void constructDefault();
void constructIdentity();
void constructFromVector();
void constructCopy();
void convert();
@ -96,7 +96,7 @@ typedef Math::Vector2<Float> Vector2;
DualComplexTest::DualComplexTest() {
addTests({&DualComplexTest::construct,
&DualComplexTest::constructDefault,
&DualComplexTest::constructIdentity,
&DualComplexTest::constructFromVector,
&DualComplexTest::constructCopy,
&DualComplexTest::convert,
@ -137,10 +137,13 @@ void DualComplexTest::construct() {
CORRADE_COMPARE(d, DualComplex({-1.0f, 2.5f}, {0.0f, 0.0f}));
}
void DualComplexTest::constructDefault() {
void DualComplexTest::constructIdentity() {
constexpr DualComplex a;
constexpr DualComplex b{IdentityInit};
CORRADE_COMPARE(a, DualComplex({1.0f, 0.0f}, {0.0f, 0.0f}));
CORRADE_COMPARE(b, DualComplex({1.0f, 0.0f}, {0.0f, 0.0f}));
CORRADE_COMPARE(a.length(), 1.0f);
CORRADE_COMPARE(b.length(), 1.0f);
}
void DualComplexTest::constructFromVector() {

9
src/Magnum/Math/Test/DualQuaternionTest.cpp

@ -60,7 +60,7 @@ struct DualQuaternionTest: Corrade::TestSuite::Tester {
explicit DualQuaternionTest();
void construct();
void constructDefault();
void constructIdentity();
void constructFromVector();
void constructCopy();
void convert();
@ -97,7 +97,7 @@ typedef Math::Vector3<Float> Vector3;
DualQuaternionTest::DualQuaternionTest() {
addTests({&DualQuaternionTest::construct,
&DualQuaternionTest::constructDefault,
&DualQuaternionTest::constructIdentity,
&DualQuaternionTest::constructFromVector,
&DualQuaternionTest::constructCopy,
&DualQuaternionTest::convert,
@ -138,10 +138,13 @@ void DualQuaternionTest::construct() {
CORRADE_COMPARE(d, DualQuaternion({{1.0f, 2.0f, 3.0f}, -4.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f}));
}
void DualQuaternionTest::constructDefault() {
void DualQuaternionTest::constructIdentity() {
constexpr DualQuaternion a;
constexpr DualQuaternion b{IdentityInit};
CORRADE_COMPARE(a, DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f}));
CORRADE_COMPARE(b, DualQuaternion({{0.0f, 0.0f, 0.0f}, 1.0f}, {{0.0f, 0.0f, 0.0f}, 0.0f}));
CORRADE_COMPARE(a.length(), 1.0f);
CORRADE_COMPARE(b.length(), 1.0f);
}
void DualQuaternionTest::constructFromVector() {

6
src/Magnum/Math/Test/Matrix3Test.cpp

@ -138,8 +138,8 @@ void Matrix3Test::construct() {
void Matrix3Test::constructIdentity() {
constexpr Matrix3 identity;
constexpr Matrix3 identity2(Matrix3::Identity);
constexpr Matrix3 identity3(Matrix3::Identity, 4.0f);
constexpr Matrix3 identity2{IdentityInit};
constexpr Matrix3 identity3{IdentityInit, 4.0f};
Matrix3 identityExpected({1.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 0.0f},
@ -155,7 +155,7 @@ void Matrix3Test::constructIdentity() {
}
void Matrix3Test::constructZero() {
constexpr Matrix3 a(Matrix3::Zero);
constexpr Matrix3 a{ZeroInit};
CORRADE_COMPARE(a, Matrix3({0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f}));

6
src/Magnum/Math/Test/Matrix4Test.cpp

@ -159,8 +159,8 @@ void Matrix4Test::construct() {
void Matrix4Test::constructIdentity() {
constexpr Matrix4 identity;
constexpr Matrix4 identity2(Matrix4::Identity);
constexpr Matrix4 identity3(Matrix4::Identity, 4.0f);
constexpr Matrix4 identity2{IdentityInit};
constexpr Matrix4 identity3{IdentityInit, 4.0f};
Matrix4 identityExpected({1.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 0.0f, 0.0f},
@ -179,7 +179,7 @@ void Matrix4Test::constructIdentity() {
void Matrix4Test::constructZero() {
/* Zero constructor */
constexpr Matrix4 a(Matrix4::Zero);
constexpr Matrix4 a{ZeroInit};
CORRADE_COMPARE(a, Matrix4({0.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 0.0f},

6
src/Magnum/Math/Test/MatrixTest.cpp

@ -125,8 +125,8 @@ void MatrixTest::construct() {
void MatrixTest::constructIdentity() {
constexpr Matrix4x4 identity;
constexpr Matrix4x4 identity2(Matrix4x4::Identity);
constexpr Matrix4x4 identity3(Matrix4x4::Identity, 4.0f);
constexpr Matrix4x4 identity2{IdentityInit};
constexpr Matrix4x4 identity3{IdentityInit, 4.0f};
Matrix4x4 identityExpected(Vector4(1.0f, 0.0f, 0.0f, 0.0f),
Vector4(0.0f, 1.0f, 0.0f, 0.0f),
@ -144,7 +144,7 @@ void MatrixTest::constructIdentity() {
}
void MatrixTest::constructZero() {
constexpr Matrix4x4 a(Matrix4x4::Zero);
constexpr Matrix4x4 a{ZeroInit};
CORRADE_COMPARE(a, Matrix4x4(Vector4(0.0f, 0.0f, 0.0f, 0.0f),
Vector4(0.0f, 0.0f, 0.0f, 0.0f),
Vector4(0.0f, 0.0f, 0.0f, 0.0f),

9
src/Magnum/Math/Test/QuaternionTest.cpp

@ -58,7 +58,7 @@ struct QuaternionTest: Corrade::TestSuite::Tester {
explicit QuaternionTest();
void construct();
void constructDefault();
void constructIdentity();
void constructFromVector();
void constructCopy();
void convert();
@ -101,7 +101,7 @@ typedef Math::Vector4<Float> Vector4;
QuaternionTest::QuaternionTest() {
addTests({&QuaternionTest::construct,
&QuaternionTest::constructDefault,
&QuaternionTest::constructIdentity,
&QuaternionTest::constructFromVector,
&QuaternionTest::constructCopy,
&QuaternionTest::convert,
@ -144,10 +144,13 @@ void QuaternionTest::construct() {
CORRADE_COMPARE(c, -4.0f);
}
void QuaternionTest::constructDefault() {
void QuaternionTest::constructIdentity() {
constexpr Quaternion a;
constexpr Quaternion b{IdentityInit};
CORRADE_COMPARE(a, Quaternion({0.0f, 0.0f, 0.0f}, 1.0f));
CORRADE_COMPARE(b, Quaternion({0.0f, 0.0f, 0.0f}, 1.0f));
CORRADE_COMPARE(a.length(), 1.0f);
CORRADE_COMPARE(b.length(), 1.0f);
}
void QuaternionTest::constructFromVector() {

20
src/Magnum/Math/Test/RangeTest.cpp

@ -173,13 +173,19 @@ void RangeTest::construct() {
}
void RangeTest::constructDefault() {
constexpr Range1Di a;
constexpr Range2Di b;
constexpr Range3Di c;
CORRADE_COMPARE(a, Range1Di(0, 0));
CORRADE_COMPARE(b, Range2Di({0, 0}, {0, 0}));
CORRADE_COMPARE(c, Range3Di({0, 0, 0}, {0, 0, 0}));
constexpr Range1Di a1;
constexpr Range2Di b1;
constexpr Range3Di c1;
constexpr Range1Di a2{ZeroInit};
constexpr Range2Di b2{ZeroInit};
constexpr Range3Di c2{ZeroInit};
CORRADE_COMPARE(a1, Range1Di(0, 0));
CORRADE_COMPARE(a2, Range1Di(0, 0));
CORRADE_COMPARE(b1, Range2Di({0, 0}, {0, 0}));
CORRADE_COMPARE(b2, Range2Di({0, 0}, {0, 0}));
CORRADE_COMPARE(c1, Range3Di({0, 0, 0}, {0, 0, 0}));
CORRADE_COMPARE(c2, Range3Di({0, 0, 0}, {0, 0, 0}));
}
void RangeTest::constructFromSize() {

5
src/Magnum/Math/Test/RectangularMatrixTest.cpp

@ -148,10 +148,15 @@ void RectangularMatrixTest::construct() {
void RectangularMatrixTest::constructDefault() {
constexpr Matrix4x3 a;
constexpr Matrix4x3 b{ZeroInit};
CORRADE_COMPARE(a, Matrix4x3(Vector3(0.0f, 0.0f, 0.0f),
Vector3(0.0f, 0.0f, 0.0f),
Vector3(0.0f, 0.0f, 0.0f),
Vector3(0.0f, 0.0f, 0.0f)));
CORRADE_COMPARE(b, Matrix4x3(Vector3(0.0f, 0.0f, 0.0f),
Vector3(0.0f, 0.0f, 0.0f),
Vector3(0.0f, 0.0f, 0.0f),
Vector3(0.0f, 0.0f, 0.0f)));
}
void RectangularMatrixTest::constructConversion() {

2
src/Magnum/Math/Test/Vector2Test.cpp

@ -106,7 +106,9 @@ void Vector2Test::construct() {
void Vector2Test::constructDefault() {
constexpr Vector2 a;
constexpr Vector2 b{ZeroInit};
CORRADE_COMPARE(a, Vector2(0.0f, 0.0f));
CORRADE_COMPARE(b, Vector2(0.0f, 0.0f));
}
void Vector2Test::constructOneValue() {

2
src/Magnum/Math/Test/Vector3Test.cpp

@ -104,7 +104,9 @@ void Vector3Test::construct() {
void Vector3Test::constructDefault() {
constexpr Vector3 a;
constexpr Vector3 b{ZeroInit};
CORRADE_COMPARE(a, Vector3(0.0f, 0.0f, 0.0f));
CORRADE_COMPARE(b, Vector3(0.0f, 0.0f, 0.0f));
}
void Vector3Test::constructOneValue() {

2
src/Magnum/Math/Test/Vector4Test.cpp

@ -113,7 +113,9 @@ void Vector4Test::constructPad() {
void Vector4Test::constructDefault() {
constexpr Vector4 a;
constexpr Vector4 b{ZeroInit};
CORRADE_COMPARE(a, Vector4(0.0f, 0.0f, 0.0f, 0.0f));
CORRADE_COMPARE(b, Vector4(0.0f, 0.0f, 0.0f, 0.0f));
}
void Vector4Test::constructOneValue() {

2
src/Magnum/Math/Test/VectorTest.cpp

@ -187,7 +187,9 @@ void VectorTest::constructPad() {
void VectorTest::constructDefault() {
constexpr Vector4 a;
constexpr Vector4 b{ZeroInit};
CORRADE_COMPARE(a, Vector4(0.0f, 0.0f, 0.0f, 0.0f));
CORRADE_COMPARE(b, Vector4(0.0f, 0.0f, 0.0f, 0.0f));
}
void VectorTest::constructOneValue() {

5
src/Magnum/Math/Unit.h

@ -30,6 +30,7 @@
*/
#include "Magnum/Math/TypeTraits.h"
#include "Magnum/Math/Tags.h"
namespace Magnum { namespace Math {
@ -45,8 +46,8 @@ template<template<class> class Derived, class T> class Unit {
public:
typedef T Type; /**< @brief Underlying data type */
/** @brief Default constructor */
constexpr /*implicit*/ Unit(): _value(T(0)) {}
/** @brief Construct zero value */
constexpr /*implicit*/ Unit(ZeroInitT = ZeroInit): _value(T(0)) {}
/** @brief Explicit conversion from unitless type */
constexpr explicit Unit(T value): _value(value) {}

2
src/Magnum/Math/Vector.h

@ -146,7 +146,7 @@ template<std::size_t size, class T> class Vector {
* \boldsymbol v = \boldsymbol 0
* @f]
*/
constexpr /*implicit*/ Vector(): _data() {}
constexpr /*implicit*/ Vector(ZeroInitT = ZeroInit): _data{} {}
/** @todo Creating Vector from combination of vector and scalar types */

4
src/Magnum/Math/Vector2.h

@ -111,8 +111,8 @@ template<class T> class Vector2: public Vector<2, T> {
}
#endif
/** @copydoc Vector::Vector() */
constexpr /*implicit*/ Vector2() {}
/** @copydoc Vector::Vector(ZeroInitT) */
constexpr /*implicit*/ Vector2(ZeroInitT = ZeroInit): Vector<2, T>{ZeroInit} {}
/** @copydoc Vector::Vector(T) */
constexpr explicit Vector2(T value): Vector<2, T>(value) {}

4
src/Magnum/Math/Vector3.h

@ -133,8 +133,8 @@ template<class T> class Vector3: public Vector<3, T> {
}
#endif
/** @copydoc Vector::Vector() */
constexpr /*implicit*/ Vector3() {}
/** @copydoc Vector::Vector(ZeroInitT) */
constexpr /*implicit*/ Vector3(ZeroInitT = ZeroInit): Vector<3, T>{ZeroInit} {}
/** @copydoc Vector::Vector(T) */
constexpr explicit Vector3(T value): Vector<3, T>(value) {}

4
src/Magnum/Math/Vector4.h

@ -59,8 +59,8 @@ template<class T> class Vector4: public Vector<4, T> {
3 < otherSize ? a[3] : w};
}
/** @copydoc Vector::Vector() */
constexpr /*implicit*/ Vector4() {}
/** @copydoc Vector::Vector(ZeroInitT) */
constexpr /*implicit*/ Vector4(ZeroInitT = ZeroInit): Vector<4, T>{ZeroInit} {}
/** @copydoc Vector::Vector(T) */
constexpr explicit Vector4(T value): Vector<4, T>(value) {}

12
src/Magnum/SceneGraph/Test/ObjectTest.cpp

@ -371,16 +371,16 @@ void ObjectTest::setClean() {
CORRADE_VERIFY(childThree->isDirty());
/* If the object itself is already clean, it shouldn't clean it again */
childOne->cleanedAbsoluteTransformation = Matrix4(Matrix4::Zero);
childOne->cleanedAbsoluteTransformation = Matrix4{Math::ZeroInit};
CORRADE_VERIFY(!childOne->isDirty());
childOne->setClean();
CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero));
CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit});
/* If any object in the hierarchy is already clean, it shouldn't clean it again */
CORRADE_VERIFY(!childOne->isDirty());
CORRADE_VERIFY(childTwo->isDirty());
childTwo->setClean();
CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero));
CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit});
/* Remove object from tree => make it and its children dirty */
childThree->setClean();
@ -441,16 +441,16 @@ void ObjectTest::setCleanListHierarchy() {
CORRADE_COMPARE(childTwoFeature->cleanedAbsoluteTransformation, childTwo->absoluteTransformationMatrix());
/* If the object itself is already clean, it shouldn't clean it again */
childOne->cleanedAbsoluteTransformation = Matrix4(Matrix4::Zero);
childOne->cleanedAbsoluteTransformation = Matrix4{Math::ZeroInit};
CORRADE_VERIFY(!childOne->isDirty());
Scene3D::setClean({*childOne});
CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero));
CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit});
/* If any object in the hierarchy is already clean, it shouldn't clean it again */
CORRADE_VERIFY(!childOne->isDirty());
childTwo->setDirty();
Scene3D::setClean({*childTwo});
CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero));
CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit});
}
void ObjectTest::setCleanListBulk() {

2
src/Magnum/Shapes/Box.h

@ -56,7 +56,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Box {
*
* Creates zero-sized box positioned at origin.
*/
constexpr /*implicit*/ Box(): _transformation(MatrixTypeFor<dimensions, Float>::Zero) {}
constexpr /*implicit*/ Box(): _transformation{Math::ZeroInit} {}
/** @brief Constructor */
constexpr /*implicit*/ Box(const MatrixTypeFor<dimensions, Float>& transformation): _transformation(transformation) {}

6
src/Magnum/Test/ColorTest.cpp

@ -104,8 +104,10 @@ void ColorTest::construct() {
}
void ColorTest::constructDefault() {
constexpr Vector3 a;
CORRADE_COMPARE(a, Color3(0.0f, 0.0f, 0.0f));
constexpr Color3 a1;
constexpr Color3 a2{Math::ZeroInit};
CORRADE_COMPARE(a1, Color3(0.0f, 0.0f, 0.0f));
CORRADE_COMPARE(a2, Color3(0.0f, 0.0f, 0.0f));
constexpr Color4 b;
constexpr Color4ub c;

Loading…
Cancel
Save