voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
math.hpp
1 #ifndef BLUB_MATH_HPP
2 #define BLUB_MATH_HPP
3 
4 #include "blub/core/globals.hpp"
5 
6 #include <boost/config/suffix.hpp>
7 
8 #include <algorithm>
9 
10 
11 namespace blub
12 {
13 
14 
15 class math
16 {
17 public:
18 
19 
20 #if defined(BOOST_NO_CXX11_CONSTEXPR)
21  static const real math::pi;
22  static const real math::piHalf;
23  static const real math::sqrtZeroPointFive;
24  static const real math::sqrtOneThird;
25 #else
26  static constexpr real pi = 3.14159265358979323846;
27  static constexpr real piHalf = pi / 2.;
28  static constexpr real sqrtZeroPointFive = 0.707106781;
29  static constexpr real sqrtOneThird = 0.577350269; // sqrt(1/3)
30 #endif
31 
32 
33  template <typename T>
34  static T min(const T &val, const T &minimum)
35  {
36  return std::min(val, minimum);
37  }
38  template <typename T>
39  static T max(const T &val, const T &maximum)
40  {
41  return std::max(val, maximum);
42  }
43  static real abs(const real& calc);
44 
45  template <typename T>
46  static T clamp(const T& val, const T& minval, const T& maxval)
47  {
48  BASSERT(minval <= maxval);
49  return std::max(std::min(val, maxval), minval);
50  }
51  template <typename T, typename pairType>
52  static T clamp(const T& val, const pairType& minMaxVal)
53  {
54  BASSERT(minMaxVal.first <= minMaxVal.second);
55  return clamp(val, minMaxVal.first, minMaxVal.second);
56  }
57 
58  static real map(const real &value, const real &fromMin, const real &fromMax, const real &toMin, const real &toMax);
59 
60  template <typename T>
61  static T floor(const T& calc)
62  {
63  return std::floor(calc);
64  }
65  template <typename T>
66  static T ceil(const T& val)
67  {
68  return std::ceil(val);
69  }
70 
71  template <typename T>
72  static bool between(const T& number, const T& min, const T& max)
73  {
74  return (number >= min) && (number <= max);
75  }
76 
77  static real sin(const real& calc);
78  static real asin(const real& calc);
79  static real cos(const real& calc);
80  static real acos(const real& calc);
81  static real atan2(const real& fst, const real& snd);
82 
83  static real sqrt(const real& calc);
84 
85  static int32 pow(const int32& number, const int32& expo);
86  static real pow(const real& number, const real& expo);
87 
88  static uint32 rand();
89  static real randReal();
90 
91 private:
92  math()
93  {;}
94 
95 };
96 
97 }
98 
99 #endif // BLUB_MATH_HPP
Definition: math.hpp:15
Definition: map.hpp:11
Definition: deadlineTimer.hpp:10