master
ブランチ master
VulkanExample / dep / include / glm / gtx / common.inl
3.5 KB、121行 生 Blame 履歴
1/// @ref gtx_common
2
3#include <cmath>
4#include "../gtc/epsilon.hpp"
5#include "../gtc/constants.hpp"
6
7namespace glm{
8namespace detail
9{
10 template<length_t L, typename T, qualifier Q, bool isFloat = true>
11 struct compute_fmod
12 {
13 GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
14 {
15 return detail::functor2<vec, L, T, Q>::call(detail::TFmod<T>(), a, b);
16 }
17 };
18
19 template<length_t L, typename T, qualifier Q>
20 struct compute_fmod<L, T, Q, false>
21 {
22 GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& a, vec<L, T, Q> const& b)
23 {
24 return a % b;
25 }
26 };
27}//namespace detail
28
29 template<typename T>
30 GLM_FUNC_QUALIFIER bool isdenormal(T const& x)
31 {
32 static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'isdenormal' only accept floating-point inputs");
33
34 return std::fpclassify(x) == FP_SUBNORMAL;
35 }
36
37 template<typename T, qualifier Q>
38 GLM_FUNC_QUALIFIER typename vec<1, T, Q>::bool_type isdenormal
39 (
40 vec<1, T, Q> const& x
41 )
42 {
43 static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'isdenormal' only accept floating-point inputs");
44
45 return typename vec<1, T, Q>::bool_type(
46 isdenormal(x.x));
47 }
48
49 template<typename T, qualifier Q>
50 GLM_FUNC_QUALIFIER typename vec<2, T, Q>::bool_type isdenormal
51 (
52 vec<2, T, Q> const& x
53 )
54 {
55 static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'isdenormal' only accept floating-point inputs");
56
57 return typename vec<2, T, Q>::bool_type(
58 isdenormal(x.x),
59 isdenormal(x.y));
60 }
61
62 template<typename T, qualifier Q>
63 GLM_FUNC_QUALIFIER typename vec<3, T, Q>::bool_type isdenormal
64 (
65 vec<3, T, Q> const& x
66 )
67 {
68 static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'isdenormal' only accept floating-point inputs");
69
70 return typename vec<3, T, Q>::bool_type(
71 isdenormal(x.x),
72 isdenormal(x.y),
73 isdenormal(x.z));
74 }
75
76 template<typename T, qualifier Q>
77 GLM_FUNC_QUALIFIER typename vec<4, T, Q>::bool_type isdenormal
78 (
79 vec<4, T, Q> const& x
80 )
81 {
82 static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'isdenormal' only accept floating-point inputs");
83
84 return typename vec<4, T, Q>::bool_type(
85 isdenormal(x.x),
86 isdenormal(x.y),
87 isdenormal(x.z),
88 isdenormal(x.w));
89 }
90
91 // fmod
92 template<typename genType>
93 GLM_FUNC_QUALIFIER genType fmod(genType x, genType y)
94 {
95 return fmod(vec<1, genType>(x), y).x;
96 }
97
98 template<length_t L, typename T, qualifier Q>
99 GLM_FUNC_QUALIFIER vec<L, T, Q> fmod(vec<L, T, Q> const& x, T y)
100 {
101 return detail::compute_fmod<L, T, Q, std::numeric_limits<T>::is_iec559>::call(x, vec<L, T, Q>(y));
102 }
103
104 template<length_t L, typename T, qualifier Q>
105 GLM_FUNC_QUALIFIER vec<L, T, Q> fmod(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
106 {
107 return detail::compute_fmod<L, T, Q, std::numeric_limits<T>::is_iec559>::call(x, y);
108 }
109
110 template <length_t L, typename T, qualifier Q>
111 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)
112 {
113 return greaterThan(Value, Min) && lessThan(Value, Max);
114 }
115
116 template <length_t L, typename T, qualifier Q>
117 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)
118 {
119 return greaterThanEqual(Value, Min) && lessThanEqual(Value, Max);
120 }
121}//namespace glm