-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate collision checker and parameters to library (#38)
* Migrate collision checker and parameters to library
- Loading branch information
1 parent
a3f0af1
commit ddccce1
Showing
7 changed files
with
143 additions
and
42 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
functional_programming_tests/include/pathing/collision_checking.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "pathing/pathing.hpp" | ||
|
||
template <typename T> | ||
struct CollisionChecker { | ||
/** | ||
* @brief Checks if the robot is colliding with an obstacle or out of bounds | ||
* @param robot_size The size of the robot in pixels | ||
*/ | ||
CollisionChecker(int robot_size) : robot_size_{robot_size} {} | ||
|
||
/** | ||
* @brief Checks if the robot is colliding with an obstacle or out of bounds | ||
* @param map The map to check for collision | ||
* @param x position of the center of robot | ||
* @param y position of the center of robot | ||
* TODO: This check doesn't make any physical sense. The robot should be | ||
* checked radially from the center of the robot. This is a square | ||
* starting from the corner of the robot as the origin. | ||
* @return True if the robot is colliding with an obstacle or out of bounds | ||
*/ | ||
bool operator()(Map<T> const& map, auto const x, auto const y) const { | ||
// Get the dimensions of the map for bounds checking | ||
auto const [dim_x, dim_y] = map.dim(); | ||
|
||
// Check if the robot is out of bounds or colliding with an obstacle | ||
for (int dx = 0; dx < robot_size_; ++dx) { | ||
for (int dy = 0; dy < robot_size_; ++dy) { | ||
// Get the position of the robot to check for collision | ||
int const px = x + dx; | ||
int const py = y + dy; | ||
|
||
// Check if the robot is out of bounds | ||
if (px < 0 || px >= dim_x || py < 0 || py >= dim_y) { | ||
return true; | ||
} | ||
// Check if the robot is colliding with an obstacle | ||
if (map.at(Position{x + dx, y + dy}) == 255) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private: | ||
int robot_size_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.