Ray Tracer  2020
Macros | Functions | Variables
utility.h File Reference

General utility functions. More...

#include <cmath>
#include <limits>
#include <algorithm>
#include <string>

Go to the source code of this file.

Macros

#define UTILITY_H_INCLUDED
 

Functions

double deg2rad (double deg)
 Convert degrees to radians. More...
 
double rad2deg (double rad)
 Convert radians to degrees. More...
 
int sign (double val)
 Return the sign of a number. More...
 
std::string toUpper (const std::string &str)
 Convert a string to upper case. More...
 

Variables

const double epsilon = 1e-6
 Small number for checking when things are almost zero. More...
 
const double infinity = std::numeric_limits<double>::max()
 Very large number, bigger than any sensible distance. More...
 
const double pi = 3.141592653589793
 \(\pi\), obviously. Note that M_PI is NOT part of standard C/C++, so is not portable More...
 

Detailed Description

General utility functions.

Macro Definition Documentation

◆ UTILITY_H_INCLUDED

#define UTILITY_H_INCLUDED

Function Documentation

◆ deg2rad()

double deg2rad ( double  deg)
inline

Convert degrees to radians.

C++ mathematical functions expect angles in radians, but many people think in degrees. The high level Transform functions expect parameters in degrees and this function, along with deg2rad(), converts between the two.

Parameters
degAn angle measured in degrees.
Returns
The angle measured in radians.

◆ rad2deg()

double rad2deg ( double  rad)
inline

Convert radians to degrees.

C++ mathematical functions expect angles in radians, but many people think in degrees. The high level Transform functions expect parameters in degrees and this function, along with rad2deg(), converts between the two.

Parameters
radAn angle measured in radians.
Returns
The angle measured in degrees.

◆ sign()

int sign ( double  val)
inline

Return the sign of a number.

This function returns +1 for positive numbers, -1 for negative numbers and 0 for zero values. Since rounding can cause non-zero values, very small numbers (less than epsilon) are returned as being 0.

Parameters
valThe value to check the sign of.
Returns
0, +1, or -1 depending on the sign of val.

◆ toUpper()

std::string toUpper ( const std::string &  str)
inline

Convert a string to upper case.

This function returns a copy of the input string with all lower case characters converted to upper case.

Parameters
strThe string to convert.
Returns
The string converted to upper case.

Variable Documentation

◆ epsilon

const double epsilon = 1e-6

Small number for checking when things are almost zero.

◆ infinity

const double infinity = std::numeric_limits<double>::max()

Very large number, bigger than any sensible distance.

◆ pi

const double pi = 3.141592653589793

\(\pi\), obviously. Note that M_PI is NOT part of standard C/C++, so is not portable