MathHelper.h
Go to the documentation of this file.
1 #ifndef __GfxTL_MATHHELPER_HEADER__
2 #define __GfxTL_MATHHELPER_HEADER__
3 #ifndef _USE_MATH_DEFINES
4 #define _USE_MATH_DEFINES
5 #endif
6 #include <cmath>
7 
8 namespace GfxTL
9 {
10  template <class ScalarT>
11  class Math
12  {
13  public:
14  static inline ScalarT
15  Abs(ScalarT s)
16  {
17  if (s < 0)
18  {
19  return -s;
20  }
21  return s;
22  }
23 
24  static inline ScalarT
25  Sign(ScalarT s)
26  {
27  if (s < 0)
28  {
29  return -1;
30  }
31  else if (s > 0)
32  {
33  return 1;
34  }
35  return 0;
36  }
37 
38  static inline ScalarT
39  Clamp(ScalarT s, ScalarT bottom, ScalarT top)
40  {
41  if (s < bottom)
42  {
43  return bottom;
44  }
45  if (s > top)
46  {
47  return top;
48  }
49  return s;
50  }
51 
52  static inline ScalarT
53  Max(ScalarT a, ScalarT b)
54  {
55  if (a > b)
56  {
57  return a;
58  }
59  return b;
60  }
61 
62  static inline ScalarT
63  Min(ScalarT a, ScalarT b)
64  {
65  if (a < b)
66  {
67  return a;
68  }
69  return b;
70  }
71  };
72 
73  /*template< >
74  class Math< float >
75  {
76  public:
77  static inline float Abs(float s)
78  {
79  // *reinterpret_cast< unsigned int * >(&s) &= 0x7FFFFFFFu;
80  if(s < 0) return -s;
81  return s;
82  }
83 
84  static inline float Sign(float s)
85  {
86  if(s < 0)
87  return -1;
88  else
89  return 1;
90  }
91 
92  static inline float Clamp(float s, float bottom, float top)
93  {
94  if(s < bottom)
95  return bottom;
96  if(s > top)
97  return top;
98  return s;
99  }
100 
101  static inline float Max(float a, float b)
102  {
103  if(a > b)
104  return a;
105  return b;
106  }
107 
108  static inline float Min(float a, float b)
109  {
110  if(a < b)
111  return a;
112  return b;
113  }
114  };*/
115 }; // namespace GfxTL
116 
117 #endif
GfxTL::Math::Abs
static ScalarT Abs(ScalarT s)
Definition: MathHelper.h:15
GfxTL::Math::Sign
static ScalarT Sign(ScalarT s)
Definition: MathHelper.h:25
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
GfxTL::Math::Min
static ScalarT Min(ScalarT a, ScalarT b)
Definition: MathHelper.h:63
GfxTL::Math
Definition: MathHelper.h:11
GfxTL::Math::Clamp
static ScalarT Clamp(ScalarT s, ScalarT bottom, ScalarT top)
Definition: MathHelper.h:39
GfxTL
Definition: AABox.h:9
GfxTL::Math::Max
static ScalarT Max(ScalarT a, ScalarT b)
Definition: MathHelper.h:53
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33