removed gridSize from the template arguments
- not needed and code much cleaner some minor changes new test-cases
This commit is contained in:
17
grid/Grid.h
17
grid/Grid.h
@@ -14,20 +14,21 @@
|
||||
#include "../misc/Debug.h"
|
||||
|
||||
/**
|
||||
* grid of the given grid-size, storing some value which
|
||||
* extends GridPoint and GridNode
|
||||
* grid of a given-size, storing some user-data-value which
|
||||
* - extends GridPoint and GridNode
|
||||
*
|
||||
* Usage:
|
||||
* for (Node& n : grid) {...}
|
||||
* for (Node& n2 : grid.neighbors(n)) {...}
|
||||
*
|
||||
*/
|
||||
template <int gridSize_cm, typename T> class Grid {
|
||||
template <typename T> class Grid {
|
||||
|
||||
static constexpr const char* name = "Grid";
|
||||
|
||||
#include "GridNeighborIterator.h"
|
||||
|
||||
/** UID for nodes */
|
||||
typedef uint64_t UID;
|
||||
|
||||
private:
|
||||
@@ -38,10 +39,13 @@ private:
|
||||
/** UID -> index mapping */
|
||||
std::unordered_map<UID, int> hashes;
|
||||
|
||||
/** the user-given grid-size */
|
||||
const int gridSize_cm;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
Grid() {
|
||||
/** ctor with the grid's size (in cm) */
|
||||
Grid(const int gridSize_cm) : gridSize_cm(gridSize_cm) {
|
||||
static_assert((sizeof(T::_idx) > 0), "T must inherit from GridNode!");
|
||||
static_assert((sizeof(T::x_cm) > 0), "T must inherit from GridPoint!");
|
||||
}
|
||||
@@ -52,12 +56,15 @@ public:
|
||||
/** no-assign */
|
||||
void operator = (const Grid& o) = delete;
|
||||
|
||||
|
||||
/** allows for-each iteration over all included nodes */
|
||||
decltype(nodes.begin()) begin() {return nodes.begin();}
|
||||
|
||||
/** allows for-each iteration over all included nodes */
|
||||
decltype(nodes.end()) end() {return nodes.end();}
|
||||
|
||||
/** get the grid's size */
|
||||
int getGridSize_cm() const {return gridSize_cm;}
|
||||
|
||||
/**
|
||||
* add the given element to the grid.
|
||||
|
||||
Reference in New Issue
Block a user