Browse Source

Added convenience Matrix2x2, Matrix3x3 and Matrix4x4 aliases.

Unlike Matrix3/Matrix4 these don't have any transformation-related
functions. Deprecated the old Matrix2 typedef, which is now replaced
with Matrix2x2 and will be removed in future release.
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
f130ce5891
  1. 8
      src/DebugTools/Test/CapsuleRendererTest.cpp
  2. 4
      src/DebugTools/Test/CylinderRendererTest.cpp
  3. 104
      src/Magnum.h
  4. 36
      src/Math/Algorithms/Test/GaussJordanTest.cpp
  5. 30
      src/Math/Algorithms/Test/GramSchmidtTest.cpp
  6. 6
      src/Math/Math.h
  7. 40
      src/Math/Matrix.h
  8. 4
      src/Math/Test/ComplexTest.cpp
  9. 30
      src/Math/Test/Matrix3Test.cpp
  10. 38
      src/Math/Test/Matrix4Test.cpp
  11. 176
      src/Math/Test/MatrixTest.cpp
  12. 6
      src/Math/Test/QuaternionTest.cpp
  13. 62
      src/Math/Test/RectangularMatrixTest.cpp
  14. 2
      src/Shaders/Phong.h

8
src/DebugTools/Test/CapsuleRendererTest.cpp

@ -55,9 +55,9 @@ void CapsuleRendererTest::zeroLength2D() {
const Vector2 a(0.5f, 3.0f); const Vector2 a(0.5f, 3.0f);
std::array<Matrix3, 3> transformation = Implementation::capsuleRendererTransformation<2>(a, a, 3.5f); std::array<Matrix3, 3> transformation = Implementation::capsuleRendererTransformation<2>(a, a, 3.5f);
const auto scaling = Math::Matrix<2, Float>::fromDiagonal(Vector2(3.5f)); const auto scaling = Matrix2x2::fromDiagonal(Vector2(3.5f));
CORRADE_COMPARE(transformation[0].rotationScaling(), scaling); CORRADE_COMPARE(transformation[0].rotationScaling(), scaling);
CORRADE_COMPARE(transformation[1].rotationScaling(), (Math::Matrix<2, Float>::fromDiagonal({3.5f, 0.0f}))); CORRADE_COMPARE(transformation[1].rotationScaling(), Matrix2x2::fromDiagonal({3.5f, 0.0f}));
CORRADE_COMPARE(transformation[2].rotationScaling(), scaling); CORRADE_COMPARE(transformation[2].rotationScaling(), scaling);
CORRADE_COMPARE(transformation[0].translation(), a); CORRADE_COMPARE(transformation[0].translation(), a);
@ -94,9 +94,9 @@ void CapsuleRendererTest::zeroLength3D() {
const Vector3 a(0.5f, 3.0f, 7.0f); const Vector3 a(0.5f, 3.0f, 7.0f);
std::array<Matrix4, 3> transformation = Implementation::capsuleRendererTransformation<3>(a, a, 3.5f); std::array<Matrix4, 3> transformation = Implementation::capsuleRendererTransformation<3>(a, a, 3.5f);
const auto scaling = Math::Matrix<3, Float>::fromDiagonal(Vector3(3.5f)); const auto scaling = Matrix3x3::fromDiagonal(Vector3(3.5f));
CORRADE_COMPARE(transformation[0].rotationScaling(), scaling); CORRADE_COMPARE(transformation[0].rotationScaling(), scaling);
CORRADE_COMPARE(transformation[1].rotationScaling(), (Math::Matrix<3, Float>::fromDiagonal({3.5f, 0.0f, 3.5f}))); CORRADE_COMPARE(transformation[1].rotationScaling(), Matrix3x3::fromDiagonal({3.5f, 0.0f, 3.5f}));
CORRADE_COMPARE(transformation[2].rotationScaling(), scaling); CORRADE_COMPARE(transformation[2].rotationScaling(), scaling);
CORRADE_COMPARE(transformation[0].translation(), a); CORRADE_COMPARE(transformation[0].translation(), a);

4
src/DebugTools/Test/CylinderRendererTest.cpp

@ -55,7 +55,7 @@ void CylinderRendererTest::zeroLength2D() {
const Vector2 a(0.5f, 3.0f); const Vector2 a(0.5f, 3.0f);
const Matrix3 transformation = Implementation::cylinderRendererTransformation<2>(a, a, 3.5f); const Matrix3 transformation = Implementation::cylinderRendererTransformation<2>(a, a, 3.5f);
CORRADE_COMPARE(transformation.rotationScaling(), (Math::Matrix<2, Float>::fromDiagonal({3.5f, 0.0f}))); CORRADE_COMPARE(transformation.rotationScaling(), Matrix2x2::fromDiagonal({3.5f, 0.0f}));
CORRADE_COMPARE(transformation.translation(), a); CORRADE_COMPARE(transformation.translation(), a);
} }
@ -76,7 +76,7 @@ void CylinderRendererTest::zeroLength3D() {
const Vector3 a(0.5f, 3.0f, 7.0f); const Vector3 a(0.5f, 3.0f, 7.0f);
const Matrix4 transformation = Implementation::cylinderRendererTransformation<3>(a, a, 3.5f); const Matrix4 transformation = Implementation::cylinderRendererTransformation<3>(a, a, 3.5f);
CORRADE_COMPARE(transformation.rotationScaling(), (Math::Matrix<3, Float>::fromDiagonal({3.5f, 0.0f, 3.5f}))); CORRADE_COMPARE(transformation.rotationScaling(), Matrix3x3::fromDiagonal({3.5f, 0.0f, 3.5f}));
CORRADE_COMPARE(transformation.translation(), a); CORRADE_COMPARE(transformation.translation(), a);
} }

104
src/Magnum.h

