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