added several grid-walks
added new helper methods/classes (e.g. for heading) new test cases optimize the dijkstra cleanups/refactoring added timed-benchmarks to the log many more...
This commit is contained in:
19
grid/Grid.h
19
grid/Grid.h
@@ -15,7 +15,12 @@
|
||||
|
||||
/**
|
||||
* grid of the given grid-size, storing some value which
|
||||
* extends GridPoint
|
||||
* extends GridPoint and GridNode
|
||||
*
|
||||
* Usage:
|
||||
* for (Node& n : grid) {...}
|
||||
* for (Node& n2 : grid.neighbors(n)) {...}
|
||||
*
|
||||
*/
|
||||
template <int gridSize_cm, typename T> class Grid {
|
||||
|
||||
@@ -47,6 +52,12 @@ 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();}
|
||||
|
||||
|
||||
/**
|
||||
* add the given element to the grid.
|
||||
@@ -235,14 +246,14 @@ public:
|
||||
Log::add(name, "running grid cleanup");
|
||||
|
||||
// check every single node
|
||||
for (int i = (int)nodes.size() - 1; i >= 0; --i) {
|
||||
for (size_t i = 0; i < nodes.size(); ++i) {
|
||||
|
||||
// is this node marked as "deleted"? (idx == -1)
|
||||
if (nodes[i]._idx == -1) {
|
||||
|
||||
// remove this node
|
||||
deleteNode(i);
|
||||
++i;
|
||||
--i;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -261,6 +272,8 @@ private:
|
||||
/** hard-delete the given node */
|
||||
void deleteNode(const int idx) {
|
||||
|
||||
_assertBetween(idx, 0, nodes.size()-1, "index out of bounds");
|
||||
|
||||
// COMPLEX AND SLOW AS HELL.. BUT UGLY TO REWIRTE TO BE CORRECT
|
||||
|
||||
// remove him from the node list (reclaim its memory and its index)
|
||||
|
||||
Reference in New Issue
Block a user