@ -185,15 +185,59 @@ typedef Math::Vector3<Int> Vector3i;
/** @brief Four-component signed integer vector */ /** @brief Four-component signed integer vector */
typedef Math::Vector4<Int> Vector4i; typedef Math::Vector4<Int> Vector4i;
/** @brief 2x2 float matrix */ /**
typedef Math::Matrix<2, Float> Matrix2; @brief 3x3 float transformation matrix
/** @brief 3x3 float matrix */ @see @ref Matrix3x3
*/
typedef Math::Matrix3<Float> Matrix3; typedef Math::Matrix3<Float> Matrix3;
/** @brief 4x4 float matrix */ /**
@brief 4x4 float transformation matrix
@see @ref Matrix4x4
*/
typedef Math::Matrix4<Float> Matrix4; typedef Math::Matrix4<Float> Matrix4;
/** @brief 2x2 float matrix */
#ifndef CORRADE_GCC46_COMPATIBILITY
typedef Math::Matrix2x2<Float> Matrix2x2;
#else
typedef Math::Matrix<2, Float> Matrix2x2;
#endif
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@copybrief Matrix2x2
@deprecated Use @ref Magnum::Matrix2x2 "Matrix2x2" instead.
*/
typedef Math::Matrix<2, Float> Matrix2;
#endif
/**
@brief 3x3 float matrix
Note that this is different from @ref Matrix3, which contains additional
functions for transformations in 2D.
*/
#ifndef CORRADE_GCC46_COMPATIBILITY
typedef Math::Matrix3x3<Float> Matrix3x3;
#else
typedef Math::Matrix<3, Float> Matrix3x3;
#endif
/**
@brief 4x4 float matrix
Note that this is different from @ref Matrix4, which contains additional
functions for transformations in 3D.
*/
#ifndef CORRADE_GCC46_COMPATIBILITY
typedef Math::Matrix4x4<Float> Matrix4x4;
#else
typedef Math::Matrix<4, Float> Matrix4x4;
#endif
/** @brief Float matrix with 2 columns and 3 rows */ /** @brief Float matrix with 2 columns and 3 rows */
#ifndef CORRADE_GCC46_COMPATIBILITY #ifndef CORRADE_GCC46_COMPATIBILITY
typedef Math::Matrix2x3<Float> Matrix2x3; typedef Math::Matrix2x3<Float> Matrix2x3;
@ -284,15 +328,59 @@ typedef Math::Vector3<Double> Vector3d;
/** @brief Four-component double vector */ /** @brief Four-component double vector */
typedef Math::Vector4<Double> Vector4d; typedef Math::Vector4<Double> Vector4d;
/** @brief 2x2 double matrix */ /**
typedef Math::Matrix<2, Double> Matrix2d; @brief 3x3 double transformation matrix
/** @brief 3x3 double matrix */ @see @ref Matrix3x3d
*/
typedef Math::Matrix3<Double> Matrix3d; typedef Math::Matrix3<Double> Matrix3d;
/** @brief 4x4 double matrix */ /**
@brief 4x4 double transformation matrix
@see @ref Matrix4x4d
*/
typedef Math::Matrix4<Double> Matrix4d; typedef Math::Matrix4<Double> Matrix4d;
/** @brief 2x2 double matrix */
#ifndef CORRADE_GCC46_COMPATIBILITY
typedef Math::Matrix2x2<Double> Matrix2x2d;
#else
typedef Math::Matrix<2, Double> Matrix2x2d;
#endif
#ifdef MAGNUM_BUILD_DEPRECATED
/**
@copybrief Matrix2x2d
@deprecated Use @ref Magnum::Matrix2x2d "Matrix2x2d" instead.
*/
typedef Math::Matrix<2, Double> Matrix2d;
#endif
/**
@brief 3x3 double matrix
Note that this is different from @ref Matrix3d, which contains additional
functions for transformations in 2D.
*/
#ifndef CORRADE_GCC46_COMPATIBILITY
typedef Math::Matrix3x3<Double> Matrix3x3d;
#else
typedef Math::Matrix<3, Double> Matrix3x3d;
#endif
/**
@brief 4x4 double matrix
Note that this is different from @ref Matrix4d, which contains additional
functions for transformations in 3D.
*/
#ifndef CORRADE_GCC46_COMPATIBILITY
typedef Math::Matrix4x4<Double> Matrix4x4d;
#else
typedef Math::Matrix<4, Double> Matrix4x4d;
#endif
/** @brief Double matrix with 2 columns and 3 rows */ /** @brief Double matrix with 2 columns and 3 rows */
#ifndef CORRADE_GCC46_COMPATIBILITY #ifndef CORRADE_GCC46_COMPATIBILITY
typedef Math::Matrix2x3<Double> Matrix2x3d; typedef Math::Matrix2x3<Double> Matrix2x3d;

36
src/Math/Algorithms/Test/GaussJordanTest.cpp

@ -36,7 +36,7 @@ class GaussJordanTest: public Corrade::TestSuite::Tester {
void invert(); void invert();
}; };
typedef RectangularMatrix<4, 4, Float> Matrix4; typedef RectangularMatrix<4, 4, Float> Matrix4x4;
typedef Vector<4, Float> Vector4; typedef Vector<4, Float> Vector4;
GaussJordanTest::GaussJordanTest() { GaussJordanTest::GaussJordanTest() {
@ -45,32 +45,32 @@ GaussJordanTest::GaussJordanTest() {
} }
void GaussJordanTest::singular() { void GaussJordanTest::singular() {
Matrix4 a(Vector4(1.0f, 2.0f, 3.0f, 4.0f), Matrix4x4 a(Vector4(1.0f, 2.0f, 3.0f, 4.0f),
Vector4(2.0f, 3.0f, -7.0f, 11.0f), Vector4(2.0f, 3.0f, -7.0f, 11.0f),
Vector4(2.0f, 4.0f, 6.0f, 8.0f), Vector4(2.0f, 4.0f, 6.0f, 8.0f),
Vector4(1.0f, 2.0f, 7.0f, 40.0f)); Vector4(1.0f, 2.0f, 7.0f, 40.0f));
RectangularMatrix<4, 1, Float> t; RectangularMatrix<4, 1, Float> t;
CORRADE_VERIFY(!gaussJordanInPlaceTransposed(a, t)); CORRADE_VERIFY(!gaussJordanInPlaceTransposed(a, t));
} }
void GaussJordanTest::invert() { void GaussJordanTest::invert() {
Matrix4 a(Vector4(3.0f, 5.0f, 8.0f, 4.0f), Matrix4x4 a(Vector4(3.0f, 5.0f, 8.0f, 4.0f),
Vector4(4.0f, 4.0f, 7.0f, 3.0f), Vector4(4.0f, 4.0f, 7.0f, 3.0f),
Vector4(7.0f, -1.0f, 8.0f, 0.0f), Vector4(7.0f, -1.0f, 8.0f, 0.0f),
Vector4(9.0f, 4.0f, 5.0f, 9.0f)); Vector4(9.0f, 4.0f, 5.0f, 9.0f));
Matrix4 expectedInverse(Vector4(-60/103.0f, 71/103.0f, -4/103.0f, 3/103.0f), Matrix4x4 expectedInverse(Vector4(-60/103.0f, 71/103.0f, -4/103.0f, 3/103.0f),
Vector4(-66/103.0f, 109/103.0f, -25/103.0f, -7/103.0f), Vector4(-66/103.0f, 109/103.0f, -25/103.0f, -7/103.0f),
Vector4(177/412.0f, -97/206.0f, 53/412.0f, -7/206.0f), Vector4(177/412.0f, -97/206.0f, 53/412.0f, -7/206.0f),
Vector4(259/412.0f, -185/206.0f, 31/412.0f, 27/206.0f)); Vector4(259/412.0f, -185/206.0f, 31/412.0f, 27/206.0f));
Matrix4 a2(a); Matrix4x4 a2(a);
Matrix4 inverse = Matrix4::fromDiagonal(Vector4(1.0f)); Matrix4x4 inverse = Matrix4x4::fromDiagonal(Vector4(1.0f));
CORRADE_VERIFY(gaussJordanInPlace(a2, inverse)); CORRADE_VERIFY(gaussJordanInPlace(a2, inverse));
CORRADE_COMPARE(inverse, expectedInverse); CORRADE_COMPARE(inverse, expectedInverse);
CORRADE_COMPARE(a*inverse, Matrix4::fromDiagonal(Vector4(1.0f))); CORRADE_COMPARE(a*inverse, Matrix4x4::fromDiagonal(Vector4(1.0f)));
} }
}}}} }}}}

30
src/Math/Algorithms/Test/GramSchmidtTest.cpp

