diff options
author | crupest <crupest@outlook.com> | 2019-04-04 17:12:25 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-04-04 17:12:25 +0800 |
commit | a410e2048db6f5ef6fb50e401a59b4b98b979050 (patch) | |
tree | 500680c63b074e8c3eefd756fd6a1d0f41840c1a /src/util/math_util.hpp | |
parent | fcaf471275a67d718887430ee63a53890915c4c7 (diff) | |
download | cru-a410e2048db6f5ef6fb50e401a59b4b98b979050.tar.gz cru-a410e2048db6f5ef6fb50e401a59b4b98b979050.tar.bz2 cru-a410e2048db6f5ef6fb50e401a59b4b98b979050.zip |
...
Diffstat (limited to 'src/util/math_util.hpp')
-rw-r--r-- | src/util/math_util.hpp | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/src/util/math_util.hpp b/src/util/math_util.hpp deleted file mode 100644 index 01348641..00000000 --- a/src/util/math_util.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once -#include "pre.hpp" - -#include <optional> -#include <type_traits> - -namespace cru::util { -template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>> -float Coerce(const T n, const std::optional<T> min, - const std::optional<T> max) { - if (min.has_value() && n < min.value()) return min.value(); - if (max.has_value() && n > max.value()) return max.value(); - return n; -} - -template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>> -float Coerce(const T n, const T min, const T max) { - if (n < min) return min; - if (n > max) return max; - return n; -} - -template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>> -float Coerce(const T n, const std::nullopt_t, const std::optional<T> max) { - if (max.has_value() && n > max.value()) return max.value(); - return n; -} - -template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>> -float Coerce(const T n, const std::optional<T> min, const std::nullopt_t) { - if (min.has_value() && n < min.value()) return min.value(); - return n; -} - -template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>> -float Coerce(const T n, const std::nullopt_t, const T max) { - if (n > max) return max; - return n; -} - -template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>> -float Coerce(const T n, const T min, const std::nullopt_t) { - if (n < min) return min; - return n; -} - -template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>> -T AtLeast0(const T value) { - return value < static_cast<T>(0) ? static_cast<T>(0) : value; -} -} // namespace cru::util |