diff options
author | Petr Mrázek <peterix@gmail.com> | 2018-07-24 00:11:24 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2018-07-28 22:12:57 +0200 |
commit | 76d6ec91a4a9b330e8df413f76b3d8189e0eec2f (patch) | |
tree | 80ddc5d403f830ab68750b0042b5aa36d366eb8a /api/logic/ExponentialSeries.h | |
parent | 7b439c85c0bf3583ac8970e7ab9e8db3bd65c968 (diff) | |
download | MultiMC-76d6ec91a4a9b330e8df413f76b3d8189e0eec2f.tar MultiMC-76d6ec91a4a9b330e8df413f76b3d8189e0eec2f.tar.gz MultiMC-76d6ec91a4a9b330e8df413f76b3d8189e0eec2f.tar.lz MultiMC-76d6ec91a4a9b330e8df413f76b3d8189e0eec2f.tar.xz MultiMC-76d6ec91a4a9b330e8df413f76b3d8189e0eec2f.zip |
NOISSUE simplify.
Diffstat (limited to 'api/logic/ExponentialSeries.h')
-rw-r--r-- | api/logic/ExponentialSeries.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/api/logic/ExponentialSeries.h b/api/logic/ExponentialSeries.h new file mode 100644 index 00000000..a9487f0a --- /dev/null +++ b/api/logic/ExponentialSeries.h @@ -0,0 +1,43 @@ + +#pragma once + +template <typename T> +inline void clamp(T& current, T min, T max) +{ + if (current < min) + { + current = min; + } + else if(current > max) + { + current = max; + } +} + +// List of numbers from min to max. Next is exponent times bigger than previous. + +class ExponentialSeries +{ +public: + ExponentialSeries(unsigned min, unsigned max, unsigned exponent = 2) + { + m_current = m_min = min; + m_max = max; + m_exponent = exponent; + } + void reset() + { + m_current = m_min; + } + unsigned operator()() + { + unsigned retval = m_current; + m_current *= m_exponent; + clamp(m_current, m_min, m_max); + return retval; + } + unsigned m_current; + unsigned m_min; + unsigned m_max; + unsigned m_exponent; +}; |