master
ブランチ master
VulkanExample / dep / include / glm / ext / scalar_common.inl
4 KB、145行 生 Blame 履歴
1namespace glm
2{
3 template<typename T>
4 GLM_FUNC_QUALIFIER T (min)(T a, T b, T c)
5 {
6 return (glm::min)((glm::min)(a, b), c);
7 }
8
9 template<typename T>
10 GLM_FUNC_QUALIFIER T (min)(T a, T b, T c, T d)
11 {
12 return (glm::min)((glm::min)(a, b), (glm::min)(c, d));
13 }
14
15 template<typename T>
16 GLM_FUNC_QUALIFIER T (max)(T a, T b, T c)
17 {
18 return (glm::max)((glm::max)(a, b), c);
19 }
20
21 template<typename T>
22 GLM_FUNC_QUALIFIER T (max)(T a, T b, T c, T d)
23 {
24 return (glm::max)((glm::max)(a, b), (glm::max)(c, d));
25 }
26
27 using std::fmin;
28
29 template<typename T>
30 GLM_FUNC_QUALIFIER T (fmin)(T a, T b, T c)
31 {
32 static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'fmin' only accept floating-point input");
33
34 if (isnan(a))
35 return (fmin)(b, c);
36 if (isnan(b))
37 return (fmin)(a, c);
38 if (isnan(c))
39 return min(a, b);
40 return (min)(a, b, c);
41 }
42
43 template<typename T>
44 GLM_FUNC_QUALIFIER T (fmin)(T a, T b, T c, T d)
45 {
46 static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'fmin' only accept floating-point input");
47
48 if (isnan(a))
49 return (fmin)(b, c, d);
50 if (isnan(b))
51 return (min)(a, (fmin)(c, d));
52 if (isnan(c))
53 return (fmin)(min(a, b), d);
54 if (isnan(d))
55 return (min)(a, b, c);
56 return (min)(a, b, c, d);
57 }
58
59 using std::fmax;
60
61 template<typename T>
62 GLM_FUNC_QUALIFIER T (fmax)(T a, T b, T c)
63 {
64 static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'fmax' only accept floating-point input");
65
66 if (isnan(a))
67 return (fmax)(b, c);
68 if (isnan(b))
69 return (fmax)(a, c);
70 if (isnan(c))
71 return (max)(a, b);
72 return (max)(a, b, c);
73 }
74
75 template<typename T>
76 GLM_FUNC_QUALIFIER T (fmax)(T a, T b, T c, T d)
77 {
78 static_assert(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'fmax' only accept floating-point input");
79
80 if (isnan(a))
81 return (fmax)(b, c, d);
82 if (isnan(b))
83 return (max)(a, (fmax)(c, d));
84 if (isnan(c))
85 return (fmax)((max)(a, b), d);
86 if (isnan(d))
87 return (max)(a, b, c);
88 return (max)(a, b, c, d);
89 }
90
91 // fclamp
92 template<typename genType>
93 GLM_FUNC_QUALIFIER genType fclamp(genType x, genType minVal, genType maxVal)
94 {
95 static_assert(std::numeric_limits<genType>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'fclamp' only accept floating-point or integer inputs");
96 return fmin((fmax)(x, minVal), maxVal);
97 }
98
99 template<typename genType>
100 GLM_FUNC_QUALIFIER genType clamp(genType const& Texcoord)
101 {
102 return glm::clamp(Texcoord, static_cast<genType>(0), static_cast<genType>(1));
103 }
104
105 template<typename genType>
106 GLM_FUNC_QUALIFIER genType repeat(genType const& Texcoord)
107 {
108 return glm::fract(Texcoord);
109 }
110
111 template<typename genType>
112 GLM_FUNC_QUALIFIER genType mirrorClamp(genType const& Texcoord)
113 {
114 return glm::fract(glm::abs(Texcoord));
115 }
116
117 template<typename genType>
118 GLM_FUNC_QUALIFIER genType mirrorRepeat(genType const& Texcoord)
119 {
120 genType const Abs = glm::abs(Texcoord);
121 genType const Clamp = glm::mod(glm::floor(Abs), static_cast<genType>(2));
122 genType const Floor = glm::floor(Abs);
123 genType const Rest = Abs - Floor;
124 genType const Mirror = Clamp + Rest;
125 return mix(Rest, static_cast<genType>(1) - Rest, Mirror >= static_cast<genType>(1));
126 }
127
128 template<typename genType>
129 GLM_FUNC_QUALIFIER int iround(genType const& x)
130 {
131 static_assert(std::numeric_limits<genType>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'iround' only accept floating-point inputs");
132 assert(static_cast<genType>(0.0) <= x);
133
134 return static_cast<int>(x + static_cast<genType>(0.5));
135 }
136
137 template<typename genType>
138 GLM_FUNC_QUALIFIER uint uround(genType const& x)
139 {
140 static_assert(std::numeric_limits<genType>::is_iec559 || GLM_CONFIG_UNRESTRICTED_FLOAT, "'uround' only accept floating-point inputs");
141 assert(static_cast<genType>(0.0) <= x);
142
143 return static_cast<uint>(x + static_cast<genType>(0.5));
144 }
145}//namespace glm