Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LO21_Pin_Noir_Boucher_Bouri_Detree
CellulutLO21
Commits
97af64b7
Commit
97af64b7
authored
May 11, 2021
by
Yann Boucher
Browse files
Implemented ArbitraryNeighborhoodRule and its tests => fixed
#32
parent
75fd9aa8
Pipeline
#77836
passed with stages
in 16 seconds
Changes
13
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
include/arbitraryneighborhoodrule.hpp
0 → 100644
View file @
97af64b7
/**
\file arbitraryneighborhoodrule.hpp
\date 11/05/2021
\author Yann Boucher
\version 1
\brief ArbitraryNeighborhoodRule
Représente un voisinage arbitraire, défini par l'utilisateur.
**/
#ifndef ARBITRARYNEIGHBORHOODRULE_HPP
#define ARBITRARYNEIGHBORHOODRULE_HPP
#include
"neighborhoodrule.hpp"
#include
"property.hpp"
class
ArbitraryNeighborhoodRule
:
public
HasUserProperties
{
public:
virtual
Neighborhood
getNeighborhood
(
const
Grid
&
grid
,
Coord
pos
)
const
;
virtual
std
::
vector
<
NeighborhoodFormat
>
getFormats
()
const
;
public:
DEFINE_CONFIGURABLE_DYNLIST
(
CoordinateProperty
,
neighbors
,
"neighbors"
,
());
};
#endif // ARBITRARYNEIGHBORHOODRULE_HPP
include/neighborhood.hpp
View file @
97af64b7
...
...
@@ -38,7 +38,7 @@ class Neighborhood {
//! \brief Fonction vérifiant que la coordonnée d'un voisin que l'on souhaite ajouter dans le vecteur neighborPositions est unique
//! \param Coord : Coordonnée à comparer
//! \return retourne vrai si la coordonnée est unique sinon faux s'il existe un doublon
bool
isUnique
(
const
Coord
c
)
const
;
bool
isUnique
(
Coord
c
)
const
;
public:
//! \brief Retourne le nombre de voisin ayant l'état définit en paramètre
//! \param State : Etat des voisins à rechercher
...
...
@@ -48,7 +48,7 @@ public:
//! \brief Retourne l'état de la cellule voisine située à la coordonnée relative entrée en paramètre
//! \param Coordonnée du voisin à trouver
//! \return L'état de la cellule
unsigned
getAt
(
const
Coord
c
)
const
;
unsigned
getAt
(
Coord
c
)
const
;
//! \brief Ajoute un voisin au vecteur des voisins. Prend une coordonnée et un état en paramètre
//! \param Coord, State : coordonée relative et état du voisin
...
...
include/property.hpp
View file @
97af64b7
...
...
@@ -31,6 +31,8 @@ Fichier définissant la classe Property représentant une propriété chargable,
#include
<QJsonObject>
#include
<QFile>
#include
"coord.hpp"
struct
StringProperty
;
struct
IntegerProperty
;
struct
CoordinateProperty
;
...
...
@@ -173,7 +175,11 @@ Représente une coordonnée relative 2D.
struct
CoordinateProperty
:
public
PropertyImpl
<
CoordinateProperty
>
{
public:
int
x
=
0
,
y
=
0
;
CoordinateProperty
()
=
default
;
CoordinateProperty
(
Coord
arg
)
:
c
(
arg
)
{}
Coord
c
;
};
/**
...
...
include/structure.hpp
View file @
97af64b7
...
...
@@ -25,7 +25,6 @@ Fichier contenant la classe Structure, représentant un ensemble de cellules con
Cette classe permet de représenter un ensemble de cellules constituant une structure, comme un oscillateur ou un glider.
**/
// TODO : contrainte d'unicité (utiliser std::unordered_map?)
class
Structure
{
public:
...
...
include/structurereader.hpp
View file @
97af64b7
...
...
@@ -17,7 +17,6 @@ Fichier contenant la classe StructureReader et ses filles, permettant de lire un
class
Structure
;
// TODO : adapter cettre classe d'Exception en la faisant hériter à notre propre classe d'Exception
class
StructureReaderException
:
public
std
::
exception
{
public:
...
...
src/arbitraryneighborhoodrule.cpp
0 → 100644
View file @
97af64b7
/**
\file arbitraryneighborhoodrule.cpp
\date 11/05/2021
\author Yann Boucher
\version 1
\brief ArbitraryNeighborhoodRule
Représente un voisinage arbitraire, défini par l'utilisateur.
**/
#include
"arbitraryneighborhoodrule.hpp"
#include
"neighborhood.hpp"
#include
"grid.h"
Neighborhood
ArbitraryNeighborhoodRule
::
getNeighborhood
(
const
Grid
&
grid
,
Coord
pos
)
const
{
Neighborhood
n
;
for
(
const
auto
&
item
:
neighbors
.
contents
)
{
CoordinateProperty
coord
=
static_cast
<
CoordinateProperty
&>
(
*
item
);
n
.
addNeighbor
(
coord
.
c
+
pos
,
grid
.
get_state
(
coord
.
c
.
y
,
coord
.
c
.
x
));
}
return
n
;
}
std
::
vector
<
NeighborhoodFormat
>
ArbitraryNeighborhoodRule
::
getFormats
()
const
{
NeighborhoodFormat
format
;
for
(
const
auto
&
item
:
neighbors
.
contents
)
{
CoordinateProperty
coord
=
static_cast
<
CoordinateProperty
&>
(
*
item
);
format
.
positions
.
push_back
(
coord
.
c
);
}
return
{
format
};
}
src/propertyvisitors.cpp
View file @
97af64b7
...
...
@@ -113,11 +113,11 @@ void UIBuilderVisitor::visit(CoordinateProperty &prop)
frame
->
layout
()
->
addItem
(
new
QSpacerItem
(
40
,
20
,
QSizePolicy
::
Expanding
,
QSizePolicy
::
Minimum
));
add_widget
(
prop
.
name
(),
frame
);
spin_x
->
setValue
(
prop
.
x
);
spin_y
->
setValue
(
prop
.
y
);
spin_x
->
setValue
(
prop
.
c
.
x
);
spin_y
->
setValue
(
prop
.
c
.
y
);
QObject
::
connect
(
spin_x
,
QOverload
<
int
>::
of
(
&
QSpinBox
::
valueChanged
),
[
&
prop
](
int
i
)
{
prop
.
x
=
i
;
});
[
&
prop
](
int
i
)
{
prop
.
c
.
x
=
i
;
});
QObject
::
connect
(
spin_y
,
QOverload
<
int
>::
of
(
&
QSpinBox
::
valueChanged
),
[
&
prop
](
int
i
)
{
prop
.
y
=
i
;
});
[
&
prop
](
int
i
)
{
prop
.
c
.
y
=
i
;
});
}
void
UIBuilderVisitor
::
visit
(
PropertyList
&
list
)
...
...
@@ -259,7 +259,7 @@ void PropertySaverVisitor::visit(IntegerProperty &prop)
void
PropertySaverVisitor
::
visit
(
CoordinateProperty
&
prop
)
{
QJsonArray
arr
;
arr
.
append
(
prop
.
x
);
arr
.
append
(
prop
.
y
);
arr
.
append
(
prop
.
c
.
x
);
arr
.
append
(
prop
.
c
.
y
);
save_value
(
prop
,
QJsonValue
(
arr
));
}
...
...
@@ -351,7 +351,6 @@ void PropertyLoaderVisitor::visit(IntegerProperty &prop)
prop
.
val
=
val
.
toInt
();
if
(
prop
.
val
>
prop
.
prop_max
||
prop
.
val
<
prop
.
prop_min
)
{
// TODO
throw
propertyvisitorsException
(
"Invalid property value"
);
}
}
...
...
@@ -362,8 +361,8 @@ void PropertyLoaderVisitor::visit(CoordinateProperty &prop)
QJsonValue
val
=
fetch_value
(
prop
);
if
(
val
.
isArray
()
&&
val
.
toArray
().
size
()
==
2
)
{
prop
.
x
=
val
.
toArray
()[
0
].
toInt
();
prop
.
y
=
val
.
toArray
()[
1
].
toInt
();
prop
.
c
.
x
=
val
.
toArray
()[
0
].
toInt
();
prop
.
c
.
y
=
val
.
toArray
()[
1
].
toInt
();
}
}
...
...
@@ -375,7 +374,6 @@ void PropertyLoaderVisitor::visit(PropertyList &prop)
{
enter_value
(
val
);
// TODO
if
(
!
prop
.
dynamic
&&
val
.
toArray
().
size
()
!=
(
int
)
prop
.
contents
.
size
())
throw
propertyvisitorsException
(
"Invalid array size"
);
...
...
src/src.pro
View file @
97af64b7
...
...
@@ -12,6 +12,7 @@ TEMPLATE = app
INCLUDEPATH
+=
..
/
include
SOURCES
+=
\
arbitraryneighborhoodrule
.
cpp
\
gridview
.
cpp
\
main
.
cpp
\
propertyvisitors
.
cpp
\
...
...
@@ -24,6 +25,7 @@ SOURCES += \
HEADERS
+=
\
..
/
include
/
coord
.
hpp
\
..
/
include
/
neighborhoodrule
.
hpp
\
..
/
include
/
arbitraryneighborhoodrule
.
hpp
\
..
/
include
/
property
.
hpp
\
..
/
include
/
propertyvisitors
.
hpp
\
..
/
include
/
structure
.
hpp
\
...
...
src/structurereader.cpp
View file @
97af64b7
...
...
@@ -91,7 +91,6 @@ int StructureReader::read_int()
}
catch
(
std
::
exception
&
e
)
{
// TODO
throw
StructureReaderException
(
"La valeur lue n'est pas un entier !"
);
}
...
...
tests/arbitraryneighborhoodrule_test.cpp
0 → 100644
View file @
97af64b7
#include
"cellulut_tests.hpp"
#include
"arbitraryneighborhoodrule.hpp"
void
CellulutTests
::
test_arbitrary_neighborhood_rule
()
{
std
::
vector
<
Coord
>
coords
=
{
{
1
,
2
},
{
-
1
,
2
},
{
0
,
3
},
{
2
,
4
},
};
ArbitraryNeighborhoodRule
rule
;
for
(
auto
coord
:
coords
)
static_cast
<
CoordinateProperty
&>
(
rule
.
neighbors
.
push_back
())
=
CoordinateProperty
{
coord
};
QCOMPARE
(
rule
.
getFormats
().
size
(),
1
);
QCOMPARE
(
rule
.
getFormats
()[
0
].
positions
.
size
(),
coords
.
size
());
auto
list
=
rule
.
getFormats
()[
0
].
positions
;
QVERIFY
(
std
::
is_permutation
(
coords
.
begin
(),
coords
.
end
(),
rule
.
getFormats
()[
0
].
positions
.
begin
()));
}
tests/cellulut_tests.hpp
View file @
97af64b7
...
...
@@ -16,6 +16,8 @@ private slots:
void
test_rle_structurereader
();
void
test_json_structurereader
();
void
test_arbitrary_neighborhood_rule
();
void
test_history
();
void
test_grid
();
};
...
...
tests/propertyvisitors_test.cpp
View file @
97af64b7
...
...
@@ -23,11 +23,11 @@ void CellulutTests::test_loader_saver_visitor()
ex
.
champ_test
.
str
=
"champ_test"
;
ex
.
model_name
.
str
=
"model_name"
;
ex
.
test_int
.
val
=
5
;
ex
.
test_coord
.
x
=
1
;
ex
.
test_coord
.
y
=
2
;
ex
.
test_coord
.
c
.
x
=
1
;
ex
.
test_coord
.
c
.
y
=
2
;
CoordinateProperty
&
prop1
=
static_cast
<
CoordinateProperty
&>
(
ex
.
test_list
.
push_back
());
CoordinateProperty
&
prop2
=
static_cast
<
CoordinateProperty
&>
(
ex
.
test_list
.
push_back
());
prop1
.
x
=
-
1
;
prop1
.
y
=
3
;
prop2
.
x
=
0
;
prop2
.
y
=
-
3
;
prop1
.
c
.
x
=
-
1
;
prop1
.
c
.
y
=
3
;
prop2
.
c
.
x
=
0
;
prop2
.
c
.
y
=
-
3
;
// save
...
...
@@ -50,15 +50,14 @@ void CellulutTests::test_loader_saver_visitor()
QVERIFY
(
ex_loaded
.
champ_test
.
str
==
ex
.
champ_test
.
str
);
QVERIFY
(
ex_loaded
.
model_name
.
str
==
ex
.
model_name
.
str
);
QVERIFY
(
ex_loaded
.
test_int
.
val
==
ex
.
test_int
.
val
);
QVERIFY
(
ex_loaded
.
test_coord
.
x
==
ex
.
test_coord
.
x
&&
ex_loaded
.
test_coord
.
y
==
ex
.
test_coord
.
y
);
QVERIFY
(
ex_loaded
.
test_coord
.
c
==
ex
.
test_coord
.
c
);
QVERIFY
(
ex_loaded
.
test_list
.
size
()
==
ex
.
test_list
.
size
());
for
(
size_t
i
=
0
;
i
<
ex_loaded
.
test_list
.
size
();
++
i
)
{
CoordinateProperty
&
prop1
=
static_cast
<
CoordinateProperty
&>
(
ex_loaded
.
test_list
.
at
(
i
));
CoordinateProperty
&
prop2
=
static_cast
<
CoordinateProperty
&>
(
ex
.
test_list
.
at
(
i
));
QVERIFY
(
prop1
.
x
==
prop2
.
x
);
QVERIFY
(
prop1
.
y
==
prop2
.
y
);
QVERIFY
(
prop1
.
c
==
prop2
.
c
);
}
}
tests/tests.pro
View file @
97af64b7
...
...
@@ -16,6 +16,9 @@ INCLUDEPATH += ../include
SOURCES
+=
\
..
/
src
/
propertyvisitors
.
cpp
\
..
/
src
/
structurereader
.
cpp
\
..
/
src
/
neighborhood
.
cpp
\
..
/
src
/
arbitraryneighborhoodrule
.
cpp
\
arbitraryneighborhoodrule_test
.
cpp
\
coord_tests
.
cpp
\
factory_tests
.
cpp
\
grid_test
.
cpp
\
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment