Files
MapLibreParticleLab/include/mbgl/math/wrap.hpp
Bart Louwers 550f64be22 core: rename mbgl namespace to mln (#4487)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-08-14 23:25:20 +02:00

25 lines
518 B
C++

#pragma once
#include <cmath>
namespace mln {
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) {
if (value >= min && value < max) {
return value;
} else if (value == max) {
return min;
}
const T delta = max - min;
const T wrapped = min + std::fmod(value - min, delta);
return value < min ? wrapped + delta : wrapped;
}
} // namespace util
} // namespace mln