6 Commits
plot ... 1.0.0

Author SHA1 Message Date
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
5 changed files with 73 additions and 36 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>
@@ -55,9 +56,8 @@ void PivotGui::Render() {
static bool refresh = true; static bool refresh = true;
// divisions des fenetres // divisions des fenetres
ImVec2 topLeftWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.8f); ImVec2 topLeftWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y);
ImVec2 topRightWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.8f); ImVec2 topRightWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y);
ImVec2 bottomWindowSize(io.DisplaySize.x, io.DisplaySize.y * 0.2f);
// Begin fenetre top left // Begin fenetre top left
ImGui::SetNextWindowSize(topLeftWindowSize); ImGui::SetNextWindowSize(topLeftWindowSize);
@@ -85,7 +85,7 @@ void PivotGui::Render() {
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
@@ -101,7 +101,7 @@ void PivotGui::Render() {
if (x > 0) if (x > 0)
ImGui::SameLine(); ImGui::SameLine();
ImGui::PushID(y * matrixSizeX + x); ImGui::PushID(y * 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("", &matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal))
refresh = true; refresh = true;
ImGui::PopItemWidth(); ImGui::PopItemWidth();
@@ -109,12 +109,30 @@ void PivotGui::Render() {
} }
} }
// 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::EndChild(); // End Matrice initiale ImGui::NewLine();
ImGui::Text("Matrice échelonnée:");
// Convert the "result" string back to a matrix
Matrix resultMatrix = LoadMatrixFromStdVect(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::End(); // End fenetre top left ImGui::End(); // End fenetre top left
@@ -128,16 +146,6 @@ void PivotGui::Render() {
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
@@ -160,7 +168,15 @@ void PivotGui::Render() {
} }
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::End(); // End fenetre top right
} }
void PivotGui::Destroy() {} void PivotGui::Destroy() {}

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 = 7;
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")