diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2015-07-02 13:03:32 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2015-07-06 13:07:34 -0700 |
commit | 46a6173bd744c7d2a65fc6533e0d6a37a93e7e5b (patch) | |
tree | bd83693a3a3e82180b84512c5a9776bd50f1ada9 /include | |
parent | 78126f3b6b303febe4a0de2a08509816e75bbf21 (diff) | |
download | qtlocation-mapboxgl-46a6173bd744c7d2a65fc6533e0d6a37a93e7e5b.tar.gz |
[wrap)
If (wrap] is desired, it is the responsibility of the caller to handle the case in which min is returned.
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/util/math.hpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/include/mbgl/util/math.hpp b/include/mbgl/util/math.hpp index 5fcf3dce80..37b1dd3431 100644 --- a/include/mbgl/util/math.hpp +++ b/include/mbgl/util/math.hpp @@ -112,10 +112,12 @@ T clamp(T value, T min, T max) { return value < min ? min : (value > max ? max : value); } +// Constrains n to the given range (including min, excluding max) via modular +// arithmetic. template <typename T> T wrap(T value, T min, T max) { T d = max - min; - return value == max ? value : std::fmod((std::fmod((value - min), d) + d), d) + min; + return std::fmod((std::fmod((value - min), d) + d), d) + min; } template <typename T> |