| 1 | // LAF Base Library |
| 2 | // Copyright (c) 2019 Igara Studio S.A. |
| 3 | // Copyright (c) 2015-2016 David Capello |
| 4 | // |
| 5 | // This file is released under the terms of the MIT license. |
| 6 | // Read LICENSE.txt for more information. |
| 7 | |
| 8 | #ifndef BASE_PI_H_INCLUDED |
| 9 | #define BASE_PI_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #ifndef PI |
| 13 | #define PI 3.14159265358979323846 |
| 14 | #endif |
| 15 | |
| 16 | #include <cmath> |
| 17 | |
| 18 | namespace base { |
| 19 | |
| 20 | // Puts the angle in the -PI to PI range. |
| 21 | inline double fmod_radians(double angle) { |
| 22 | if (angle < -PI) { |
| 23 | if (angle < -2.0*PI) |
| 24 | angle = -std::fmod(-angle, 2.0*PI); |
| 25 | angle += 2.0*PI; |
| 26 | } |
| 27 | if (angle > 2.0*PI) |
| 28 | angle = std::fmod(angle, 2.0*PI); |
| 29 | if (angle > PI) |
| 30 | angle -= 2.0*PI; |
| 31 | return angle; |
| 32 | } |
| 33 | |
| 34 | } |
| 35 | |
| 36 | #endif |
| 37 | |