-
Notifications
You must be signed in to change notification settings - Fork 0
/
math_tools.hpp
41 lines (31 loc) · 1.21 KB
/
math_tools.hpp
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
#pragma once
//-----------------------------------------------------------------------------
// System Includes
//-----------------------------------------------------------------------------
#pragma region
#include <stdint.h>
#include <math.h>
#pragma endregion
//-----------------------------------------------------------------------------
// Declarations and Definitions
//-----------------------------------------------------------------------------
namespace pathtracing
{
//-------------------------------------------------------------------------
// Declarations and Definitions: Constants
//-------------------------------------------------------------------------
const double g_pi = 3.14159265358979323846;
//-------------------------------------------------------------------------
// Declarations and Definitions: Utilities
//-------------------------------------------------------------------------
constexpr double Clamp(
double x, double low = 0.0, double high = 1.0) noexcept
{
return (x < high) ? ((x > low) ? x : low) : high;
}
inline uint8_t ToByte(double x, double gamma = 2.2) noexcept
{
return static_cast<uint8_t>(Clamp(255.0 * pow(x, 1 / gamma),
0.0, 255.0));
}
} // namespace pathtracing