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.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/direction.h b/src/direction.h index 3dd95f9..595693f 100644 --- a/src/direction.h +++ b/src/direction.h
@@ -90,4 +90,21 @@ inline Direction directionFacingPoint(vec2i point) {
90 } 90 }
91} 91}
92 92
93inline Direction cardinalDirectionFacingPoint(vec2i point) {
94 double theta = atan2(point.y(), point.x());
95 theta /= M_PI;
96
97 if (theta < -3.0/4.0) {
98 return Direction::left;
99 } else if (theta < -1.0/4.0) {
100 return Direction::down;
101 } else if (theta < 1.0/4.0) {
102 return Direction::right;
103 } else if (theta < 3.0/4.0) {
104 return Direction::up;
105 } else {
106 return Direction::left;
107 }
108}
109
93#endif /* end of include guard: DIRECTION_H_AB66A90E */ 110#endif /* end of include guard: DIRECTION_H_AB66A90E */