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 #include <cmath>
14 
15 namespace TurtleBrains
16 {
17  namespace Math
18  {
28  inline bool IsEqual(const float leftValue, const float rightValue, const float tolerance = tbMath::kTolerance)
29  {
30  return fabs(leftValue - rightValue) <= tolerance;
31  }
32 
41  inline bool IsZero(const float value, const float tolerance = tbMath::kTolerance)
42  {
43  return (fabs(value)) <= tolerance;
44  }
45 
54  template <typename T> const T& Maximum(const T& leftValue, const T& rightValue)
55  {
56  return (leftValue < rightValue) ? rightValue : leftValue;
57  }
58 
67  template <typename T> const T& Minimum(const T& leftValue, const T& rightValue)
68  {
69  return (leftValue < rightValue) ? leftValue : rightValue;
70  }
71 
84  template <typename T> const T& Clamp(const T& value, const T& minimumValue, const T& maximumValue)
85  {
86  if (value < minimumValue) return minimumValue;
87  if (maximumValue < value) return maximumValue;
88  return 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.
const T & Clamp(const T &value, const T &minimumValue, const T &maximumValue)
Definition: tb_math.h:84
Contains all functions, classes and helpers related to game/application development written by Tim "B...
Definition: tb_application_dialog.h:21
const T & Maximum(const T &leftValue, const T &rightValue)
Definition: tb_math.h:54
bool IsZero(const float value, const float tolerance=tbMath::kTolerance)
Definition: tb_math.h:41
bool IsEqual(const float leftValue, const float rightValue, const float tolerance=tbMath::kTolerance)
Definition: tb_math.h:28
const T & Minimum(const T &leftValue, const T &rightValue)
Definition: tb_math.h:67