9 Commits

Author SHA1 Message Date
9b84b9bf59 maybe fix test
Some checks failed
Linux arm64 / Build (push) Failing after 33m25s
2024-05-23 15:17:21 +02:00
bb650e4f2d gui refactor 2024-05-23 15:16:29 +02:00
e784a7b471 reduce solver random matrix size
Some checks failed
Linux arm64 / Build (push) Failing after 38m45s
2024-05-23 14:34:22 +02:00
9a5b99a79d init random
Some checks failed
Linux arm64 / Build (push) Failing after 2m43s
2024-05-14 23:09:51 +02:00
ffa0ebf4cb add missing include
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-05-14 22:51:53 +02:00
4b3e878bc5 removed weird function
Some checks failed
Linux arm64 / Build (push) Failing after 2m26s
2024-05-14 22:41:01 +02:00
47f250170e remove useless xmake require
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-05-14 22:39:57 +02:00
a4036ae36d add linear system test
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-05-14 22:39:15 +02:00
e6d0785009 show jordaned matrix
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-05-14 22:36:57 +02:00
6 changed files with 148 additions and 69 deletions

View File

@@ -105,12 +105,6 @@ class VectAffine {
*/ */
bool IsElementOf(const Matrix& a_Vector) const; bool IsElementOf(const Matrix& a_Vector) const;
/**
* \brief Exprime l'espace vectoriel comme les solutions d'un système linéaire des coordonnées des vecteurs
* \return Une matrice représentant le système linéaire
*/
Matrix GetLinearSystem() const;
bool operator==(const VectAffine& a_VectAffine) const { bool operator==(const VectAffine& a_VectAffine) const {
return m_Origin == a_VectAffine.GetOrigin() && m_Base == a_VectAffine.GetBase(); return m_Origin == a_VectAffine.GetOrigin() && m_Base == a_VectAffine.GetBase();
}; };

View File

@@ -88,11 +88,3 @@ VectAffine::VectAffine(const Vect& a_Base, const Matrix& a_Origin) :
bool VectAffine::IsElementOf(const Matrix& a_Vector) const { bool VectAffine::IsElementOf(const Matrix& a_Vector) const {
return m_Base.IsElementOf(a_Vector - m_Origin); return m_Base.IsElementOf(a_Vector - m_Origin);
} }
Matrix VectAffine::GetLinearSystem() const {
Matrix result = m_Base.GetLinearSystem();
result.Augment(m_Origin.SubMatrix(0, 0, result.GetRawCount(), 1));
return result;
}

View File

@@ -1,5 +1,6 @@
#include "PivotGui.h" #include "PivotGui.h"
#include "Gauss.h"
#include "Matrix.h" #include "Matrix.h"
#include "Solver.h" #include "Solver.h"
#include <imgui.h> #include <imgui.h>
@@ -7,6 +8,12 @@
static std::string equationsResultImage; static std::string equationsResultImage;
struct GuiMatrix {
std::vector<std::vector<int>> matrixValues;
int matrixSizeX = 4;
int matrixSizeY = 4;
};
static Matrix LoadMatrixFromStdVect(const std::vector<std::vector<int>>& data) { static Matrix LoadMatrixFromStdVect(const std::vector<std::vector<int>>& data) {
Matrix result {data.size(), data.empty() ? 0 : data[0].size()}; Matrix result {data.size(), data.empty() ? 0 : data[0].size()};
for (std::size_t i = 0; i < result.GetRawCount(); i++) { for (std::size_t i = 0; i < result.GetRawCount(); i++) {
@@ -44,104 +51,109 @@ static std::string PrintVect(const Vect& vect) {
void PivotGui::Init() {} void PivotGui::Init() {}
void PivotGui::Render() { static void RenderSystemTab() {}
ImGuiIO& io = ImGui::GetIO();
static std::vector<std::vector<int>> matrixValues;
static int matrixSizeX = 4;
static int matrixSizeY = 4;
static Solver solver;
static bool refresh = true;
static void RenderLeftGaussChild(bool& refresh, GuiMatrix& guiMatrix) {
// divisions des fenetres // divisions des fenetres
ImVec2 topLeftWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.8f); ImVec2 topLeftWindowSize(ImGui::GetContentRegionAvail().x * 0.5f, 0);
ImVec2 topRightWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.8f);
ImVec2 bottomWindowSize(io.DisplaySize.x, io.DisplaySize.y * 0.2f);
// Begin fenetre top left // Begin fenetre top left
ImGui::SetNextWindowSize(topLeftWindowSize); // ImGui::SetNextWindowPos(ImVec2(0, 0)); // Position at the top-left corner
ImGui::SetNextWindowPos(ImVec2(0, 0)); // Position at the top-left corner ImGui::BeginChild("Left Top Window", topLeftWindowSize, ImGuiChildFlags_Border);
ImGui::Begin("Left Top Window", nullptr, /*ImGui::Begin(, nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar); ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
*/
// ImGui::BeginTabBar("MainMenu");
// Get window position // Get window position
ImVec2 windowPos = ImGui::GetWindowPos(); ImVec2 windowPos = ImGui::GetWindowPos();
ImGui::Text("Matrice initiale:"); ImGui::Text("Matrice initiale:");
if (ImGui::InputInt("##RowsMatriceInitiale", &matrixSizeY)) if (ImGui::InputInt("##RowsMatriceInitiale", &guiMatrix.matrixSizeY))
refresh = true; refresh = true;
matrixSizeY = std::max(1, matrixSizeY); guiMatrix.matrixSizeY = std::max(1, guiMatrix.matrixSizeY);
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text("Lignes"); ImGui::Text("Lignes");
if (ImGui::InputInt("##ColumnsMatriceInitiale", &matrixSizeX)) if (ImGui::InputInt("##ColumnsMatriceInitiale", &guiMatrix.matrixSizeX))
refresh = true; refresh = true;
matrixSizeX = std::max(1, matrixSizeX); guiMatrix.matrixSizeX = std::max(1, guiMatrix.matrixSizeX);
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text("Colonnes"); ImGui::Text("Colonnes");
ImGui::NewLine(); ImGui::NewLine();
ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false); // ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false);
// Resize matrixValues and initialize new elements to 0 // Resize matrixValues and initialize new elements to 0
if (refresh) { if (refresh) {
matrixValues.resize(matrixSizeY); guiMatrix.matrixValues.resize(guiMatrix.matrixSizeY);
for (auto& row : matrixValues) { for (auto& row : guiMatrix.matrixValues) {
row.resize(matrixSizeX, 0); row.resize(guiMatrix.matrixSizeX, 0);
} }
} }
for (int y = 0; y < matrixSizeY; y++) { for (int y = 0; y < guiMatrix.matrixSizeY; y++) {
for (int x = 0; x < matrixSizeX; x++) { for (int x = 0; x < guiMatrix.matrixSizeX; x++) {
if (x > 0) if (x > 0)
ImGui::SameLine(); ImGui::SameLine();
ImGui::PushID(y * matrixSizeX + x); ImGui::PushID(y * guiMatrix.matrixSizeX + x);
ImGui::PushItemWidth(30); // Adjust this value to change the cell size ImGui::PushItemWidth(60); // Adjust this value to change the cell size
if (ImGui::InputInt("", &matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal)) if (ImGui::InputInt("", &guiMatrix.matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal))
refresh = true; refresh = true;
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::PopID(); ImGui::PopID();
} }
} }
// Display the equationsResult strings in the GUI if they are not empty // ImGui::EndChild(); // End Matrice initiale
if (!equationsResultImage.empty()) {
ImGui::TextWrapped(equationsResultImage.c_str()); ImGui::NewLine();
ImGui::Text("Matrice échelonnée:");
// Convert the "result" string back to a matrix
Matrix resultMatrix = LoadMatrixFromStdVect(guiMatrix.matrixValues);
// Apply the Gauss-Jordan elimination to the matrix
Gauss::GaussJordan(resultMatrix, true, true); // Assuming you want to reduce and normalize the matrix
// Display the matrix
for (std::size_t i = 0; i < resultMatrix.GetRawCount(); i++) {
for (std::size_t j = 0; j < resultMatrix.GetColumnCount(); j++) {
ImGui::PushID(i * resultMatrix.GetColumnCount() + j);
if (ImGui::Button(ElementToString(resultMatrix.at(i, j)).c_str(), ImVec2(70, 70))) { // Adjust the size as needed
// Handle button click here if needed
}
ImGui::PopID();
if (j < resultMatrix.GetColumnCount() - 1)
ImGui::SameLine();
}
} }
ImGui::EndChild(); // End Matrice initiale ImGui::EndChild();
}
ImGui::End(); // End fenetre top left
static void RenderRightGaussChild(bool& refresh, GuiMatrix& guiMatrix) {
static Solver solver;
// Begin fenetre top right // Begin fenetre top right
ImGui::SetNextWindowSize(topRightWindowSize); // ImGui::SetNextWindowSize(topRightWindowSize);
ImGui::SetNextWindowPos(ImVec2(windowPos.x + topLeftWindowSize.x, 0)); // Position at the top-right corner // ImGui::SetNextWindowPos(ImVec2(windowPos.x + topLeftWindowSize.x, 0)); // Position at the top-right corner
ImGui::Begin("Right Top Window", nullptr, ImGui::BeginChild("Right Top Window", {0, 0}, ImGuiChildFlags_Border);
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar); // ImGui::Begin("Right Top Window", nullptr,
// ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
// rajouter le code pour la partie top right // rajouter le code pour la partie top right
static std::string result = ""; static std::string result = "";
ImGui::TextWrapped(result.c_str());
ImGui::End(); // End fenetre top right
// Begin fenetre bas
ImGui::SetNextWindowSize(bottomWindowSize);
ImGui::SetNextWindowPos(ImVec2(0, io.DisplaySize.y * 0.8f)); // Position at the bottom-left corner
ImGui::Begin("Bottom Part", nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
if (refresh) { if (refresh) {
// Calculate the kernel and image // Calculate the kernel and image
Vect image = solver.Image(LoadMatrixFromStdVect(matrixValues)); Vect image = solver.Image(LoadMatrixFromStdVect(guiMatrix.matrixValues));
Matrix linearSystem = image.GetLinearSystem(); Matrix linearSystem = image.GetLinearSystem();
// Store the equationsResult strings in the global variable // Store the equationsResult strings in the global variable
@@ -154,13 +166,59 @@ void PivotGui::Render() {
equationsResultImage = equationsResultImage.substr(0, equationsResultImage.size() - 3) + " = 0\n"; equationsResultImage = equationsResultImage.substr(0, equationsResultImage.size() - 3) + " = 0\n";
} }
result = std::string("Noyau: ") + "\n" + PrintVect(solver.Kernel(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" + result = std::string("Noyau: ") + "\n" + PrintVect(solver.Kernel(LoadMatrixFromStdVect(guiMatrix.matrixValues))) + "\n" +
"Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" + "Image: " + "\n" + "\n" + "Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(guiMatrix.matrixValues))) + "\n" + "\n" +
PrintVect(image); "Image: " + "\n" + PrintVect(image);
} }
refresh = false; refresh = false;
ImGui::End(); // End fenetre bas
// Display the equationsResult strings in the GUI if they are not empty
if (!equationsResultImage.empty()) {
ImGui::TextWrapped("%s", equationsResultImage.c_str());
}
ImGui::TextWrapped("%s", result.c_str());
ImGui::EndChild(); // End fenetre top right
}
static void RenderGaussTab() {
static GuiMatrix guiMatrix;
static bool refresh = true;
RenderLeftGaussChild(refresh, guiMatrix);
ImGui::SameLine();
RenderRightGaussChild(refresh, guiMatrix);
}
static void RenderMainWindow() {
ImGuiIO& io = ImGui::GetIO();
ImGui::SetNextWindowSize(io.DisplaySize);
ImGui::SetNextWindowPos({0, 0});
ImGui::Begin("MainWindow", nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
ImGui::BeginTabBar("MainBar");
if (ImGui::BeginTabItem("Noyau et Image")) {
RenderGaussTab();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Systèmes")) {
RenderSystemTab();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
ImGui::End();
}
void PivotGui::Render() {
RenderMainWindow();
#ifndef NDEBUG
ImGui::ShowDemoWindow(nullptr);
#endif
} }
void PivotGui::Destroy() {} void PivotGui::Destroy() {}

View File

@@ -10,7 +10,7 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
const static int EXECUTION_COUNT = 10000; const static int EXECUTION_COUNT = 10000;
static constexpr int MATRIX_MAX_SIZE = 7; static constexpr int MATRIX_MAX_SIZE = 5;
static int GetRandomSize() { static int GetRandomSize() {
return rand() % MATRIX_MAX_SIZE + 1; return rand() % MATRIX_MAX_SIZE + 1;

View File

@@ -1,6 +1,27 @@
#include "Vect.h" #include "Vect.h"
#include "test_assert.h" #include "test_assert.h"
#include <algorithm>
const static int EXECUTION_COUNT = 100000;
static constexpr int MATRIX_MAX_SIZE = 5;
static int GetRandomSize() {
return rand() % MATRIX_MAX_SIZE + 1;
}
static int GetRandomInt() {
return GetRandomSize();
}
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
Matrix matrix {a_Raw, a_Column};
std::generate(matrix.GetLineIterator(0), matrix.GetLineIterator(a_Raw), []() { return GetRandomInt(); });
return matrix;
}
void TestVect() { void TestVect() {
Vect vect1 {{3, 2, { Vect vect1 {{3, 2, {
1, 2, 1, 2,
@@ -41,8 +62,23 @@ void TestVectAffine() {
test_assert(!aff.IsElementOf(Matrix::ColumnVector({1, 2, 3}))); test_assert(!aff.IsElementOf(Matrix::ColumnVector({1, 2, 3})));
} }
void TestLinearSystem() {
for (std::size_t i = 0; i < EXECUTION_COUNT; i++) {
Vect vect = GetRandomMatrix(GetRandomSize(), GetRandomSize());
Matrix systeme = vect.GetLinearSystem();
for (std::size_t j = 0; j < vect.GetCardinal(); j++) {
Matrix nullMatrix {systeme.GetColumnCount(), 1};
test_assert(systeme * vect.GetVector(j) == nullMatrix);
}
}
}
int main() { int main() {
srand(time(0));
TestVect(); TestVect();
TestVectAffine(); TestVectAffine();
TestLinearSystem();
return 0; return 0;
} }

View File

@@ -1,6 +1,5 @@
add_rules("mode.debug", "mode.release") add_rules("mode.debug", "mode.release")
add_requires("libsdl 2.28.3", {configs = {sdlmain = false}})
add_requires("imgui", {configs = {sdl2_no_renderer = true, opengl3 = true}}) add_requires("imgui", {configs = {sdl2_no_renderer = true, opengl3 = true}})
set_languages("c++20") set_languages("c++20")