@ -36,7 +36,7 @@ class GramSchmidtTest: public Corrade::TestSuite::Tester {
void orthonormalize(); void orthonormalize();
}; };
typedef RectangularMatrix<3, 3, Float> Matrix3; typedef RectangularMatrix<3, 3, Float> Matrix3x3;
typedef Vector<3, Float> Vector3; typedef Vector<3, Float> Vector3;
GramSchmidtTest::GramSchmidtTest() { GramSchmidtTest::GramSchmidtTest() {
@ -45,11 +45,11 @@ GramSchmidtTest::GramSchmidtTest() {
} }
void GramSchmidtTest::orthogonalize() { void GramSchmidtTest::orthogonalize() {
Matrix3 m(Vector3(3.0f, 5.0f, 1.0f), Matrix3x3 m(Vector3(3.0f, 5.0f, 1.0f),
Vector3(4.0f, 4.0f, 7.0f), Vector3(4.0f, 4.0f, 7.0f),
Vector3(7.0f, -1.0f, -3.0f)); Vector3(7.0f, -1.0f, -3.0f));
Matrix3 orthogonalized = Algorithms::gramSchmidtOrthogonalize(m); Matrix3x3 orthogonalized = Algorithms::gramSchmidtOrthogonalize(m);
/* Verify the first vector is in direction of first original */ /* Verify the first vector is in direction of first original */
CORRADE_COMPARE(orthogonalized[0], m[0]); CORRADE_COMPARE(orthogonalized[0], m[0]);
@ -62,18 +62,18 @@ void GramSchmidtTest::orthogonalize() {
CORRADE_COMPARE(Vector3::dot(orthogonalized[1], orthogonalized[2]), 0.0f); CORRADE_COMPARE(Vector3::dot(orthogonalized[1], orthogonalized[2]), 0.0f);
/* Just to be sure */ /* Just to be sure */
Matrix3 expected(Vector3( 3.0f, 5.0f, 1.0f), Matrix3x3 expected(Vector3( 3.0f, 5.0f, 1.0f),
Vector3(0.657143f, -1.571429f, 5.885714f), Vector3(0.657143f, -1.571429f, 5.885714f),
Vector3(6.086759f, -3.3379f, -1.570777f)); Vector3(6.086759f, -3.3379f, -1.570777f));
CORRADE_COMPARE(orthogonalized, expected); CORRADE_COMPARE(orthogonalized, expected);
} }
void GramSchmidtTest::orthonormalize() { void GramSchmidtTest::orthonormalize() {
Matrix3 m(Vector3(3.0f, 5.0f, 8.0f), Matrix3x3 m(Vector3(3.0f, 5.0f, 8.0f),
Vector3(4.0f, 4.0f, 7.0f), Vector3(4.0f, 4.0f, 7.0f),
Vector3(7.0f, -1.0f, 8.0f)); Vector3(7.0f, -1.0f, 8.0f));
Matrix3 orthonormalized = Algorithms::gramSchmidtOrthonormalize(m); Matrix3x3 orthonormalized = Algorithms::gramSchmidtOrthonormalize(m);
/* Verify the first vector is in direction of first original */ /* Verify the first vector is in direction of first original */
CORRADE_COMPARE(orthonormalized[0], m[0].normalized()); CORRADE_COMPARE(orthonormalized[0], m[0].normalized());
@ -89,9 +89,9 @@ void GramSchmidtTest::orthonormalize() {
CORRADE_COMPARE(Vector3::dot(orthonormalized[1], orthonormalized[2]), 0.0f); CORRADE_COMPARE(Vector3::dot(orthonormalized[1], orthonormalized[2]), 0.0f);
/* Just to be sure */ /* Just to be sure */
Matrix3 expected(Vector3( 0.303046f, 0.505076f, 0.808122f), Matrix3x3 expected(Vector3( 0.303046f, 0.505076f, 0.808122f),
Vector3( 0.928316f, -0.348119f, -0.130544f), Vector3( 0.928316f, -0.348119f, -0.130544f),
Vector3(-0.215388f, -0.789754f, 0.574367f)); Vector3(-0.215388f, -0.789754f, 0.574367f));
CORRADE_COMPARE(orthonormalized, expected); CORRADE_COMPARE(orthonormalized, expected);
} }

6
src/Math/Math.h

@ -44,6 +44,12 @@ template<class> class DualComplex;
template<class> class DualQuaternion; template<class> class DualQuaternion;
template<std::size_t, class> class Matrix; template<std::size_t, class> class Matrix;
#ifndef CORRADE_GCC46_COMPATIBILITY
template<class T> using Matrix2x2 = Matrix<2, T>;
template<class T> using Matrix3x3 = Matrix<3, T>;
template<class T> using Matrix4x4 = Matrix<4, T>;
#endif
template<class> class Matrix3; template<class> class Matrix3;
template<class> class Matrix4; template<class> class Matrix4;

40
src/Math/Matrix.h

@ -44,7 +44,7 @@ namespace Implementation {
See @ref matrix-vector for brief introduction. See @ref matrix-vector for brief introduction.
@configurationvalueref{Magnum::Math::Matrix} @configurationvalueref{Magnum::Math::Matrix}
@see Magnum::Matrix2, Magnum::Matrix2d @see @ref Matrix2x2, @ref Matrix3x3, @ref Matrix4x4
*/ */
template<std::size_t size, class T> class Matrix: public RectangularMatrix<size, size, T> { template<std::size_t size, class T> class Matrix: public RectangularMatrix<size, size, T> {
public: public:
@ -89,9 +89,9 @@ template<std::size_t size, class T> class Matrix: public RectangularMatrix<size,
* Performs only default casting on the values, no rounding or * Performs only default casting on the values, no rounding or
* anything else. Example usage: * anything else. Example usage:
* @code * @code
* Matrix<2, Float> floatingPoint({1.3f, 2.7f}, * Matrix2x2<Float> floatingPoint({1.3f, 2.7f},
* {-15.0f, 7.0f}); * {-15.0f, 7.0f});
* Matrix<2, Byte> integral(floatingPoint); * Matrix2x2<Byte> integral(floatingPoint);
* // integral == {{1, 2}, {-15, 7}} * // integral == {{1, 2}, {-15, 7}}
* @endcode * @endcode
*/ */
@ -180,6 +180,40 @@ template<std::size_t size, class T> class Matrix: public RectangularMatrix<size,
#endif #endif
}; };
#ifndef CORRADE_GCC46_COMPATIBILITY
/**
@brief 2x2 matrix
Convenience alternative to <tt>%Matrix<2, T></tt>. See @ref Matrix for more
information.
@note Not available on GCC < 4.7. Use <tt>%Matrix<2, T></tt> instead.
@see @ref Magnum::Matrix2x2, @ref Magnum::Matrix2x2d
*/
template<class T> using Matrix2x2 = Matrix<2, T>;
/**
@brief 3x3 matrix
Convenience alternative to <tt>%Matrix<3, T></tt>. See @ref Matrix for more
information. Note that this is different from @ref Matrix3, which contains
additional functions for transformations in 2D.
@note Not available on GCC < 4.7. Use <tt>%Matrix<3, T></tt> instead.
@see @ref Magnum::Matrix3x3, @ref Magnum::Matrix3x3d
*/
template<class T> using Matrix3x3 = Matrix<3, T>;
/**
@brief 4x4 matrix
Convenience alternative to <tt>%Matrix<4, T></tt>. See @ref Matrix for more
information. Note that this is different from @ref Matrix4, which contains
additional functions for transformations in 3D.
@note Not available on GCC < 4.7. Use <tt>%Matrix<3, T></tt> instead.
@see @ref Magnum::Matrix4x4, @ref Magnum::Matrix4x4d
*/
template<class T> using Matrix4x4 = Matrix<4, T>;
#endif
MAGNUM_MATRIX_OPERATOR_IMPLEMENTATION(Matrix<size, T>) MAGNUM_MATRIX_OPERATOR_IMPLEMENTATION(Matrix<size, T>)
/** @debugoperator{Magnum::Math::Matrix} */ /** @debugoperator{Magnum::Math::Matrix} */

4
src/Math/Test/ComplexTest.cpp

@ -100,7 +100,7 @@ typedef Math::Rad<Float> Rad;
typedef Math::Complex<Float> Complex; typedef Math::Complex<Float> Complex;
typedef Math::Vector2<Float> Vector2; typedef Math::Vector2<Float> Vector2;
typedef Math::Matrix3<Float> Matrix3; typedef Math::Matrix3<Float> Matrix3;
typedef Math::Matrix<2, Float> Matrix2; typedef Math::Matrix<2, Float> Matrix2x2;
void ComplexTest::construct() { void ComplexTest::construct() {
constexpr Complex a(0.5f, -3.7f); constexpr Complex a(0.5f, -3.7f);
@ -275,7 +275,7 @@ void ComplexTest::rotation() {
void ComplexTest::matrix() { void ComplexTest::matrix() {
Complex a = Complex::rotation(Deg(37.0f)); Complex a = Complex::rotation(Deg(37.0f));
Matrix2 m = Matrix3::rotation(Deg(37.0f)).rotationScaling(); Matrix2x2 m = Matrix3::rotation(Deg(37.0f)).rotationScaling();
CORRADE_COMPARE(a.toMatrix(), m); CORRADE_COMPARE(a.toMatrix(), m);

30
src/Math/Test/Matrix3Test.cpp

@ -90,7 +90,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester {
typedef Math::Deg<Float> Deg; typedef Math::Deg<Float> Deg;
typedef Math::Matrix3<Float> Matrix3; typedef Math::Matrix3<Float> Matrix3;
typedef Math::Matrix3<Int> Matrix3i; typedef Math::Matrix3<Int> Matrix3i;
typedef Math::Matrix<2, Float> Matrix2; typedef Math::Matrix<2, Float> Matrix2x2;
typedef Math::Vector3<Float> Vector3; typedef Math::Vector3<Float> Vector3;
typedef Math::Vector2<Float> Vector2; typedef Math::Vector2<Float> Vector2;
@ -269,8 +269,8 @@ void Matrix3Test::projection() {
} }
void Matrix3Test::fromParts() { void Matrix3Test::fromParts() {
constexpr Matrix2 rotationScaling(Vector2(3.0f, 5.0f), constexpr Matrix2x2 rotationScaling(Vector2(3.0f, 5.0f),
Vector2(4.0f, 4.0f)); Vector2(4.0f, 4.0f));
constexpr Vector2 translation(7.0f, -1.0f); constexpr Vector2 translation(7.0f, -1.0f);
constexpr Matrix3 a = Matrix3::from(rotationScaling, translation); constexpr Matrix3 a = Matrix3::from(rotationScaling, translation);
@ -283,10 +283,10 @@ void Matrix3Test::rotationScalingPart() {
constexpr Matrix3 a({3.0f, 5.0f, 8.0f}, constexpr Matrix3 a({3.0f, 5.0f, 8.0f},
{4.0f, 4.0f, 7.0f}, {4.0f, 4.0f, 7.0f},
{7.0f, -1.0f, 8.0f}); {7.0f, -1.0f, 8.0f});
constexpr Matrix2 b = a.rotationScaling(); constexpr Matrix2x2 b = a.rotationScaling();
CORRADE_COMPARE(b, Matrix2(Vector2(3.0f, 5.0f), CORRADE_COMPARE(b, Matrix2x2(Vector2(3.0f, 5.0f),
Vector2(4.0f, 4.0f))); Vector2(4.0f, 4.0f)));
} }
void Matrix3Test::rotationNormalizedPart() { void Matrix3Test::rotationNormalizedPart() {
@ -303,34 +303,34 @@ void Matrix3Test::rotationNormalizedPart() {
Matrix3 b({ 0.965926f, 0.258819f, 1.0f}, Matrix3 b({ 0.965926f, 0.258819f, 1.0f},
{-0.258819f, 0.965926f, 3.0f}, {-0.258819f, 0.965926f, 3.0f},
{ 0.0f, 0.0f, 1.0f}); { 0.0f, 0.0f, 1.0f});
CORRADE_COMPARE(b.rotationNormalized(), Matrix2(Vector2( 0.965926f, 0.258819f), CORRADE_COMPARE(b.rotationNormalized(), Matrix2x2(Vector2( 0.965926f, 0.258819f),
Vector2(-0.258819f, 0.965926f))); Vector2(-0.258819f, 0.965926f)));
} }
void Matrix3Test::rotationPart() { void Matrix3Test::rotationPart() {
Matrix3 rotation = Matrix3::rotation(Deg(15.0f)); Matrix3 rotation = Matrix3::rotation(Deg(15.0f));
Matrix2 expectedRotationPart(Vector2( 0.965926f, 0.258819f), Matrix2x2 expectedRotationPart(Vector2( 0.965926f, 0.258819f),
Vector2(-0.258819f, 0.965926f)); Vector2(-0.258819f, 0.965926f));
/* For rotation and translation this is the same as rotationScaling() */ /* For rotation and translation this is the same as rotationScaling() */
Matrix3 rotationTranslation = rotation*Matrix3::translation({2.0f, 5.0f}); Matrix3 rotationTranslation = rotation*Matrix3::translation({2.0f, 5.0f});
Matrix2 rotationTranslationPart = rotationTranslation.rotation(); Matrix2x2 rotationTranslationPart = rotationTranslation.rotation();
CORRADE_COMPARE(rotationTranslationPart, rotationTranslation.rotationScaling()); CORRADE_COMPARE(rotationTranslationPart, rotationTranslation.rotationScaling());
CORRADE_COMPARE(rotationTranslationPart, expectedRotationPart); CORRADE_COMPARE(rotationTranslationPart, expectedRotationPart);
/* Test uniform scaling */ /* Test uniform scaling */
Matrix3 rotationScaling = rotation*Matrix3::scaling(Vector2(3.0f)); Matrix3 rotationScaling = rotation*Matrix3::scaling(Vector2(3.0f));
Matrix2 rotationScalingPart = rotationScaling.rotation(); Matrix2x2 rotationScalingPart = rotationScaling.rotation();
CORRADE_COMPARE(rotationScalingPart.determinant(), 1.0f); CORRADE_COMPARE(rotationScalingPart.determinant(), 1.0f);
CORRADE_COMPARE(rotationScalingPart*rotationScalingPart.transposed(), Matrix2()); CORRADE_COMPARE(rotationScalingPart*rotationScalingPart.transposed(), Matrix2x2());
CORRADE_COMPARE(rotationScalingPart, expectedRotationPart); CORRADE_COMPARE(rotationScalingPart, expectedRotationPart);
/* Fails on non-uniform scaling */ /* Fails on non-uniform scaling */
std::ostringstream o; std::ostringstream o;
Error::setOutput(&o); Error::setOutput(&o);
Matrix2 rotationScaling2 = (rotation*Matrix3::scaling(Vector2::yScale(3.5f))).rotation(); Matrix2x2 rotationScaling2 = (rotation*Matrix3::scaling(Vector2::yScale(3.5f))).rotation();
CORRADE_COMPARE(o.str(), "Math::Matrix3::rotation(): the matrix doesn't have uniform scaling\n"); CORRADE_COMPARE(o.str(), "Math::Matrix3::rotation(): the matrix doesn't have uniform scaling\n");
CORRADE_COMPARE(rotationScaling2, Matrix2()); CORRADE_COMPARE(rotationScaling2, Matrix2x2());
} }
void Matrix3Test::uniformScalingPart() { void Matrix3Test::uniformScalingPart() {

38
src/Math/Test/Matrix4Test.cpp

@ -98,7 +98,7 @@ typedef Math::Deg<Float> Deg;
typedef Math::Rad<Float> Rad; typedef Math::Rad<Float> Rad;
typedef Math::Matrix4<Float> Matrix4; typedef Math::Matrix4<Float> Matrix4;
typedef Math::Matrix4<Int> Matrix4i; typedef Math::Matrix4<Int> Matrix4i;
typedef Math::Matrix<3, Float> Matrix3; typedef Math::Matrix<3, Float> Matrix3x3;
typedef Math::Vector3<Float> Vector3; typedef Math::Vector3<Float> Vector3;
Matrix4Test::Matrix4Test() { Matrix4Test::Matrix4Test() {
@ -348,9 +348,9 @@ void Matrix4Test::perspectiveProjectionFov() {
} }
void Matrix4Test::fromParts() { void Matrix4Test::fromParts() {
constexpr Matrix3 rotationScaling(Vector3(3.0f, 5.0f, 8.0f), constexpr Matrix3x3 rotationScaling(Vector3(3.0f, 5.0f, 8.0f),
Vector3(4.0f, 4.0f, 7.0f), Vector3(4.0f, 4.0f, 7.0f),
Vector3(7.0f, -1.0f, 8.0f)); Vector3(7.0f, -1.0f, 8.0f));
constexpr Vector3 translation(9.0f, 4.0f, 5.0f); constexpr Vector3 translation(9.0f, 4.0f, 5.0f);
constexpr Matrix4 a = Matrix4::from(rotationScaling, translation); constexpr Matrix4 a = Matrix4::from(rotationScaling, translation);
@ -365,11 +365,11 @@ void Matrix4Test::rotationScalingPart() {
{4.0f, 4.0f, 7.0f, 3.0f}, {4.0f, 4.0f, 7.0f, 3.0f},
{7.0f, -1.0f, 8.0f, 0.0f}, {7.0f, -1.0f, 8.0f, 0.0f},
{9.0f, 4.0f, 5.0f, 9.0f}); {9.0f, 4.0f, 5.0f, 9.0f});
constexpr Matrix3 b = a.rotationScaling(); constexpr Matrix3x3 b = a.rotationScaling();
CORRADE_COMPARE(b, Matrix3(Vector3(3.0f, 5.0f, 8.0f), CORRADE_COMPARE(b, Matrix3x3(Vector3(3.0f, 5.0f, 8.0f),
Vector3(4.0f, 4.0f, 7.0f), Vector3(4.0f, 4.0f, 7.0f),
Vector3(7.0f, -1.0f, 8.0f))); Vector3(7.0f, -1.0f, 8.0f)));
} }
void Matrix4Test::rotationNormalizedPart() { void Matrix4Test::rotationNormalizedPart() {
@ -387,36 +387,36 @@ void Matrix4Test::rotationNormalizedPart() {
{ 0.47987163f, 0.59757638f, 0.6423595f, 3.0f}, { 0.47987163f, 0.59757638f, 0.6423595f, 3.0f},
{-0.80181062f, 0.0015183985f, 0.59757638f, 4.0f}, {-0.80181062f, 0.0015183985f, 0.59757638f, 4.0f},
{ 0.0f, 0.0f, 0.0f, 1.0f}); { 0.0f, 0.0f, 0.0f, 1.0f});
CORRADE_COMPARE(b.rotationNormalized(), Matrix3(Vector3( 0.35612214f, -0.80181062f, 0.47987163f), CORRADE_COMPARE(b.rotationNormalized(), Matrix3x3(Vector3( 0.35612214f, -0.80181062f, 0.47987163f),
Vector3( 0.47987163f, 0.59757638f, 0.6423595f), Vector3( 0.47987163f, 0.59757638f, 0.6423595f),
Vector3(-0.80181062f, 0.0015183985f, 0.59757638f))); Vector3(-0.80181062f, 0.0015183985f, 0.59757638f)));
} }
void Matrix4Test::rotationPart() { void Matrix4Test::rotationPart() {
Matrix4 rotation = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()); Matrix4 rotation = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized());
Matrix3 expectedRotationPart(Vector3( 0.35612214f, -0.80181062f, 0.47987163f), Matrix3x3 expectedRotationPart(Vector3( 0.35612214f, -0.80181062f, 0.47987163f),
Vector3( 0.47987163f, 0.59757638f, 0.6423595f), Vector3( 0.47987163f, 0.59757638f, 0.6423595f),
Vector3(-0.80181062f, 0.0015183985f, 0.59757638f)); Vector3(-0.80181062f, 0.0015183985f, 0.59757638f));
/* For rotation and translation this is the same as rotationScaling() */ /* For rotation and translation this is the same as rotationScaling() */
Matrix4 rotationTranslation = rotation*Matrix4::translation({2.0f, 5.0f, -3.0f}); Matrix4 rotationTranslation = rotation*Matrix4::translation({2.0f, 5.0f, -3.0f});
Matrix3 rotationTranslationPart = rotationTranslation.rotation(); Matrix3x3 rotationTranslationPart = rotationTranslation.rotation();
CORRADE_COMPARE(rotationTranslationPart, rotationTranslation.rotationScaling()); CORRADE_COMPARE(rotationTranslationPart, rotationTranslation.rotationScaling());
CORRADE_COMPARE(rotationTranslationPart, expectedRotationPart); CORRADE_COMPARE(rotationTranslationPart, expectedRotationPart);
/* Test uniform scaling */ /* Test uniform scaling */
Matrix4 rotationScaling = rotation*Matrix4::scaling(Vector3(3.0f)); Matrix4 rotationScaling = rotation*Matrix4::scaling(Vector3(3.0f));
Matrix3 rotationScalingPart = rotationScaling.rotation(); Matrix3x3 rotationScalingPart = rotationScaling.rotation();
CORRADE_COMPARE(rotationScalingPart.determinant(), 1.0f); CORRADE_COMPARE(rotationScalingPart.determinant(), 1.0f);
CORRADE_COMPARE(rotationScalingPart*rotationScalingPart.transposed(), Matrix3()); CORRADE_COMPARE(rotationScalingPart*rotationScalingPart.transposed(), Matrix3x3());
CORRADE_COMPARE(rotationScalingPart, expectedRotationPart); CORRADE_COMPARE(rotationScalingPart, expectedRotationPart);
/* Fails on non-uniform scaling */ /* Fails on non-uniform scaling */
std::ostringstream o; std::ostringstream o;
Error::setOutput(&o); Error::setOutput(&o);
Matrix3 rotationScaling2 = (rotation*Matrix4::scaling(Vector3::yScale(3.5f))).rotation(); Matrix3x3 rotationScaling2 = (rotation*Matrix4::scaling(Vector3::yScale(3.5f))).rotation();
CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): the matrix doesn't have uniform scaling\n"); CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): the matrix doesn't have uniform scaling\n");
CORRADE_COMPARE(rotationScaling2, Matrix3()); CORRADE_COMPARE(rotationScaling2, Matrix3x3());
} }
void Matrix4Test::uniformScalingPart() { void Matrix4Test::uniformScalingPart() {

176
src/Math/Test/MatrixTest.cpp

@ -82,9 +82,9 @@ class MatrixTest: public Corrade::TestSuite::Tester {
void configuration(); void configuration();
}; };
typedef Matrix<4, Float> Matrix4; typedef Matrix<4, Float> Matrix4x4;
typedef Matrix<4, Int> Matrix4i; typedef Matrix<4, Int> Matrix4x4i;
typedef Matrix<3, Float> Matrix3; typedef Matrix<3, Float> Matrix3x3;
typedef Vector<4, Float> Vector4; typedef Vector<4, Float> Vector4;
typedef Vector<4, Int> Vector4i; typedef Vector<4, Int> Vector4i;
typedef Vector<3, Float> Vector3; typedef Vector<3, Float> Vector3;
@ -115,30 +115,30 @@ MatrixTest::MatrixTest() {
} }
void MatrixTest::construct() { void MatrixTest::construct() {
constexpr Matrix4 a = {Vector4(3.0f, 5.0f, 8.0f, -3.0f), constexpr Matrix4x4 a = {Vector4(3.0f, 5.0f, 8.0f, -3.0f),
Vector4(4.5f, 4.0f, 7.0f, 2.0f), Vector4(4.5f, 4.0f, 7.0f, 2.0f),
Vector4(1.0f, 2.0f, 3.0f, -1.0f), Vector4(1.0f, 2.0f, 3.0f, -1.0f),
Vector4(7.9f, -1.0f, 8.0f, -1.5f)}; Vector4(7.9f, -1.0f, 8.0f, -1.5f)};
CORRADE_COMPARE(a, Matrix4(Vector4(3.0f, 5.0f, 8.0f, -3.0f), CORRADE_COMPARE(a, Matrix4x4(Vector4(3.0f, 5.0f, 8.0f, -3.0f),
Vector4(4.5f, 4.0f, 7.0f, 2.0f), Vector4(4.5f, 4.0f, 7.0f, 2.0f),
Vector4(1.0f, 2.0f, 3.0f, -1.0f), Vector4(1.0f, 2.0f, 3.0f, -1.0f),
Vector4(7.9f, -1.0f, 8.0f, -1.5f))); Vector4(7.9f, -1.0f, 8.0f, -1.5f)));
} }
void MatrixTest::constructIdentity() { void MatrixTest::constructIdentity() {
Matrix4 identity; Matrix4x4 identity;
Matrix4 identity2(Matrix4::Identity); Matrix4x4 identity2(Matrix4x4::Identity);
Matrix4 identity3(Matrix4::Identity, 4.0f); Matrix4x4 identity3(Matrix4x4::Identity, 4.0f);
Matrix4 identityExpected(Vector4(1.0f, 0.0f, 0.0f, 0.0f), Matrix4x4 identityExpected(Vector4(1.0f, 0.0f, 0.0f, 0.0f),
Vector4(0.0f, 1.0f, 0.0f, 0.0f), Vector4(0.0f, 1.0f, 0.0f, 0.0f),
Vector4(0.0f, 0.0f, 1.0f, 0.0f), Vector4(0.0f, 0.0f, 1.0f, 0.0f),
Vector4(0.0f, 0.0f, 0.0f, 1.0f)); Vector4(0.0f, 0.0f, 0.0f, 1.0f));
Matrix4 identity3Expected(Vector4(4.0f, 0.0f, 0.0f, 0.0f), Matrix4x4 identity3Expected(Vector4(4.0f, 0.0f, 0.0f, 0.0f),
Vector4(0.0f, 4.0f, 0.0f, 0.0f), Vector4(0.0f, 4.0f, 0.0f, 0.0f),
Vector4(0.0f, 0.0f, 4.0f, 0.0f), Vector4(0.0f, 0.0f, 4.0f, 0.0f),
Vector4(0.0f, 0.0f, 0.0f, 4.0f)); Vector4(0.0f, 0.0f, 0.0f, 4.0f));
CORRADE_COMPARE(identity, identityExpected); CORRADE_COMPARE(identity, identityExpected);
CORRADE_COMPARE(identity2, identityExpected); CORRADE_COMPARE(identity2, identityExpected);
@ -146,30 +146,30 @@ void MatrixTest::constructIdentity() {
} }
void MatrixTest::constructZero() { void MatrixTest::constructZero() {
constexpr Matrix4 a(Matrix4::Zero); constexpr Matrix4x4 a(Matrix4x4::Zero);
CORRADE_COMPARE(a, Matrix4(Vector4(0.0f, 0.0f, 0.0f, 0.0f), 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),
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))); Vector4(0.0f, 0.0f, 0.0f, 0.0f)));
} }
void MatrixTest::constructConversion() { void MatrixTest::constructConversion() {
constexpr Matrix4 a(Vector4(3.0f, 5.0f, 8.0f, -3.0f), constexpr Matrix4x4 a(Vector4(3.0f, 5.0f, 8.0f, -3.0f),
Vector4(4.5f, 4.0f, 7.0f, 2.0f), Vector4(4.5f, 4.0f, 7.0f, 2.0f),
Vector4(1.0f, 2.0f, 3.0f, -1.0f), Vector4(1.0f, 2.0f, 3.0f, -1.0f),
Vector4(7.9f, -1.0f, 8.0f, -1.5f)); Vector4(7.9f, -1.0f, 8.0f, -1.5f));
#ifndef CORRADE_GCC46_COMPATIBILITY #ifndef CORRADE_GCC46_COMPATIBILITY
constexpr Matrix4i b(a); constexpr Matrix4x4i b(a);
#else #else
Matrix4i b(a); /* Not constexpr under GCC < 4.7 */ Matrix4i b(a); /* Not constexpr under GCC < 4.7 */
#endif #endif
CORRADE_COMPARE(b, Matrix4i(Vector4i(3, 5, 8, -3), CORRADE_COMPARE(b, Matrix4x4i(Vector4i(3, 5, 8, -3),
Vector4i(4, 4, 7, 2), Vector4i(4, 4, 7, 2),
Vector4i(1, 2, 3, -1), Vector4i(1, 2, 3, -1),
Vector4i(7, -1, 8, -1))); Vector4i(7, -1, 8, -1)));
/* Implicit conversion is not allowed */ /* Implicit conversion is not allowed */
CORRADE_VERIFY(!(std::is_convertible<Matrix4, Matrix4i>::value)); CORRADE_VERIFY(!(std::is_convertible<Matrix4x4, Matrix4x4i>::value));
} }
void MatrixTest::constructCopy() { void MatrixTest::constructCopy() {
@ -177,22 +177,22 @@ void MatrixTest::constructCopy() {
Vector4(4.5f, 4.0f, 7.0f, 2.0f), Vector4(4.5f, 4.0f, 7.0f, 2.0f),
Vector4(1.0f, 2.0f, 3.0f, -1.0f), Vector4(1.0f, 2.0f, 3.0f, -1.0f),
Vector4(7.9f, -1.0f, 8.0f, -1.5f)); Vector4(7.9f, -1.0f, 8.0f, -1.5f));
constexpr Matrix4 b(a); constexpr Matrix4x4 b(a);
CORRADE_COMPARE(b, Matrix4(Vector4(3.0f, 5.0f, 8.0f, -3.0f), CORRADE_COMPARE(b, Matrix4x4(Vector4(3.0f, 5.0f, 8.0f, -3.0f),
Vector4(4.5f, 4.0f, 7.0f, 2.0f), Vector4(4.5f, 4.0f, 7.0f, 2.0f),
Vector4(1.0f, 2.0f, 3.0f, -1.0f), Vector4(1.0f, 2.0f, 3.0f, -1.0f),
Vector4(7.9f, -1.0f, 8.0f, -1.5f))); Vector4(7.9f, -1.0f, 8.0f, -1.5f)));
} }
void MatrixTest::convert() { void MatrixTest::convert() {
constexpr Mat3 a{{1.5f, 2.0f, -3.5f, constexpr Mat3 a{{1.5f, 2.0f, -3.5f,
2.0f, -3.1f, 0.4f, 2.0f, -3.1f, 0.4f,
9.5f, -1.5f, 0.1f}}; 9.5f, -1.5f, 0.1f}};
constexpr Matrix3 b(Vector3(1.5f, 2.0f, -3.5f), constexpr Matrix3x3 b(Vector3(1.5f, 2.0f, -3.5f),
Vector3(2.0f, -3.1f, 0.4f), Vector3(2.0f, -3.1f, 0.4f),
Vector3(9.5f, -1.5f, 0.1f)); Vector3(9.5f, -1.5f, 0.1f));
constexpr Matrix3 c(b); constexpr Matrix3x3 c(b);
CORRADE_COMPARE(c, b); CORRADE_COMPARE(c, b);
#ifndef CORRADE_GCC46_COMPATIBILITY #ifndef CORRADE_GCC46_COMPATIBILITY
@ -203,20 +203,20 @@ void MatrixTest::convert() {
CORRADE_COMPARE(d.a[i], a.a[i]); CORRADE_COMPARE(d.a[i], a.a[i]);
/* Implicit conversion is not allowed */ /* Implicit conversion is not allowed */
CORRADE_VERIFY(!(std::is_convertible<Mat3, Matrix3>::value)); CORRADE_VERIFY(!(std::is_convertible<Mat3, Matrix3x3>::value));
CORRADE_VERIFY(!(std::is_convertible<Matrix3, Mat3>::value)); CORRADE_VERIFY(!(std::is_convertible<Matrix3x3, Mat3>::value));
} }
void MatrixTest::isOrthogonal() { void MatrixTest::isOrthogonal() {
CORRADE_VERIFY(!Matrix3(Vector3(1.0f, 0.0f, 0.0f), CORRADE_VERIFY(!Matrix3x3(Vector3(1.0f, 0.0f, 0.0f),
Vector3(0.0f, 1.0f, 0.0f), Vector3(0.0f, 1.0f, 0.0f),
Vector3(0.0f, 0.1f, 1.0f)).isOrthogonal()); Vector3(0.0f, 0.1f, 1.0f)).isOrthogonal());
CORRADE_VERIFY(!Matrix3(Vector3(1.0f, 0.0f, 0.0f), CORRADE_VERIFY(!Matrix3x3(Vector3(1.0f, 0.0f, 0.0f),
Vector3(0.0f, 1.0f, 0.0f), Vector3(0.0f, 1.0f, 0.0f),
Vector3(0.0f, 1.0f, 0.0f)).isOrthogonal()); Vector3(0.0f, 1.0f, 0.0f)).isOrthogonal());
CORRADE_VERIFY(Matrix3(Vector3(1.0f, 0.0f, 0.0f), CORRADE_VERIFY(Matrix3x3(Vector3(1.0f, 0.0f, 0.0f),
Vector3(0.0f, 1.0f, 0.0f), Vector3(0.0f, 1.0f, 0.0f),
Vector3(0.0f, 0.0f, 1.0f)).isOrthogonal()); Vector3(0.0f, 0.0f, 1.0f)).isOrthogonal());
} }
void MatrixTest::trace() { void MatrixTest::trace() {
@ -232,14 +232,14 @@ void MatrixTest::trace() {
} }
void MatrixTest::ij() { void MatrixTest::ij() {
Matrix4 original(Vector4( 0.0f, 1.0f, 2.0f, 3.0f), Matrix4x4 original(Vector4( 0.0f, 1.0f, 2.0f, 3.0f),
Vector4( 4.0f, 5.0f, 6.0f, 7.0f), Vector4( 4.0f, 5.0f, 6.0f, 7.0f),
Vector4( 8.0f, 9.0f, 10.0f, 11.0f), Vector4( 8.0f, 9.0f, 10.0f, 11.0f),
Vector4(12.0f, 13.0f, 14.0f, 15.0f)); Vector4(12.0f, 13.0f, 14.0f, 15.0f));
Matrix3 skipped(Vector3( 0.0f, 1.0f, 3.0f), Matrix3x3 skipped(Vector3( 0.0f, 1.0f, 3.0f),
Vector3( 8.0f, 9.0f, 11.0f), Vector3( 8.0f, 9.0f, 11.0f),
Vector3(12.0f, 13.0f, 15.0f)); Vector3(12.0f, 13.0f, 15.0f));
CORRADE_COMPARE(original.ij(1, 2), skipped); CORRADE_COMPARE(original.ij(1, 2), skipped);
} }
@ -257,33 +257,33 @@ void MatrixTest::determinant() {
} }
void MatrixTest::inverted() { void MatrixTest::inverted() {
Matrix4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), Matrix4x4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f),
Vector4(4.0f, 4.0f, 7.0f, 3.0f), Vector4(4.0f, 4.0f, 7.0f, 3.0f),
Vector4(7.0f, -1.0f, 8.0f, 0.0f), Vector4(7.0f, -1.0f, 8.0f, 0.0f),
Vector4(9.0f, 4.0f, 5.0f, 9.0f)); Vector4(9.0f, 4.0f, 5.0f, 9.0f));
Matrix4 inverse(Vector4(-60/103.0f, 71/103.0f, -4/103.0f, 3/103.0f), Matrix4x4 inverse(Vector4(-60/103.0f, 71/103.0f, -4/103.0f, 3/103.0f),
Vector4(-66/103.0f, 109/103.0f, -25/103.0f, -7/103.0f), Vector4(-66/103.0f, 109/103.0f, -25/103.0f, -7/103.0f),
Vector4(177/412.0f, -97/206.0f, 53/412.0f, -7/206.0f), Vector4(177/412.0f, -97/206.0f, 53/412.0f, -7/206.0f),
Vector4(259/412.0f, -185/206.0f, 31/412.0f, 27/206.0f)); Vector4(259/412.0f, -185/206.0f, 31/412.0f, 27/206.0f));
Matrix4 _inverse = m.inverted(); Matrix4x4 _inverse = m.inverted();
CORRADE_COMPARE(_inverse, inverse); CORRADE_COMPARE(_inverse, inverse);
CORRADE_COMPARE(_inverse*m, Matrix4()); CORRADE_COMPARE(_inverse*m, Matrix4x4());
} }
void MatrixTest::invertedOrthogonal() { void MatrixTest::invertedOrthogonal() {
std::ostringstream o; std::ostringstream o;
Error::setOutput(&o); Error::setOutput(&o);
Matrix3 a(Vector3(Constants::sqrt3()/2.0f, 0.5f, 0.0f), Matrix3x3 a(Vector3(Constants::sqrt3()/2.0f, 0.5f, 0.0f),
Vector3(-0.5f, Constants::sqrt3()/2.0f, 0.0f), Vector3(-0.5f, Constants::sqrt3()/2.0f, 0.0f),
Vector3(0.0f, 0.0f, 1.0f)); Vector3(0.0f, 0.0f, 1.0f));
(a*2).invertedOrthogonal(); (a*2).invertedOrthogonal();
CORRADE_COMPARE(o.str(), "Math::Matrix::invertedOrthogonal(): the matrix is not orthogonal\n"); CORRADE_COMPARE(o.str(), "Math::Matrix::invertedOrthogonal(): the matrix is not orthogonal\n");
CORRADE_COMPARE(a.invertedOrthogonal()*a, Matrix3()); CORRADE_COMPARE(a.invertedOrthogonal()*a, Matrix3x3());
CORRADE_COMPARE(a.invertedOrthogonal(), a.inverted()); CORRADE_COMPARE(a.invertedOrthogonal(), a.inverted());
} }
@ -344,10 +344,10 @@ void MatrixTest::subclass() {
} }
void MatrixTest::debug() { void MatrixTest::debug() {
Matrix4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), Matrix4x4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f),
Vector4(4.0f, 4.0f, 7.0f, 3.0f), Vector4(4.0f, 4.0f, 7.0f, 3.0f),
Vector4(7.0f, -1.0f, 8.0f, 0.0f), Vector4(7.0f, -1.0f, 8.0f, 0.0f),
Vector4(9.0f, 4.0f, 5.0f, 9.0f)); Vector4(9.0f, 4.0f, 5.0f, 9.0f));
std::ostringstream o; std::ostringstream o;
Debug(&o) << m; Debug(&o) << m;
@ -357,7 +357,7 @@ void MatrixTest::debug() {
" 4, 3, 0, 9)\n"); " 4, 3, 0, 9)\n");
o.str({}); o.str({});
Debug(&o) << "a" << Matrix4() << "b" << Matrix4(); Debug(&o) << "a" << Matrix4x4() << "b" << Matrix4x4();
CORRADE_COMPARE(o.str(), "a Matrix(1, 0, 0, 0,\n" CORRADE_COMPARE(o.str(), "a Matrix(1, 0, 0, 0,\n"
" 0, 1, 0, 0,\n" " 0, 1, 0, 0,\n"
" 0, 0, 1, 0,\n" " 0, 0, 1, 0,\n"
@ -370,15 +370,15 @@ void MatrixTest::debug() {
void MatrixTest::configuration() { void MatrixTest::configuration() {
Corrade::Utility::Configuration c; Corrade::Utility::Configuration c;
Matrix4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f), Matrix4x4 m(Vector4(3.0f, 5.0f, 8.0f, 4.0f),
Vector4(4.0f, 4.0f, 7.0f, 3.125f), Vector4(4.0f, 4.0f, 7.0f, 3.125f),
Vector4(7.0f, -1.0f, 8.0f, 0.0f), Vector4(7.0f, -1.0f, 8.0f, 0.0f),
Vector4(9.0f, 4.0f, 5.0f, 9.55f)); Vector4(9.0f, 4.0f, 5.0f, 9.55f));
std::string value("3 4 7 9 5 4 -1 4 8 7 8 5 4 3.125 0 9.55"); std::string value("3 4 7 9 5 4 -1 4 8 7 8 5 4 3.125 0 9.55");
c.setValue("matrix", m); c.setValue("matrix", m);
CORRADE_COMPARE(c.value("matrix"), value); CORRADE_COMPARE(c.value("matrix"), value);
CORRADE_COMPARE(c.value<Matrix4>("matrix"), m); CORRADE_COMPARE(c.value<Matrix4x4>("matrix"), m);
} }
}}} }}}

