summary refs log tree commit diff stats
path: root/src/direction.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/direction.h')
-rw-r--r--src/direction.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/direction.h b/src/direction.h index 0fe3e5a..14ea0a5 100644 --- a/src/direction.h +++ b/src/direction.h
@@ -3,6 +3,9 @@
3 3
4#include <string_view> 4#include <string_view>
5#include <stdexcept> 5#include <stdexcept>
6#include <tuple>
7
8using coord = std::tuple<int, int>;
6 9
7enum class Direction { 10enum class Direction {
8 up, 11 up,
@@ -19,4 +22,13 @@ inline Direction directionFromString(std::string_view str) {
19 throw std::invalid_argument("Invalid direction: " + std::string(str)); 22 throw std::invalid_argument("Invalid direction: " + std::string(str));
20} 23}
21 24
25inline coord coordInDirection(int x, int y, Direction dir) {
26 switch (dir) {
27 case Direction::up: return {x, y-1};
28 case Direction::down: return {x, y+1};
29 case Direction::left: return {x-1, y};
30 case Direction::right: return {x+1, y};
31 }
32}
33
22#endif /* end of include guard: DIRECTION_H_42BDAFB9 */ 34#endif /* end of include guard: DIRECTION_H_42BDAFB9 */