associated_min_max.inl 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /// @ref gtx_associated_min_max
  2. namespace glm{
  3. // Min comparison between 2 variables
  4. template<typename T, typename U, qualifier Q>
  5. GLM_FUNC_QUALIFIER U associatedMin(T x, U a, T y, U b)
  6. {
  7. return x < y ? a : b;
  8. }
  9. template<length_t L, typename T, typename U, qualifier Q>
  10. GLM_FUNC_QUALIFIER vec<2, U, Q> associatedMin
  11. (
  12. vec<L, T, Q> const& x, vec<L, U, Q> const& a,
  13. vec<L, T, Q> const& y, vec<L, U, Q> const& b
  14. )
  15. {
  16. vec<L, U, Q> Result;
  17. for(length_t i = 0, n = Result.length(); i < n; ++i)
  18. Result[i] = x[i] < y[i] ? a[i] : b[i];
  19. return Result;
  20. }
  21. template<length_t L, typename T, typename U, qualifier Q>
  22. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMin
  23. (
  24. T x, const vec<L, U, Q>& a,
  25. T y, const vec<L, U, Q>& b
  26. )
  27. {
  28. vec<L, U, Q> Result;
  29. for(length_t i = 0, n = Result.length(); i < n; ++i)
  30. Result[i] = x < y ? a[i] : b[i];
  31. return Result;
  32. }
  33. template<length_t L, typename T, typename U, qualifier Q>
  34. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMin
  35. (
  36. vec<L, T, Q> const& x, U a,
  37. vec<L, T, Q> const& y, U b
  38. )
  39. {
  40. vec<L, U, Q> Result;
  41. for(length_t i = 0, n = Result.length(); i < n; ++i)
  42. Result[i] = x[i] < y[i] ? a : b;
  43. return Result;
  44. }
  45. // Min comparison between 3 variables
  46. template<typename T, typename U>
  47. GLM_FUNC_QUALIFIER U associatedMin
  48. (
  49. T x, U a,
  50. T y, U b,
  51. T z, U c
  52. )
  53. {
  54. U Result = x < y ? (x < z ? a : c) : (y < z ? b : c);
  55. return Result;
  56. }
  57. template<length_t L, typename T, typename U, qualifier Q>
  58. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMin
  59. (
  60. vec<L, T, Q> const& x, vec<L, U, Q> const& a,
  61. vec<L, T, Q> const& y, vec<L, U, Q> const& b,
  62. vec<L, T, Q> const& z, vec<L, U, Q> const& c
  63. )
  64. {
  65. vec<L, U, Q> Result;
  66. for(length_t i = 0, n = Result.length(); i < n; ++i)
  67. Result[i] = x[i] < y[i] ? (x[i] < z[i] ? a[i] : c[i]) : (y[i] < z[i] ? b[i] : c[i]);
  68. return Result;
  69. }
  70. // Min comparison between 4 variables
  71. template<typename T, typename U>
  72. GLM_FUNC_QUALIFIER U associatedMin
  73. (
  74. T x, U a,
  75. T y, U b,
  76. T z, U c,
  77. T w, U d
  78. )
  79. {
  80. T Test1 = min(x, y);
  81. T Test2 = min(z, w);;
  82. U Result1 = x < y ? a : b;
  83. U Result2 = z < w ? c : d;
  84. U Result = Test1 < Test2 ? Result1 : Result2;
  85. return Result;
  86. }
  87. // Min comparison between 4 variables
  88. template<length_t L, typename T, typename U, qualifier Q>
  89. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMin
  90. (
  91. vec<L, T, Q> const& x, vec<L, U, Q> const& a,
  92. vec<L, T, Q> const& y, vec<L, U, Q> const& b,
  93. vec<L, T, Q> const& z, vec<L, U, Q> const& c,
  94. vec<L, T, Q> const& w, vec<L, U, Q> const& d
  95. )
  96. {
  97. vec<L, U, Q> Result;
  98. for(length_t i = 0, n = Result.length(); i < n; ++i)
  99. {
  100. T Test1 = min(x[i], y[i]);
  101. T Test2 = min(z[i], w[i]);
  102. U Result1 = x[i] < y[i] ? a[i] : b[i];
  103. U Result2 = z[i] < w[i] ? c[i] : d[i];
  104. Result[i] = Test1 < Test2 ? Result1 : Result2;
  105. }
  106. return Result;
  107. }
  108. // Min comparison between 4 variables
  109. template<length_t L, typename T, typename U, qualifier Q>
  110. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMin
  111. (
  112. T x, vec<L, U, Q> const& a,
  113. T y, vec<L, U, Q> const& b,
  114. T z, vec<L, U, Q> const& c,
  115. T w, vec<L, U, Q> const& d
  116. )
  117. {
  118. T Test1 = min(x, y);
  119. T Test2 = min(z, w);
  120. vec<L, U, Q> Result;
  121. for(length_t i = 0, n = Result.length(); i < n; ++i)
  122. {
  123. U Result1 = x < y ? a[i] : b[i];
  124. U Result2 = z < w ? c[i] : d[i];
  125. Result[i] = Test1 < Test2 ? Result1 : Result2;
  126. }
  127. return Result;
  128. }
  129. // Min comparison between 4 variables
  130. template<length_t L, typename T, typename U, qualifier Q>
  131. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMin
  132. (
  133. vec<L, T, Q> const& x, U a,
  134. vec<L, T, Q> const& y, U b,
  135. vec<L, T, Q> const& z, U c,
  136. vec<L, T, Q> const& w, U d
  137. )
  138. {
  139. vec<L, U, Q> Result;
  140. for(length_t i = 0, n = Result.length(); i < n; ++i)
  141. {
  142. T Test1 = min(x[i], y[i]);
  143. T Test2 = min(z[i], w[i]);;
  144. U Result1 = x[i] < y[i] ? a : b;
  145. U Result2 = z[i] < w[i] ? c : d;
  146. Result[i] = Test1 < Test2 ? Result1 : Result2;
  147. }
  148. return Result;
  149. }
  150. // Max comparison between 2 variables
  151. template<typename T, typename U>
  152. GLM_FUNC_QUALIFIER U associatedMax(T x, U a, T y, U b)
  153. {
  154. return x > y ? a : b;
  155. }
  156. // Max comparison between 2 variables
  157. template<length_t L, typename T, typename U, qualifier Q>
  158. GLM_FUNC_QUALIFIER vec<2, U, Q> associatedMax
  159. (
  160. vec<L, T, Q> const& x, vec<L, U, Q> const& a,
  161. vec<L, T, Q> const& y, vec<L, U, Q> const& b
  162. )
  163. {
  164. vec<L, U, Q> Result;
  165. for(length_t i = 0, n = Result.length(); i < n; ++i)
  166. Result[i] = x[i] > y[i] ? a[i] : b[i];
  167. return Result;
  168. }
  169. // Max comparison between 2 variables
  170. template<length_t L, typename T, typename U, qualifier Q>
  171. GLM_FUNC_QUALIFIER vec<L, T, Q> associatedMax
  172. (
  173. T x, vec<L, U, Q> const& a,
  174. T y, vec<L, U, Q> const& b
  175. )
  176. {
  177. vec<L, U, Q> Result;
  178. for(length_t i = 0, n = Result.length(); i < n; ++i)
  179. Result[i] = x > y ? a[i] : b[i];
  180. return Result;
  181. }
  182. // Max comparison between 2 variables
  183. template<length_t L, typename T, typename U, qualifier Q>
  184. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMax
  185. (
  186. vec<L, T, Q> const& x, U a,
  187. vec<L, T, Q> const& y, U b
  188. )
  189. {
  190. vec<L, T, Q> Result;
  191. for(length_t i = 0, n = Result.length(); i < n; ++i)
  192. Result[i] = x[i] > y[i] ? a : b;
  193. return Result;
  194. }
  195. // Max comparison between 3 variables
  196. template<typename T, typename U>
  197. GLM_FUNC_QUALIFIER U associatedMax
  198. (
  199. T x, U a,
  200. T y, U b,
  201. T z, U c
  202. )
  203. {
  204. U Result = x > y ? (x > z ? a : c) : (y > z ? b : c);
  205. return Result;
  206. }
  207. // Max comparison between 3 variables
  208. template<length_t L, typename T, typename U, qualifier Q>
  209. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMax
  210. (
  211. vec<L, T, Q> const& x, vec<L, U, Q> const& a,
  212. vec<L, T, Q> const& y, vec<L, U, Q> const& b,
  213. vec<L, T, Q> const& z, vec<L, U, Q> const& c
  214. )
  215. {
  216. vec<L, U, Q> Result;
  217. for(length_t i = 0, n = Result.length(); i < n; ++i)
  218. Result[i] = x[i] > y[i] ? (x[i] > z[i] ? a[i] : c[i]) : (y[i] > z[i] ? b[i] : c[i]);
  219. return Result;
  220. }
  221. // Max comparison between 3 variables
  222. template<length_t L, typename T, typename U, qualifier Q>
  223. GLM_FUNC_QUALIFIER vec<L, T, Q> associatedMax
  224. (
  225. T x, vec<L, U, Q> const& a,
  226. T y, vec<L, U, Q> const& b,
  227. T z, vec<L, U, Q> const& c
  228. )
  229. {
  230. vec<L, U, Q> Result;
  231. for(length_t i = 0, n = Result.length(); i < n; ++i)
  232. Result[i] = x > y ? (x > z ? a[i] : c[i]) : (y > z ? b[i] : c[i]);
  233. return Result;
  234. }
  235. // Max comparison between 3 variables
  236. template<length_t L, typename T, typename U, qualifier Q>
  237. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMax
  238. (
  239. vec<L, T, Q> const& x, U a,
  240. vec<L, T, Q> const& y, U b,
  241. vec<L, T, Q> const& z, U c
  242. )
  243. {
  244. vec<L, T, Q> Result;
  245. for(length_t i = 0, n = Result.length(); i < n; ++i)
  246. Result[i] = x[i] > y[i] ? (x[i] > z[i] ? a : c) : (y[i] > z[i] ? b : c);
  247. return Result;
  248. }
  249. // Max comparison between 4 variables
  250. template<typename T, typename U>
  251. GLM_FUNC_QUALIFIER U associatedMax
  252. (
  253. T x, U a,
  254. T y, U b,
  255. T z, U c,
  256. T w, U d
  257. )
  258. {
  259. T Test1 = max(x, y);
  260. T Test2 = max(z, w);;
  261. U Result1 = x > y ? a : b;
  262. U Result2 = z > w ? c : d;
  263. U Result = Test1 > Test2 ? Result1 : Result2;
  264. return Result;
  265. }
  266. // Max comparison between 4 variables
  267. template<length_t L, typename T, typename U, qualifier Q>
  268. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMax
  269. (
  270. vec<L, T, Q> const& x, vec<L, U, Q> const& a,
  271. vec<L, T, Q> const& y, vec<L, U, Q> const& b,
  272. vec<L, T, Q> const& z, vec<L, U, Q> const& c,
  273. vec<L, T, Q> const& w, vec<L, U, Q> const& d
  274. )
  275. {
  276. vec<L, U, Q> Result;
  277. for(length_t i = 0, n = Result.length(); i < n; ++i)
  278. {
  279. T Test1 = max(x[i], y[i]);
  280. T Test2 = max(z[i], w[i]);
  281. U Result1 = x[i] > y[i] ? a[i] : b[i];
  282. U Result2 = z[i] > w[i] ? c[i] : d[i];
  283. Result[i] = Test1 > Test2 ? Result1 : Result2;
  284. }
  285. return Result;
  286. }
  287. // Max comparison between 4 variables
  288. template<length_t L, typename T, typename U, qualifier Q>
  289. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMax
  290. (
  291. T x, vec<L, U, Q> const& a,
  292. T y, vec<L, U, Q> const& b,
  293. T z, vec<L, U, Q> const& c,
  294. T w, vec<L, U, Q> const& d
  295. )
  296. {
  297. T Test1 = max(x, y);
  298. T Test2 = max(z, w);
  299. vec<L, U, Q> Result;
  300. for(length_t i = 0, n = Result.length(); i < n; ++i)
  301. {
  302. U Result1 = x > y ? a[i] : b[i];
  303. U Result2 = z > w ? c[i] : d[i];
  304. Result[i] = Test1 > Test2 ? Result1 : Result2;
  305. }
  306. return Result;
  307. }
  308. // Max comparison between 4 variables
  309. template<length_t L, typename T, typename U, qualifier Q>
  310. GLM_FUNC_QUALIFIER vec<L, U, Q> associatedMax
  311. (
  312. vec<L, T, Q> const& x, U a,
  313. vec<L, T, Q> const& y, U b,
  314. vec<L, T, Q> const& z, U c,
  315. vec<L, T, Q> const& w, U d
  316. )
  317. {
  318. vec<L, U, Q> Result;
  319. for(length_t i = 0, n = Result.length(); i < n; ++i)
  320. {
  321. T Test1 = max(x[i], y[i]);
  322. T Test2 = max(z[i], w[i]);;
  323. U Result1 = x[i] > y[i] ? a : b;
  324. U Result2 = z[i] > w[i] ? c : d;
  325. Result[i] = Test1 > Test2 ? Result1 : Result2;
  326. }
  327. return Result;
  328. }
  329. }//namespace glm