6
src/Math/Test/QuaternionTest.cpp

@ -69,7 +69,7 @@ class QuaternionTest: public Corrade::TestSuite::Tester {
typedef Math::Deg<Float> Deg; typedef Math::Deg<Float> Deg;
typedef Math::Rad<Float> Rad; typedef Math::Rad<Float> Rad;
typedef Math::Matrix<3, Float> Matrix3; typedef Math::Matrix<3, Float> Matrix3x3;
typedef Math::Matrix4<Float> Matrix4; typedef Math::Matrix4<Float> Matrix4;
typedef Math::Quaternion<Float> Quaternion; typedef Math::Quaternion<Float> Quaternion;
typedef Math::Vector3<Float> Vector3; typedef Math::Vector3<Float> Vector3;
@ -283,7 +283,7 @@ void QuaternionTest::matrix() {
Vector3 axis = Vector3(1.0f, -3.0f, 5.0f).normalized(); Vector3 axis = Vector3(1.0f, -3.0f, 5.0f).normalized();
Quaternion q = Quaternion::rotation(Deg(37.0f), axis); Quaternion q = Quaternion::rotation(Deg(37.0f), axis);
Matrix3 m = Matrix4::rotation(Deg(37.0f), axis).rotationScaling(); Matrix3x3 m = Matrix4::rotation(Deg(37.0f), axis).rotationScaling();
/* Verify that negated quaternion gives the same rotation */ /* Verify that negated quaternion gives the same rotation */
CORRADE_COMPARE(q.toMatrix(), m); CORRADE_COMPARE(q.toMatrix(), m);
@ -299,7 +299,7 @@ void QuaternionTest::matrix() {
CORRADE_COMPARE(Quaternion::fromMatrix(m), q); CORRADE_COMPARE(Quaternion::fromMatrix(m), q);
/* Trace < 0 */ /* Trace < 0 */
Matrix3 m2 = Matrix4::rotation(Deg(130.0f), axis).rotationScaling(); Matrix3x3 m2 = Matrix4::rotation(Deg(130.0f), axis).rotationScaling();
Quaternion q2 = Quaternion::rotation(Deg(130.0f), axis); Quaternion q2 = Quaternion::rotation(Deg(130.0f), axis);
CORRADE_VERIFY(m2.trace() < 0.0f); CORRADE_VERIFY(m2.trace() < 0.0f);
CORRADE_COMPARE(Quaternion::fromMatrix(m2), q2); CORRADE_COMPARE(Quaternion::fromMatrix(m2), q2);

62
src/Math/Test/RectangularMatrixTest.cpp

@ -90,8 +90,8 @@ class RectangularMatrixTest: public Corrade::TestSuite::Tester {
typedef RectangularMatrix<4, 3, Float> Matrix4x3; typedef RectangularMatrix<4, 3, Float> Matrix4x3;
typedef RectangularMatrix<3, 4, Float> Matrix3x4; typedef RectangularMatrix<3, 4, Float> Matrix3x4;
typedef RectangularMatrix<2, 2, Float> Matrix2; typedef RectangularMatrix<2, 2, Float> Matrix2x2;
typedef RectangularMatrix<2, 2, Int> Matrix2i; typedef RectangularMatrix<2, 2, Int> Matrix2x2i;
typedef Vector<4, Float> Vector4; typedef Vector<4, Float> Vector4;
typedef Vector<3, Float> Vector3; typedef Vector<3, Float> Vector3;
typedef Vector<2, Float> Vector2; typedef Vector<2, Float> Vector2;
@ -152,19 +152,19 @@ void RectangularMatrixTest::constructDefault() {
} }
void RectangularMatrixTest::constructConversion() { void RectangularMatrixTest::constructConversion() {
constexpr Matrix2 a(Vector2( 1.3f, 2.7f), constexpr Matrix2x2 a(Vector2( 1.3f, 2.7f),
Vector2(-15.0f, 7.0f)); Vector2(-15.0f, 7.0f));
#ifndef CORRADE_GCC46_COMPATIBILITY #ifndef CORRADE_GCC46_COMPATIBILITY
constexpr Matrix2i b(a); constexpr Matrix2x2i b(a);
#else #else
Matrix2i b(a); /* Not constexpr under GCC < 4.7 */ Matrix2x2i b(a); /* Not constexpr under GCC < 4.7 */
#endif #endif
CORRADE_COMPARE(b, Matrix2i(Vector2i( 1, 2), CORRADE_COMPARE(b, Matrix2x2i(Vector2i( 1, 2),
Vector2i(-15, 7))); Vector2i(-15, 7)));
/* Implicit conversion is not allowed */ /* Implicit conversion is not allowed */
CORRADE_VERIFY(!(std::is_convertible<Matrix2, Matrix2i>::value)); CORRADE_VERIFY(!(std::is_convertible<Matrix2x2, Matrix2x2i>::value));
} }
void RectangularMatrixTest::constructFromData() { void RectangularMatrixTest::constructFromData() {
@ -268,28 +268,28 @@ void RectangularMatrixTest::row() {
} }
void RectangularMatrixTest::compare() { void RectangularMatrixTest::compare() {
Matrix2 a(Vector2(1.0f, -3.0f), Matrix2x2 a(Vector2(1.0f, -3.0f),
Vector2(5.0f, -10.0f)); Vector2(5.0f, -10.0f));
Matrix2 b(Vector2(1.0f + TypeTraits<Float>::epsilon()/2, -3.0f), Matrix2x2 b(Vector2(1.0f + TypeTraits<Float>::epsilon()/2, -3.0f),
Vector2(5.0f, -10.0f)); Vector2(5.0f, -10.0f));
Matrix2 c(Vector2(1.0f, -1.0f + TypeTraits<Float>::epsilon()*2), Matrix2x2 c(Vector2(1.0f, -1.0f + TypeTraits<Float>::epsilon()*2),
Vector2(5.0f, -10.0f)); Vector2(5.0f, -10.0f));
CORRADE_VERIFY(a == b); CORRADE_VERIFY(a == b);
CORRADE_VERIFY(a != c); CORRADE_VERIFY(a != c);
Matrix2i ai(Vector2i(1, -3), Matrix2x2i ai(Vector2i(1, -3),
Vector2i(5, -10)); Vector2i(5, -10));
Matrix2i bi(Vector2i(1, -2), Matrix2x2i bi(Vector2i(1, -2),
Vector2i(5, -10)); Vector2i(5, -10));
CORRADE_VERIFY(ai == ai); CORRADE_VERIFY(ai == ai);
CORRADE_VERIFY(ai != bi); CORRADE_VERIFY(ai != bi);
} }
void RectangularMatrixTest::negative() { void RectangularMatrixTest::negative() {
Matrix2 matrix(Vector2(1.0f, -3.0f), Matrix2x2 matrix(Vector2(1.0f, -3.0f),
Vector2(5.0f, -10.0f)); Vector2(5.0f, -10.0f));
Matrix2 negated(Vector2(-1.0f, 3.0f), Matrix2x2 negated(Vector2(-1.0f, 3.0f),
Vector2(-5.0f, 10.0f)); Vector2(-5.0f, 10.0f));
CORRADE_COMPARE(-matrix, negated); CORRADE_COMPARE(-matrix, negated);
} }
@ -312,20 +312,20 @@ void RectangularMatrixTest::addSubtract() {
} }
void RectangularMatrixTest::multiplyDivide() { void RectangularMatrixTest::multiplyDivide() {
Matrix2 matrix(Vector2(1.0f, 2.0f), Matrix2x2 matrix(Vector2(1.0f, 2.0f),
Vector2(3.0f, 4.0f)); Vector2(3.0f, 4.0f));
Matrix2 multiplied(Vector2(-1.5f, -3.0f), Matrix2x2 multiplied(Vector2(-1.5f, -3.0f),
Vector2(-4.5f, -6.0f)); Vector2(-4.5f, -6.0f));
CORRADE_COMPARE(matrix*-1.5f, multiplied); CORRADE_COMPARE(matrix*-1.5f, multiplied);
CORRADE_COMPARE(-1.5f*matrix, multiplied); CORRADE_COMPARE(-1.5f*matrix, multiplied);
CORRADE_COMPARE(multiplied/-1.5f, matrix); CORRADE_COMPARE(multiplied/-1.5f, matrix);
/* Divide vector with number and inverse */ /* Divide vector with number and inverse */
Matrix2 divisor(Vector2( 1.0f, 2.0f), Matrix2x2 divisor(Vector2( 1.0f, 2.0f),
Vector2(-4.0f, 8.0f)); Vector2(-4.0f, 8.0f));
Matrix2 result(Vector2( 1.0f, 0.5f), Matrix2x2 result(Vector2( 1.0f, 0.5f),
Vector2(-0.25f, 0.125f)); Vector2(-0.25f, 0.125f));
CORRADE_COMPARE(1.0f/divisor, result); CORRADE_COMPARE(1.0f/divisor, result);
} }

2
src/Shaders/Phong.h

@ -167,7 +167,7 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram {
* @brief Set normal matrix * @brief Set normal matrix
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
*/ */
Phong& setNormalMatrix(const Math::Matrix<3, Float>& matrix) { Phong& setNormalMatrix(const Matrix3x3& matrix) {
setUniform(normalMatrixUniform, matrix); setUniform(normalMatrixUniform, matrix);
return *this; return *this;
} }

Loading…
Cancel
Save