arbitraryneighborhoodrule.cpp 1.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
\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"
14
#include "grid.hpp"
15

16
17
REGISTER_FACTORY_ENTRY(NeighborhoodRule, ArbitraryNeighborhoodRule, "Arbitrary");

18
19
20
21
22
23
24
Neighborhood ArbitraryNeighborhoodRule::getNeighborhood(const Grid &grid, Coord pos) const
{
    Neighborhood n;

    for (const auto& item : neighbors.contents)
    {
        CoordinateProperty coord = static_cast<CoordinateProperty&>(*item);
25
        n.addNeighbor(coord.c + pos, grid.get_state(coord.c + pos));
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    }

    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};
}