diff options
Diffstat (limited to 'platform/location.hpp')
-rw-r--r-- | platform/location.hpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/platform/location.hpp b/platform/location.hpp index 978bf8aeab..576c95a3ee 100644 --- a/platform/location.hpp +++ b/platform/location.hpp @@ -5,6 +5,7 @@ #include "../routing/turns.hpp" #include "../std/string.hpp" +#include "../std/cmath.hpp" namespace location @@ -73,6 +74,22 @@ namespace location return lon != 0. && lon < 180. && lon > -180.; } + + // Convert angle (in degrees counterclockwise from X) to bearing ([0, 360) clockwise from the north) + static inline double AngleToBearing(double a) + { + double reverseAng = fmod(-a + 90, 360.); + if (reverseAng < 0) + reverseAng += 360.; + return reverseAng; + } + + // Convert bearing (in degrees clockwise from the north) to angle ([0, 360) counterclockwise from X) + static inline double BearingToAngle(double a) + { + return AngleToBearing(a); + } + class FollowingInfo { public: |