9 #define UNUSED(x) (void)(x) 11 #if defined(__GNUC__) || defined(__clang__) 12 #define likely(x) (__builtin_expect((x), true)) 13 #define unlikely(x) (__builtin_expect((x), false)) 16 #define unlikely(x) (x) 19 static constexpr
float pi = 3.14159265359f;
22 inline float radians(
float x) {
23 return x * pi / 180.0f;
27 inline float degrees(
float x) {
28 return x * 180.0f / pi;
33 inline T clamp(T a, T b, T c) {
34 return (a < b) ? b : ((a > c) ? c : a);
39 inline T closest_log2(T i) {
41 while (i > p) p <<= 1, q++;
46 inline int32_t float_as_int(
float f) {
47 union {
float vf; int32_t vi; } v;
53 inline float int_as_float(int32_t i) {
54 union {
float vf; int32_t vi; } v;
60 inline float prodsign(
float x,
float y) {
61 return int_as_float(float_as_int(x) ^ (float_as_int(y) & 0x80000000));
65 template <
typename T,
typename U>
66 T lerp(T a, T b, U u) {
67 return a * (1 - u) + b * u;
71 template <
typename T,
typename U>
72 T lerp(T a, T b, T c, U u, U v) {
73 return a * (1 - u - v) + b * u + c * v;
79 return (2 * dot(n, v)) * n - v;
83 std::cerr << std::endl;
87 template <
typename T,
typename... Args>
88 inline void error(T t, Args... args) {
90 std::cerr <<
"\033[1;31m";
94 std::cerr <<
"\033[0m";
100 std::cout << std::endl;
104 template <
typename T,
typename... Args>
105 inline void info(T t, Args... args) {
111 std::clog << std::endl;
115 template <
typename T,
typename... Args>
116 inline void warn(T t, Args... args) {
118 std::clog <<
"\033[1;33m";
122 std::clog <<
"\033[0m";
127 #define assert_normalized(x) check_normalized(x, __FILE__, __LINE__) 129 template <
typename T>
130 inline void check_normalized(
const T& n,
const char* file,
size_t line) {
132 const float len = length(n);
133 const float tolerance = 0.001f;
134 if (len < 1.0f - tolerance || len > 1.0f + tolerance) {
135 error(
"Vector not normalized in \'", file,
"\', line ", line);
142 template <
typename T>
145 Atom(
const T& t) : value(t) {}
149 template <
typename T>
150 Atom<T> atomically(
const T& t) {
Class that represents a value that has to be treated atomically.
Definition: common.h:143