TurtleBrains  0.2.1
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 "tb_constants.h"
13 
14 #include <cmath>
15 
16 namespace TurtleBrains
17 {
18  namespace Math
19  {
29  inline bool IsEqual(const float leftValue, const float rightValue, const float tolerance = tbMath::kTolerance)
30  {
31  return fabs(leftValue - rightValue) <= tolerance;
32  }
33 
42  inline bool IsZero(const float value, const float tolerance = tbMath::kTolerance)
43  {
44  return (fabs(value)) <= tolerance;
45  }
46 
55  template <typename T> constexpr const T& Maximum(const T& leftValue, const T& rightValue) noexcept
56  {
57  return (leftValue < rightValue) ? rightValue : leftValue;
58  }
59 
68  template <typename T> constexpr const T& Minimum(const T& leftValue, const T& rightValue) noexcept
69  {
70  return (leftValue < rightValue) ? leftValue : rightValue;
71  }
72 
85  template <typename T> constexpr const T& Clamp(const T& value, const T& minimumValue, const T& maximumValue) noexcept
86  {
87  return (value < minimumValue) ? minimumValue : (maximumValue < value) ? maximumValue : value;
88  }
89 
90  }; /* namespace Math */
91 }; /* namespace TurtleBrains */
92 
93 namespace tbMath = TurtleBrains::Math;
94 
95 #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:85
bool IsZero(const float value, const float tolerance=tbMath::kTolerance)
Definition: tb_math.h:42
constexpr const T & Maximum(const T &leftValue, const T &rightValue) noexcept
Definition: tb_math.h:55
bool IsEqual(const float leftValue, const float rightValue, const float tolerance=tbMath::kTolerance)
Definition: tb_math.h:29
constexpr const T & Minimum(const T &leftValue, const T &rightValue) noexcept
Definition: tb_math.h:68