TurtleBrains  0.3.0
High quality, portable, C++ API for native application and game development.
tb_math.h
1 
9 #ifndef _TurtleBrains_Math_h_
10 #define _TurtleBrains_Math_h_
11 
12 #include "../core/tb_configuration.h"
13 #include "tb_constants.h"
14 
15 #include <cmath>
16 
17 namespace TurtleBrains
18 {
19  namespace Math
20  {
30  inline bool IsEqual(const float leftValue, const float rightValue, const float tolerance = tbMath::kTolerance)
31  {
32  return fabs(leftValue - rightValue) <= tolerance;
33  }
34 
43  inline bool IsZero(const float value, const float tolerance = tbMath::kTolerance)
44  {
45  return (fabs(value)) <= tolerance;
46  }
47 
56  template <typename T> constexpr const T& Maximum(const T& leftValue, const T& rightValue) noexcept
57  {
58  return (leftValue < rightValue) ? rightValue : leftValue;
59  }
60 
69  template <typename T> constexpr const T& Minimum(const T& leftValue, const T& rightValue) noexcept
70  {
71  return (leftValue < rightValue) ? leftValue : rightValue;
72  }
73 
86  template <typename T> constexpr const T& Clamp(const T& value, const T& minimumValue, const T& maximumValue) noexcept
87  {
88  return (value < minimumValue) ? minimumValue : (maximumValue < value) ? maximumValue : value;
89  }
90 
91  }; /* namespace Math */
92 }; /* namespace TurtleBrains */
93 
94 namespace tbMath = TurtleBrains::Math;
95 
96 #endif /* _TurtleBrains_Math_h_ */
Contains objects and functions for dealing with Vector and Matrix math.
Contains all functions, classes and helpers related to game/application development written by Tim "B...
Definition: tb_application_dialog.h:21
constexpr const T & Clamp(const T &value, const T &minimumValue, const T &maximumValue) noexcept
Definition: tb_math.h:86
bool IsZero(const float value, const float tolerance=tbMath::kTolerance)
Definition: tb_math.h:43
constexpr const T & Maximum(const T &leftValue, const T &rightValue) noexcept
Definition: tb_math.h:56
bool IsEqual(const float leftValue, const float rightValue, const float tolerance=tbMath::kTolerance)
Definition: tb_math.h:30
constexpr const T & Minimum(const T &leftValue, const T &rightValue) noexcept
Definition: tb_math.h:69