File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ namespace gf {
21
21
GF_CORE_API Vec2F unit (Direction direction);
22
22
GF_CORE_API Vec2I displacement (Direction direction);
23
23
GF_CORE_API float angle (Direction direction);
24
+ GF_CORE_API Direction direction (float angle);
24
25
GF_CORE_API Direction opposite (Direction direction);
25
26
26
27
} // namespace gf
Original file line number Diff line number Diff line change @@ -58,6 +58,34 @@ namespace gf {
58
58
return static_cast <float >(direction) * Pi / 2 ;
59
59
}
60
60
61
+ Direction direction (float angle)
62
+ {
63
+ float normalized = std::fmod (angle, 2 * Pi);
64
+
65
+ if (angle < 0 ) {
66
+ assert (normalized < 0 );
67
+ normalized += 2 * Pi;
68
+ }
69
+
70
+ assert (0 .0f <= normalized && normalized < 2 * Pi);
71
+
72
+ static constexpr float Pi4 = Pi / 4 .0f ;
73
+
74
+ if (normalized < 1 * Pi4) {
75
+ return Direction::Right;
76
+ }
77
+ if (normalized < 3 * Pi4) {
78
+ return Direction::Down;
79
+ }
80
+ if (normalized < 5 * Pi4) {
81
+ return Direction::Right;
82
+ }
83
+ if (normalized < 7 * Pi4) {
84
+ return Direction::Up;
85
+ }
86
+ return Direction::Right;
87
+ }
88
+
61
89
Direction opposite (Direction direction)
62
90
{
63
91
if (direction == Direction::Center) {
You can’t perform that action at this time.
0 commit comments