plumageRender/3rdparty/glm/gtx/common.inl

126 lines
3.5 KiB
Plaintext
Raw Normal View History

2023-05-17 14:49:05 +08:00
/// @ref gtx_common
#include <cmath>
2023-06-07 10:52:04 +08:00
#include "../gtc/epsilon.hpp"
#include "../gtc/constants.hpp"
2023-05-17 14:49:05 +08:00
namespace glm{
namespace detail
{
2023-06-07 10:52:04 +08:00
template<length_t L, typename T, qualifier Q, bool isFloat = true>
2023-05-17 14:49:05 +08:00
struct compute_fmod
{
2023-06-07 10:52:04 +08:00
GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
2023-05-17 14:49:05 +08:00
{
2025-02-15 20:55:58 +08:00
return detail::functor2<vec, L, T, Q>::call(std::fmod, a, b);
2023-05-17 14:49:05 +08:00
}
};
2023-06-07 10:52:04 +08:00
template<length_t L, typename T, qualifier Q>
struct compute_fmod<L, T, Q, false>
2023-05-17 14:49:05 +08:00
{
2023-06-07 10:52:04 +08:00
GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
2023-05-17 14:49:05 +08:00
{
return a % b;
}
};
}//namespace detail
2025-02-15 20:55:58 +08:00
template<typename T>
2023-06-07 10:52:04 +08:00
GLM_FUNC_QUALIFIER bool isdenormal(T const& x)
2023-05-17 14:49:05 +08:00
{
2025-02-15 20:55:58 +08:00
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'isdenormal' only accept floating-point inputs");
2023-05-17 14:49:05 +08:00
# if GLM_HAS_CXX11_STL
return std::fpclassify(x) == FP_SUBNORMAL;
# else
2023-06-07 10:52:04 +08:00
return epsilonNotEqual(x, static_cast<T>(0), epsilon<T>()) && std::fabs(x) < std::numeric_limits<T>::min();
2023-05-17 14:49:05 +08:00
# endif
}
2023-06-07 10:52:04 +08:00
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename vec<1, T, Q>::bool_type isdenormal
2023-05-17 14:49:05 +08:00
(
2023-06-07 10:52:04 +08:00
vec<1, T, Q> const& x
2023-05-17 14:49:05 +08:00
)
{
2025-02-15 20:55:58 +08:00
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'isdenormal' only accept floating-point inputs");
2023-05-17 14:49:05 +08:00
2023-06-07 10:52:04 +08:00
return typename vec<1, T, Q>::bool_type(
2023-05-17 14:49:05 +08:00
isdenormal(x.x));
}
2023-06-07 10:52:04 +08:00
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename vec<2, T, Q>::bool_type isdenormal
2023-05-17 14:49:05 +08:00
(
2023-06-07 10:52:04 +08:00
vec<2, T, Q> const& x
2023-05-17 14:49:05 +08:00
)
{
2025-02-15 20:55:58 +08:00
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'isdenormal' only accept floating-point inputs");
2023-05-17 14:49:05 +08:00
2023-06-07 10:52:04 +08:00
return typename vec<2, T, Q>::bool_type(
2023-05-17 14:49:05 +08:00
isdenormal(x.x),
isdenormal(x.y));
}
2023-06-07 10:52:04 +08:00
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename vec<3, T, Q>::bool_type isdenormal
2023-05-17 14:49:05 +08:00
(
2023-06-07 10:52:04 +08:00
vec<3, T, Q> const& x
2023-05-17 14:49:05 +08:00
)
{
2025-02-15 20:55:58 +08:00
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'isdenormal' only accept floating-point inputs");
2023-05-17 14:49:05 +08:00
2023-06-07 10:52:04 +08:00
return typename vec<3, T, Q>::bool_type(
2023-05-17 14:49:05 +08:00
isdenormal(x.x),
isdenormal(x.y),
isdenormal(x.z));
}
2023-06-07 10:52:04 +08:00
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER typename vec<4, T, Q>::bool_type isdenormal
2023-05-17 14:49:05 +08:00
(
2023-06-07 10:52:04 +08:00
vec<4, T, Q> const& x
2023-05-17 14:49:05 +08:00
)
{
2025-02-15 20:55:58 +08:00
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'isdenormal' only accept floating-point inputs");
2023-05-17 14:49:05 +08:00
2023-06-07 10:52:04 +08:00
return typename vec<4, T, Q>::bool_type(
2023-05-17 14:49:05 +08:00
isdenormal(x.x),
isdenormal(x.y),
isdenormal(x.z),
isdenormal(x.w));
}
// fmod
template<typename genType>
GLM_FUNC_QUALIFIER genType fmod(genType x, genType y)
{
return fmod(vec<1, genType>(x), y).x;
}
2023-06-07 10:52:04 +08:00
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fmod(vec<L, T, Q> const& x, T y)
2023-05-17 14:49:05 +08:00
{
2023-06-07 10:52:04 +08:00
return detail::compute_fmod<L, T, Q, std::numeric_limits<T>::is_iec559>::call(x, vec<L, T, Q>(y));
2023-05-17 14:49:05 +08:00
}
2023-06-07 10:52:04 +08:00
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> fmod(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
2023-05-17 14:49:05 +08:00
{
2023-06-07 10:52:04 +08:00
return detail::compute_fmod<L, T, Q, std::numeric_limits<T>::is_iec559>::call(x, y);
2023-05-17 14:49:05 +08:00
}
2025-02-15 20:55:58 +08:00
template <length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, bool, Q> openBounded(vec<L, T, Q> const& Value, vec<L, T, Q> const& Min, vec<L, T, Q> const& Max)
{
return greaterThan(Value, Min) && lessThan(Value, Max);
}
template <length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, bool, Q> closeBounded(vec<L, T, Q> const& Value, vec<L, T, Q> const& Min, vec<L, T, Q> const& Max)
{
return greaterThanEqual(Value, Min) && lessThanEqual(Value, Max);
}
2023-05-17 14:49:05 +08:00
}//namespace glm