Ray Tracer  2020
utility.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef UTILITY_H_INCLUDED
4 #define UTILITY_H_INCLUDED
5 
6 #include <cmath>
7 #include <limits>
8 #include <algorithm>
9 #include <string>
10 
15 const double epsilon = 1e-6;
16 
17 const double infinity = std::numeric_limits<double>::max();
18 
19 const double pi = 3.141592653589793;
20 
31 inline double deg2rad(double deg) {
32  return deg*pi/180;
33 }
34 
45 inline double rad2deg(double rad) {
46  return rad*180/pi;
47 }
48 
49 
60 inline int sign(double val) {
61  if (std::abs(val) < epsilon) return 0;
62  if (val < 0) return -1;
63  return 1;
64 }
65 
75 inline std::string toUpper(const std::string& str) {
76  std::string tmp = str;
77  std::transform(tmp.begin(), tmp.end(), tmp.begin(), toupper);
78  return tmp;
79 }
80 
81 #endif // UTILITY_H_INCLUDED
std::string toUpper(const std::string &str)
Convert a string to upper case.
Definition: utility.h:75
const double infinity
Very large number, bigger than any sensible distance.
Definition: utility.h:17
const double pi
, obviously. Note that M_PI is NOT part of standard C/C++, so is not portable
Definition: utility.h:19
double deg2rad(double deg)
Convert degrees to radians.
Definition: utility.h:31
int sign(double val)
Return the sign of a number.
Definition: utility.h:60
const double epsilon
Small number for checking when things are almost zero.
Definition: utility.h:15
double rad2deg(double rad)
Convert radians to degrees.
Definition: utility.h:45