Browse Source

Math: added *Matrix::setRow().

Row equivalent for the mutable operator[]().
pull/179/head
Vladimír Vondruš 10 years ago
parent
commit
9fdf467c59
  1. 17
      src/Magnum/Math/RectangularMatrix.h
  2. 11
      src/Magnum/Math/Test/RectangularMatrixTest.cpp

17
src/Magnum/Math/RectangularMatrix.h

@ -191,10 +191,20 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
* Consider using @ref transposed() when accessing rows frequently, as * Consider using @ref transposed() when accessing rows frequently, as
* this is slower than accessing columns due to the way the matrix is * this is slower than accessing columns due to the way the matrix is
* stored. * stored.
* @see @ref operator[]() * @see @ref setRow(), @ref operator[]()
*/ */
Vector<cols, T> row(std::size_t row) const; Vector<cols, T> 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<cols, T>& data);
/** @brief Equality comparison */ /** @brief Equality comparison */
bool operator==(const RectangularMatrix<cols, rows, T>& other) const { bool operator==(const RectangularMatrix<cols, rows, T>& other) const {
for(std::size_t i = 0; i != cols; ++i) for(std::size_t i = 0; i != cols; ++i)
@ -662,6 +672,11 @@ template<std::size_t cols, std::size_t rows, class T> inline Vector<cols, T> Rec
return out; return out;
} }
template<std::size_t cols, std::size_t rows, class T> inline void RectangularMatrix<cols, rows, T>::setRow(std::size_t row, const Vector<cols, T>& data) {
for(std::size_t i = 0; i != cols; ++i)
_data[i][row] = data[i];
}
template<std::size_t cols, std::size_t rows, class T> inline RectangularMatrix<cols, rows, T> RectangularMatrix<cols, rows, T>::operator-() const { template<std::size_t cols, std::size_t rows, class T> inline RectangularMatrix<cols, rows, T> RectangularMatrix<cols, rows, T>::operator-() const {
RectangularMatrix<cols, rows, T> out; RectangularMatrix<cols, rows, T> out;

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

@ -300,11 +300,16 @@ void RectangularMatrixTest::data() {
} }
void RectangularMatrixTest::row() { void RectangularMatrixTest::row() {
const Matrix3x4 a(Vector4(1.0f, 2.0f, 3.0f, 4.0f), Matrix3x4 a(Vector4(1.0f, 2.0f, 3.0f, 4.0f),
Vector4(5.0f, 6.0f, 7.0f, 8.0f), Vector4(5.0f, 6.0f, 7.0f, 8.0f),
Vector4(9.0f, 10.0f, 11.0f, 12.0f)); Vector4(9.0f, 10.0f, 11.0f, 12.0f));
CORRADE_COMPARE(a.row(1), Vector3(2.0f, 6.0f, 10.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() { void RectangularMatrixTest::compare() {

Loading…
Cancel
Save