toytracer/util.h

32 lines
728 B
C
Raw Normal View History

2020-06-03 22:15:32 +00:00
#ifndef UTIL_H
#define UTIL_H
#include <limits>
2020-06-03 22:39:14 +00:00
#include <random>
#include <ctime>
2020-06-03 22:15:32 +00:00
const double infinity = std::numeric_limits<double>::infinity();
const double pi = 3.1415926535897932385;
inline double degrees_to_radians(double degrees) {
return degrees * pi / 180;
}
2020-06-03 22:39:14 +00:00
inline double random_double() {
static std::uniform_real_distribution<double> distribution(0.0, 1.0);
static std::mt19937 generator(std::time(nullptr));
2020-06-03 22:39:14 +00:00
return distribution(generator);
}
inline double random_double(double min, double max) {
return min + (max-min) * random_double();
}
inline double clamp(double x, double min, double max) {
if (x < min) return min;
if (x > max) return max;
return x;
}
2020-06-03 22:15:32 +00:00
#endif // UTIL_H