1 | #pragma once |
---|---|
2 | |
3 | #include <cmath> |
4 | |
5 | namespace mbgl { |
6 | namespace util { |
7 | |
8 | // Constrains n to the given range (including min, excluding max) via modular |
9 | // arithmetic. |
10 | template <typename T> |
11 | T wrap(T value, T min, T max) { |
12 | T d = max - min; |
13 | return std::fmod((std::fmod((value - min), d) + d), d) + min; |
14 | } |
15 | |
16 | } // namespace util |
17 | } // namespace mbgl |
18 |