Ocular Engine
Equality.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_ENGINE_MATH_EQUALITY__H__
19 #define __H__OCULAR_ENGINE_MATH_EQUALITY__H__
20 
21 #include "MathCommon.hpp"
22 #include <cmath>
23 
24 //------------------------------------------------------------------------------------------
25 
30 namespace Ocular
31 {
36  namespace Math
37  {
38  // We have overridden versions for double and float but maintain the use of templates for
39  // them (despite them not needing templates) to keep convention consistant between all types.
40 
41  // TODO: There is a different way of accomplishing this but I do not remember.
42 
46  template<typename T>
47  static bool IsEqual(double const a, double const b, double epsilon = EPSILON_DOUBLE)
48  {
49  //return std::fabs(a - b) <= (((std::fabs(a) > std::fabs(b)) ? std::fabs(b) : std::fabs(a)) * epsilon);
50  return std::abs(a - b) < epsilon;
51  }
52 
56  template<typename T>
57  static bool IsEqual(float const a, float const b, float epsilon = EPSILON_FLOAT)
58  {
59  //return std::fabs(a - b) <= (((std::fabs(a) > std::fabs(b)) ? std::fabs(b) : std::fabs(a)) * epsilon);
60  return std::abs(a - b) < epsilon;
61  }
62 
66  template<typename T>
67  static bool IsEqual(T const a, T const b)
68  {
69  return (a == b);
70  }
71 
72  template<typename T>
73  static bool IsZero(T const a)
74  {
75  return IsEqual<T>(a, static_cast<T>(0));
76  }
77 
78  template<typename T>
79  static bool IsOne(T const a)
80  {
81  return IsEqual<T>(a, static_cast<T>(1));
82  }
83  }
87 }
92 //------------------------------------------------------------------------------------------
93 
94 #endif
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70