core: rename mbgl directories to mln (#4511)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
49
include/mln/math/angles.hpp
Normal file
49
include/mln/math/angles.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <numbers>
|
||||
|
||||
namespace mln {
|
||||
namespace util {
|
||||
|
||||
/**
|
||||
* @brief Converts degrees to radians
|
||||
*
|
||||
* @param deg Degrees as double.
|
||||
* @return Radians as double.
|
||||
*/
|
||||
constexpr double deg2rad(double deg) noexcept {
|
||||
return deg * std::numbers::pi / 180.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts degrees to radians
|
||||
*
|
||||
* @param deg Degrees as float.
|
||||
* @return Radians as float.
|
||||
*/
|
||||
constexpr float deg2radf(float deg) noexcept {
|
||||
return deg * std::numbers::pi_v<float> / 180.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts radians to degrees
|
||||
*
|
||||
* @param rad Radians as double.
|
||||
* @return Degrees as double.
|
||||
*/
|
||||
constexpr double rad2deg(double rad) noexcept {
|
||||
return rad * 180.0 / std::numbers::pi;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converts radians to degrees
|
||||
*
|
||||
* @param rad Radians as float.
|
||||
* @return Degrees as float.
|
||||
*/
|
||||
constexpr float rad2degf(float rad) noexcept {
|
||||
return rad * 180.0F / std::numbers::pi_v<float>;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mln
|
||||
16
include/mln/math/clamp.hpp
Normal file
16
include/mln/math/clamp.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <mln/math/minmax.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace mln {
|
||||
namespace util {
|
||||
|
||||
template <typename T>
|
||||
auto clamp(std::enable_if_t<std::is_scalar_v<T>, T> value, T min_, T max_) noexcept {
|
||||
return max(min_, min(max_, value));
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mln
|
||||
40
include/mln/math/log2.hpp
Normal file
40
include/mln/math/log2.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include <android/api-level.h>
|
||||
#endif
|
||||
|
||||
namespace mln {
|
||||
namespace util {
|
||||
|
||||
/// Computes the log2(x) rounded up to the next integer.
|
||||
/// (== number of bits required to store x)
|
||||
uint32_t ceil_log2(uint64_t x);
|
||||
|
||||
template <typename T>
|
||||
T log2(T x) {
|
||||
// log2() is producing wrong results on ARMv5 binaries
|
||||
// running on ARMv7+ CPUs.
|
||||
#if defined(__ANDROID__)
|
||||
return ::log(x) / M_LN2;
|
||||
#else
|
||||
return ::log2(x);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mln
|
||||
|
||||
// log2 is not available on Android before API 18.
|
||||
#if defined(__ANDROID__) && defined(__GNUC__) && defined(__ANDROID_API__) && __ANDROID_API__ < 18
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if_t<std::is_floating_point_v<T>, T> log2(T x) {
|
||||
return ::log(x) / M_LN2;
|
||||
}
|
||||
|
||||
#endif
|
||||
53
include/mln/math/minmax.hpp
Normal file
53
include/mln/math/minmax.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace mln {
|
||||
namespace util {
|
||||
|
||||
template <typename T>
|
||||
T max(T a, T b)
|
||||
requires(std::is_integral_v<T>)
|
||||
{
|
||||
return std::max(a, b);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T max(T a, T b)
|
||||
requires(std::is_floating_point_v<T>)
|
||||
{
|
||||
return ::fmax(a, b);
|
||||
}
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
T max(T a, T b, Ts... args)
|
||||
requires(std::is_arithmetic_v<T>)
|
||||
{
|
||||
return max(a, max(b, args...));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T min(T a, T b)
|
||||
requires(std::is_integral_v<T>)
|
||||
{
|
||||
return std::min(a, b);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T min(T a, T b)
|
||||
requires(std::is_floating_point_v<T>)
|
||||
{
|
||||
return ::fmin(a, b);
|
||||
}
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
T min(T a, T b, Ts... args)
|
||||
requires(std::is_arithmetic_v<T>)
|
||||
{
|
||||
return min(a, min(b, args...));
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mln
|
||||
24
include/mln/math/wrap.hpp
Normal file
24
include/mln/math/wrap.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user