diff --git a/src/Matrix.cpp b/src/Matrix.cpp index 0a7908c..8b3a7c9 100644 --- a/src/Matrix.cpp +++ b/src/Matrix.cpp @@ -109,17 +109,20 @@ void Matrix::Transpose() { } void Matrix::Identity() { + assert(m_Lignes == m_Colonnes); for (std::size_t i = 0; i < m_Lignes; i++) { for (std::size_t j = i; j < m_Colonnes; j++) { - if (i != j) { - at(i, j) = 0; - } else { - at(i, j) = 1; - } + at(i, j) = i == j; } } } +Matrix Matrix::Identity(std::size_t taille) { + Matrix id{taille, taille}; + id.Identity(); + return id; +} + bool Matrix::IsInversed() const { for (std::size_t i = 0; i < m_Lignes; ++i) { std::size_t j; diff --git a/src/Matrix.h b/src/Matrix.h index 3bb3f39..5122715 100644 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -40,6 +40,8 @@ class Matrix { void Identity(); + static Matrix Identity(std::size_t taille); + bool IsInversed() const; Matrix SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const;