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

Move rayon to Rule class

parent 28bb3c82
......@@ -22,7 +22,6 @@ class Voisinage {
private :
const Cellule* celluleCentre;
vector<Cellule*> voisinage;
unsigned int r;
friend class RegleVoisinage;
friend class RegleVoisinageMoore;
friend class RegleVoisinageNeumann;
......@@ -60,8 +59,6 @@ public:
~Voisinage();
Cellule getCelluleCentre()const {return *celluleCentre;}
void setr(unsigned int rayon);
unsigned int getr() const {return r;}
VoisinageIterator *creerIterator()const{
return new VoisinageIterator(this);
}
......@@ -74,13 +71,21 @@ class RegleVoisinage{
};
class RegleVoisinageNeumann : public RegleVoisinage {
private:
unsigned int rayon;
public:
void calculVoisinage(Voisinage& v, const Reseau& r) override;
void setr(unsigned int r);
unsigned int getr() const { return rayon; }
};
class RegleVoisinageMoore : public RegleVoisinage {
private:
unsigned int rayon;
public:
void calculVoisinage(Voisinage& v, const Reseau& r) override;
void setr(unsigned int r);
unsigned int getr() const { return rayon; }
};
class RegleVoisinageArbitraire : public RegleVoisinage { //définit la règle pour le voisinage arbitraire
......
......@@ -51,7 +51,7 @@ void Database::initEnsEtat(const QString& name) const {
throw "Unable to select this object";
EnsembleEtat& ens = EnsembleEtat::getInstance();
ens.reset()
ens.reset();
do {
unsigned int ind = static_cast<unsigned int>(query.value("indice").toInt());
......
......@@ -3,9 +3,16 @@
#include<cmath>
#include<iostream>
void Voisinage::setr(unsigned int rayon){
if(rayon >= 0)
r = rayon;
void RegleVoisinageNeumann::setr(unsigned int r){
if(r >= 0)
rayon = r;
else
throw ("Rayon incorrect !\n");
}
void RegleVoisinageMoore::setr(unsigned int r){
if(r >= 0)
rayon = r;
else
throw ("Rayon incorrect !\n");
}
......@@ -18,9 +25,9 @@ void RegleVoisinageNeumann::calculVoisinage(Voisinage& v, const Reseau& r) {
unsigned int hauteur = r.getHauteur();
unsigned int largeur = r.getLargeur();
for (int i = -v.r; i <= v.r; i++)
for (int j = -v.r; j <= v.r; j++)
if (abs(i) + abs(j) <= v.r && i != 0 && j != 0)
for (int i = -rayon; i <= rayon; i++)
for (int j = -rayon; j <= rayon; j++)
if (abs(i) + abs(j) <= rayon && i != 0 && j != 0)
v.voisinage.push_back(&r.getReseau()[(cellY+i)%hauteur][(cellX+j)%largeur]);
}
......@@ -32,9 +39,9 @@ void RegleVoisinageMoore::calculVoisinage(Voisinage& v, const Reseau& r) {
unsigned int hauteur = r.getHauteur();
unsigned int largeur = r.getLargeur();
for (int i = -v.r; i <= v.r; i++)
for (int j = -v.r; j <= v.r; j++)
if (abs(i) <= v.r && abs(j) <= v.r && i != 0 && j != 0)
for (int i = -rayon; i <= rayon; i++)
for (int j = -rayon; j <= rayon; j++)
if (abs(i) <= rayon && abs(j) <= rayon && i != 0 && j != 0)
v.voisinage.push_back(&r.getReseau()[(cellY+i)%hauteur][(cellX+j)%largeur]);
}
......
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