-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.h
More file actions
57 lines (45 loc) · 1.11 KB
/
misc.h
File metadata and controls
57 lines (45 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef RAYTRACINGWEEKEND_RTWEEKEND_H
#define RAYTRACINGWEEKEND_RTWEEKEND_H
#include <limits>
#include <memory>
#include <cmath>
#include <iostream>
#include <fstream>
#include <random>
#include <format>
#include <algorithm>
// C++ std usings
using std::make_shared;
using std::shared_ptr;
// Constants
constexpr double infinity = std::numeric_limits<double>::infinity();
constexpr double pi = 3.1415926535897932385;
// Util funcs
inline double deg_to_rad(double deg)
{
return deg * pi / 180.0;
}
/// Returns random double from [0, 1).
inline double rand_double()
{
// c++ 11+
static std::uniform_real_distribution<double> distribution(0.0, 1.0); // [0, 1)
static std::mt19937 generator;
return distribution(generator);
}
/// Returns random double from [min, max).
inline double rand_double(double min, double max)
{
return min + (max-min) * rand_double();
}
/// Returns a random int from [min, max].
inline int rand_int(int min, int max)
{
return int(rand_double(min, max+1));
}
// Common headers
#include "color.h"
#include "interval.h"
#include "ray.h"
#include "vec3.h"
#endif //RAYTRACINGWEEKEND_RTWEEKEND_H