New basics gets the remainder of the stuff from old basics
EPSILON, MAX_DISTANCE, NearZeor, NearlyEqual, TooFar.
This commit is contained in:
parent
6c23fa9f32
commit
bb789476b6
1 changed files with 56 additions and 0 deletions
|
@ -9,10 +9,66 @@
|
||||||
#ifndef __BASICS_BASICS_HH__
|
#ifndef __BASICS_BASICS_HH__
|
||||||
#define __BASICS_BASICS_HH__
|
#define __BASICS_BASICS_HH__
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include "basics/color.hh"
|
#include "basics/color.hh"
|
||||||
#include "basics/matrix.hh"
|
#include "basics/matrix.hh"
|
||||||
#include "basics/ray.hh"
|
#include "basics/ray.hh"
|
||||||
#include "basics/types.hh"
|
#include "basics/types.hh"
|
||||||
#include "basics/vector.hh"
|
#include "basics/vector.hh"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A very small constant. If a value is between EPSILON and 0.0, it is
|
||||||
|
* considered to be zero.
|
||||||
|
*/
|
||||||
|
const Double EPSILON = 1.0e-10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum distance a ray can travel. This is the maximum value t can be.
|
||||||
|
*/
|
||||||
|
const Double MAX_DISTANCE = 1.0e7;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the value is "close enough" to zero. Takes the absolute value
|
||||||
|
* and compares it to `EPSILON`.
|
||||||
|
*
|
||||||
|
* @see EPSILON
|
||||||
|
*
|
||||||
|
* @param [in] value The value to check
|
||||||
|
* @returns `true` if the value is close enough to zero
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
inline bool
|
||||||
|
NearZero(const T value)
|
||||||
|
{
|
||||||
|
return std::fabs(value) < EPSILON;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if two values are "close enough" to be considered equal. Subtracts
|
||||||
|
* one from the other and checks if the result is near zero.
|
||||||
|
*
|
||||||
|
* @see NearZero
|
||||||
|
*
|
||||||
|
* @param [in] left The left parameter
|
||||||
|
* @param [in] right The right parameter
|
||||||
|
* @returns `true` if the values are close enough to be equal
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
inline bool
|
||||||
|
NearlyEqual(const T left,
|
||||||
|
const T right)
|
||||||
|
{
|
||||||
|
return NearZero(left - right);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
TooFar(const Double& value)
|
||||||
|
{
|
||||||
|
return value > MAX_DISTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* __BASICS_BASICS_HH__ */
|
#endif /* __BASICS_BASICS_HH__ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue