… | |
… | |
54 | template<typename T, typename U, typename V> static inline T clamp (T v, U a, V b) { return v < (T)a ? a : v >(T)b ? b : v; } |
54 | template<typename T, typename U, typename V> static inline T clamp (T v, U a, V b) { return v < (T)a ? a : v >(T)b ? b : v; } |
55 | template<typename T, typename U, typename V> static inline void clamp_it (T &v, U a, V b) { v = v < (T)a ? a : v >(T)b ? b : v; } |
55 | template<typename T, typename U, typename V> static inline void clamp_it (T &v, U a, V b) { v = v < (T)a ? a : v >(T)b ? b : v; } |
56 | |
56 | |
57 | template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } |
57 | template<typename T, typename U> static inline void swap (T& a, U& b) { T t=a; a=(T)b; b=(U)t; } |
58 | |
58 | |
|
|
59 | template<typename T> static inline T squared_diff (T a, T b) { return (a-b)*(a-b); } |
|
|
60 | |
59 | // linear interpolation |
61 | // linear interpolation |
60 | template<typename T, typename U, typename P> |
62 | template<typename T, typename U, typename P> |
61 | static inline |
63 | static inline |
62 | T lerp (T a, U b, P p) |
64 | T lerp (T a, U b, P p) |
63 | { |
65 | { |
64 | return (int(a) * int(p) + int(b) * int(100 - p)) / 100; |
66 | return (long(a) * long(100 - p) + long(b) * long(p) + 50) / 100; |
65 | } |
67 | } |
66 | |
68 | |
67 | // some bit functions, xft fuck me plenty |
69 | // some bit functions, xft fuck me plenty |
68 | #if HAVE_GCC_BUILTINS |
70 | #if HAVE_GCC_BUILTINS |
69 | static inline int ctz (unsigned int x) CONST { return __builtin_ctz (x); } |
71 | static inline int ctz (unsigned int x) CONST { return __builtin_ctz (x); } |