diff --git a/src/gui/PivotGui.cpp b/src/gui/PivotGui.cpp index d206049..a5e41a7 100644 --- a/src/gui/PivotGui.cpp +++ b/src/gui/PivotGui.cpp @@ -4,6 +4,8 @@ #include "Solver.h" #include +static std::string equationsResultImage; + static Matrix LoadMatrixFromStdVect(const std::vector>& data) { Matrix result {data.size(), data.empty() ? 0 : data[0].size()}; for (std::size_t i = 0; i < result.GetRawCount(); i++) { @@ -15,6 +17,9 @@ static Matrix LoadMatrixFromStdVect(const std::vector>& data) { } static std::string PrintVect(const Vect& vect) { + if (vect.GetCardinal() == 0) + return "{0}"; + std::string result = "Vect( "; for (std::size_t i = 0; i < vect.GetCardinal(); i++) { Matrix vector = vect.GetVector(i); @@ -84,7 +89,10 @@ void PivotGui::Render() { } } - ImGui::Text("Matrice finale:"); + // Display the equationsResult strings in the GUI if they are not empty + if (!equationsResultImage.empty()) { + ImGui::TextWrapped(equationsResultImage.c_str()); + } ImGui::EndChild(); // End Matrice initiale @@ -100,7 +108,7 @@ void PivotGui::Render() { static std::string result = "RIEN"; - ImGui::Text(result.c_str()); + ImGui::TextWrapped(result.c_str()); ImGui::End(); // End fenetre top right @@ -110,22 +118,36 @@ void PivotGui::Render() { ImGui::Begin("Bottom Part", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar); - // rajouter des boutons clickables - if (ImGui::Button("Calcul noyau")) { - // Code de calcul - Vect kernel = solver.Kernel(LoadMatrixFromStdVect(matrixValues)); + if (ImGui::Button("Calcul")) { - result = PrintVect(kernel); - } - ImGui::SameLine(); // Align buttons horizontally - if (ImGui::Button("Calcul rang")) { - // Code de calcul - std::size_t rank = solver.Rank(LoadMatrixFromStdVect(matrixValues)); - } - ImGui::SameLine(); // Align buttons horizontally - if (ImGui::Button("Calcul image")) { - // Code de calcul + // Calculate the kernel and image Vect image = solver.Image(LoadMatrixFromStdVect(matrixValues)); + Matrix linearSystem = image.GetLinearSystem(); + + // Create a column matrix with as many elements as the number of columns in the linear system + std::vector columnMatrix(linearSystem.GetColumnCount()); + for (size_t i = 0; i < linearSystem.GetColumnCount(); ++i) { + columnMatrix[i] = std::string(1, 'a' + static_cast(i)); + } + + // Multiply the linear system matrix by the column matrix + std::vector resultMatrix(linearSystem.GetRawCount()); + for (size_t i = 0; i < linearSystem.GetRawCount(); ++i) { + for (size_t j = 0; j < linearSystem.GetColumnCount(); ++j) { + resultMatrix[i] += std::to_string(static_cast(linearSystem.at(i, j))) + "*" + columnMatrix[j] + " + "; + } + resultMatrix[i] = resultMatrix[i].substr(0, resultMatrix[i].length() - 3) + " = 0"; + } + + // Store the equationsResult strings in the global variable + equationsResultImage = "Equations cartesiennes de l'espace vectoriel (Image):\n"; + for (const auto& equation : resultMatrix) { + equationsResultImage += equation + "\n"; + } + + result = std::string("Noyau: ") + "\n" + PrintVect(solver.Kernel(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" + + "Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" + + "Image: " + "\n" + PrintVect(image); } ImGui::End(); // End fenetre bas diff --git a/src/gui/PivotGui.h b/src/gui/PivotGui.h index a9245fe..de534f1 100644 --- a/src/gui/PivotGui.h +++ b/src/gui/PivotGui.h @@ -7,4 +7,4 @@ void Init(); void Render(); void Destroy(); -} // namespace PivotGui +} // namespace PivotGui \ No newline at end of file