From 01599e7d118f13858365e95818245599d97c87ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 5 Jan 2014 19:59:55 +0100 Subject: [PATCH] Math: overload RectangularMatrix::diagonal() in subclasses. ...to return proper type. --- src/Math/RectangularMatrix.h | 3 +++ src/Math/Test/RectangularMatrixTest.cpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index 311d545c7..8f1450364 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -542,6 +542,9 @@ extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utilit } \ static const __VA_ARGS__& from(const T* data) { \ return *reinterpret_cast(data); \ + } \ + constexpr static __VA_ARGS__ fromDiagonal(const Vector::DiagonalSize, T>& diagonal) { \ + return Math::RectangularMatrix::fromDiagonal(diagonal); \ } \ \ __VA_ARGS__ operator-() const { \ diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index d53544fa4..689ea1fee 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -444,6 +444,7 @@ void RectangularMatrixTest::subclassTypes() { const Float* const cdata = nullptr; CORRADE_VERIFY((std::is_same::value)); CORRADE_VERIFY((std::is_same::value)); + CORRADE_VERIFY((std::is_same::value)); /* Const operators */ const Mat2x2 c; @@ -479,6 +480,9 @@ void RectangularMatrixTest::subclass() { CORRADE_COMPARE(Mat2x2::from(cdata), Mat2x2(Vector2(1.0f, -2.0f), Vector2(3.0f, -4.5f))); + CORRADE_COMPARE(Mat2x2::fromDiagonal({1.0f, -2.0f}), Mat2x2(Vector2(1.0f, 0.0f), + Vector2(0.0f, -2.0f))); + const Mat2x2 a(Vector2(1.0f, -3.0f), Vector2(-3.0f, 1.0f)); CORRADE_COMPARE(-a, Mat2x2(Vector2(-1.0f, 3.0f),