Skip to content

Commit

Permalink
Added map
Browse files Browse the repository at this point in the history
  • Loading branch information
gregjesl committed Jan 30, 2023
1 parent 263f2ff commit a1a00df
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions glnav.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "inc/glnav_heading.h"
#include "inc/glnav_traveler.h"
#include "inc/glnav_dispatch.h"
#include "inc/glnav_map.h"
#include "inc/glnav_dijkstra.h"
// #include "inc/glnav_astar.h"

Expand Down
48 changes: 48 additions & 0 deletions inc/glnav_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef GLNAV_MAP_H
#define GLNAV_MAP_H

#include "con3/con3.h"
#include "glnav_network.h"
#include "glnav_path.h"
#include "glnav_obstacle.h"

namespace glnav
{
template<typename T>
class map : public con3::set<obstacle<T> *>
{
public:
map()
: con3::set<obstacle<T> *>()
{ }

bool obstructs(const path<T> &input)
{
for(size_t i = 0; i < this->values().size(); i++)
{
if(this->at(i)->obstructs(input)) return true;
}
return false;
}

std::set<point<T> > corners()
{
std::set<point<T> > result;

// Iterate through the obstacles
for(size_t i = 0; i < this->values().size(); i++)
{
const point_group<T> corners = this->at(i)->corners();

// Iterate through the corners
for(size_t j = 0; j < corners.size(); j++)
{
result.insert(corners.at(j));
}
}
return result;
}
};
}

#endif
25 changes: 25 additions & 0 deletions test/map.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "glnav.h"
#include "test.h"

int main(void)
{
glnav::map<int> test;
glnav::obstacle<int> test_obs = glnav::obstacle<int>::square(
glnav::point<int>(1, 1),
4
);
test.force_add(&test_obs);
TEST_EQUAL(test.values().size(), 1);

glnav::path<int> test_path(1, -10, 1, 10);
TEST_TRUE(test.obstructs(test_path));
test_path = glnav::path<int>(5, -10, 5, 10);
TEST_FALSE(test.obstructs(test_path));

std::set<glnav::point<int> > corners = test.corners();
TEST_EQUAL(corners.size(), 4);
TEST_TRUE(corners.find(glnav::point<int>(-1, -1)) != corners.end());
TEST_TRUE(corners.find(glnav::point<int>(-1, 3)) != corners.end());
TEST_TRUE(corners.find(glnav::point<int>(3, -1)) != corners.end());
TEST_TRUE(corners.find(glnav::point<int>(3, 3)) != corners.end());
}

0 comments on commit a1a00df

Please sign in to comment.