diff --git a/src/Magnum/Math/RectangularMatrix.h b/src/Magnum/Math/RectangularMatrix.h index 5c5e5ebbe..41c60897f 100644 --- a/src/Magnum/Math/RectangularMatrix.h +++ b/src/Magnum/Math/RectangularMatrix.h @@ -191,10 +191,20 @@ template class RectangularMatrix { * Consider using @ref transposed() when accessing rows frequently, as * this is slower than accessing columns due to the way the matrix is * stored. - * @see @ref operator[]() + * @see @ref setRow(), @ref operator[]() */ Vector row(std::size_t row) const; + /** + * @brief Set matrix row + * + * Consider using @ref transposed() when accessing rows frequently, as + * this is slower than accessing columns due to the way the matrix is + * stored. + * @see @ref row(), @ref operator()[] + */ + void setRow(std::size_t row, const Vector& data); + /** @brief Equality comparison */ bool operator==(const RectangularMatrix& other) const { for(std::size_t i = 0; i != cols; ++i) @@ -662,6 +672,11 @@ template inline Vector Rec return out; } +template inline void RectangularMatrix::setRow(std::size_t row, const Vector& data) { + for(std::size_t i = 0; i != cols; ++i) + _data[i][row] = data[i]; +} + template inline RectangularMatrix RectangularMatrix::operator-() const { RectangularMatrix out; diff --git a/src/Magnum/Math/Test/RectangularMatrixTest.cpp b/src/Magnum/Math/Test/RectangularMatrixTest.cpp index 7deb7e198..d1adf3735 100644 --- a/src/Magnum/Math/Test/RectangularMatrixTest.cpp +++ b/src/Magnum/Math/Test/RectangularMatrixTest.cpp @@ -300,11 +300,16 @@ void RectangularMatrixTest::data() { } void RectangularMatrixTest::row() { - const Matrix3x4 a(Vector4(1.0f, 2.0f, 3.0f, 4.0f), - Vector4(5.0f, 6.0f, 7.0f, 8.0f), - Vector4(9.0f, 10.0f, 11.0f, 12.0f)); + Matrix3x4 a(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(5.0f, 6.0f, 7.0f, 8.0f), + Vector4(9.0f, 10.0f, 11.0f, 12.0f)); CORRADE_COMPARE(a.row(1), Vector3(2.0f, 6.0f, 10.0f)); + + a.setRow(1, {-2.1f, -6.1f, -10.1f}); + CORRADE_COMPARE(a, (Matrix3x4{Vector4{1.0f, -2.1f, 3.0f, 4.0f}, + Vector4{5.0f, -6.1f, 7.0f, 8.0f}, + Vector4{9.0f, -10.1f, 11.0f, 12.0f}})); } void RectangularMatrixTest::compare() {