Verified Commit 8b0d017a authored by Romain De Laage De Bellefaye's avatar Romain De Laage De Bellefaye 🌳
Browse files

Resolve segfault

parent a11f44e5
Pipeline #79806 passed with stage
in 16 seconds
......@@ -143,7 +143,7 @@ class RegleVoisinageArbitraire : public RegleVoisinage {
/// @param[in] r Réseau à partir duquel on souhaite calculer le voisinage
void calculVoisinage(Voisinage& v, const Reseau& r) const override;
/// Obtenir les coordonnées relative d'un voisinage arbitraire en fonction d'un outil QTableWidget
vector<Coordonnees> getVoisinage(const QTableWidget* grid );
void getVoisinage(const QTableWidget* grid );
};
#endif /* voisinage_h */
......@@ -21,7 +21,7 @@ Database::Database(std::string path): db(QSqlDatabase::addDatabase("QSQLITE")) {
db.exec("CREATE TABLE IF NOT EXISTS EnsembleEtats (id INTEGER PRIMARY KEY, automate VARCHAR(30) NOT NULL, UNIQUE(automate), FOREIGN KEY('automate') REFERENCES 'automates'('nom'))");
db.exec("CREATE TABLE IF NOT EXISTS Etats (ensemble INTEGER NOT NULL, indice INTEGER NOT NULL, label VARCHAR NOT NULL, r INTEGER NOT NULL, g INTEGER NOT NULL, b INTEGER NOT NULL, CHECK(indice>=0), CHECK(r>=0), CHECK(r<=255), CHECK(g>=0), CHECK(g<=255), CHECK(b>=0), CHECK(b<=255), PRIMARY KEY (ensemble, indice), FOREIGN KEY(ensemble') REFERENCES 'EnsembleEtats'('id'))");
db.exec("CREATE TABLE IF NOT EXISTS Etats (ensemble INTEGER NOT NULL, indice INTEGER NOT NULL, label VARCHAR NOT NULL, r INTEGER NOT NULL, g INTEGER NOT NULL, b INTEGER NOT NULL, CHECK(indice>=0), CHECK(r>=0), CHECK(r<=255), CHECK(g>=0), CHECK(g<=255), CHECK(b>=0), CHECK(b<=255), PRIMARY KEY (ensemble, indice), FOREIGN KEY('ensemble') REFERENCES 'EnsembleEtats'('id'))");
db.exec("CREATE TABLE IF NOT EXISTS Cellules (reseau INTEGER NOT NULL, ensemble INTEGER NOT NULL, etat INTEGER NOT NULL, x INTEGER NOT NULL, y INTEGER NOT NULL, FOREIGN KEY('reseau') REFERENCES 'reseaux'('id'))");
......
......@@ -453,18 +453,7 @@ void NouveauModele::validerParametrage(){
else //arbitraire
{
RegleVoisinageArbitraire *regle_voisins = new RegleVoisinageArbitraire;
Coordonnees c;
for(unsigned int i=0; i<5; i++){
for(unsigned int j=0; j<5; j++)
{
if(grid->item(i,j)->background().color()==Qt::red)
{
c.x = i;
c.y = j;
regle_voisins->coordonnees.push_back(c);
}
}
}
regle_voisins->getVoisinage(grid);
Automate::getInstance().setRegleVoisinage(regle_voisins);
Database::getInstance().saveAutomaton(Automate::getInstance());
this->close();
......
......@@ -59,32 +59,31 @@ Voisinage::~Voisinage() {
void RegleVoisinageArbitraire::calculVoisinage(Voisinage &v, const Reseau& r) const { //définir get?
v.voisinage = std::vector<Cellule*>();
unsigned int abs = v.celluleCentre->abs;
unsigned int ord = v.celluleCentre->ord;
unsigned int hauteur = r.getHauteur();
unsigned int largeur = r.getLargeur();
int cellX = static_cast<int>(v.celluleCentre->abs);
int cellY = static_cast<int>(v.celluleCentre->ord);
int hauteur = static_cast<int>(r.getHauteur());
int largeur = static_cast<int>(r.getLargeur());
for (size_t nb = 0; nb < coordonnees.size(); nb++){
v.voisinage[nb] = new Cellule(r.getReseau()[(abs - coordonnees[nb].x)%hauteur] [(ord - coordonnees[nb].y)%largeur]);
int x = (cellY+coordonnees[nb].y)%largeur;
if (x < 0)
x = largeur + x;
int y = (cellX+coordonnees[nb].x)%hauteur;
if (y < 0)
y = hauteur + y;
v.voisinage.push_back(new Cellule(r.getReseau()[y][x]));
}
}
vector<Coordonnees> RegleVoisinageArbitraire::getVoisinage(const QTableWidget* grid)
{
vector<Coordonnees> coordonnees;
int k = 0;
void RegleVoisinageArbitraire::getVoisinage(const QTableWidget* grid) {
Coordonnees coordonnee;
for (unsigned int i = 0; i < 5; i++) {
for (unsigned int j = 0; j < 5; j++){
if (grid->item(i,j)->background() == Qt::red){
coordonnees[k].x = (2-i);
coordonnees[k].y = (2-j);
k += 1;
coordonnee.x = (i - 2);
coordonnee.y = (j - 2);
coordonnees.push_back(coordonnee);
}
}
}
return coordonnees;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment