summaryrefslogtreecommitdiff
path: root/include/mbgl/math/wrap.hpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-05-04 17:32:30 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-05-05 11:16:57 -0700
commitce2a06e6773dfb656c7bf6fdbb7e8bc463710685 (patch)
treed3939aca3d9378a87832f305f68e82bc1fa6fd89 /include/mbgl/math/wrap.hpp
parenta81891771441dfc1c839b9d100368b6bbf1fc127 (diff)
downloadqtlocation-mapboxgl-ce2a06e6773dfb656c7bf6fdbb7e8bc463710685.tar.gz
[core] Privatize math.hpp and vec.hpp
Diffstat (limited to 'include/mbgl/math/wrap.hpp')
-rw-r--r--include/mbgl/math/wrap.hpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/mbgl/math/wrap.hpp b/include/mbgl/math/wrap.hpp
new file mode 100644
index 0000000000..16dc598c22
--- /dev/null
+++ b/include/mbgl/math/wrap.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <cmath>
+
+namespace mbgl {
+namespace util {
+
+// 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 std::fmod((std::fmod((value - min), d) + d), d) + min;
+}
+
+} // namespace util
+} // namespace mbgl