summary refs log tree commit diff stats
path: root/src/direction.h
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2022-03-16 11:53:46 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2022-03-16 11:53:46 -0400
commit8713d03831226dcd559c6a1e2b1c7b0d7c660bac (patch)
treefd0c1e7ff253e3c69646d727bc49a112a71f5ca9 /src/direction.h
parent4b52f51404aca45a7d5d8e5998649ff67df97bbd (diff)
downloadether-8713d03831226dcd559c6a1e2b1c7b0d7c660bac.tar.gz
ether-8713d03831226dcd559c6a1e2b1c7b0d7c660bac.tar.bz2
ether-8713d03831226dcd559c6a1e2b1c7b0d7c660bac.zip
added signs (which can't be read yet)
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 */