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
8namespace 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
static ScalarT Sign(ScalarT s)
Definition MathHelper.h:25
static ScalarT Max(ScalarT a, ScalarT b)
Definition MathHelper.h:53
static ScalarT Clamp(ScalarT s, ScalarT bottom, ScalarT top)
Definition MathHelper.h:39
static ScalarT Abs(ScalarT s)
Definition MathHelper.h:15
static ScalarT Min(ScalarT a, ScalarT b)
Definition MathHelper.h:63
Definition AABox.h:10