Browse Source

Math: overload RectangularMatrix::diagonal() in subclasses.

...to return proper type.
pull/51/head
Vladimír Vondruš 13 years ago
parent
commit
01599e7d11
  1. 3
      src/Math/RectangularMatrix.h
  2. 4
      src/Math/Test/RectangularMatrixTest.cpp

3
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<const __VA_ARGS__*>(data); \
} \
constexpr static __VA_ARGS__ fromDiagonal(const Vector<Math::RectangularMatrix<cols, rows, T>::DiagonalSize, T>& diagonal) { \
return Math::RectangularMatrix<cols, rows, T>::fromDiagonal(diagonal); \
} \
\
__VA_ARGS__ operator-() const { \

4
src/Math/Test/RectangularMatrixTest.cpp

@ -444,6 +444,7 @@ void RectangularMatrixTest::subclassTypes() {
const Float* const cdata = nullptr;
CORRADE_VERIFY((std::is_same<decltype(Mat2x2::from(data)), Mat2x2&>::value));
CORRADE_VERIFY((std::is_same<decltype(Mat2x2::from(cdata)), const Mat2x2&>::value));
CORRADE_VERIFY((std::is_same<decltype(Mat2x2::fromDiagonal({})), Mat2x2>::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),

Loading…
Cancel
Save