]> git.localhorst.tv Git - blobs.git/blob - src/math/glm.hpp
color conversion tests
[blobs.git] / src / math / glm.hpp
1 #ifndef BLOBS_MATH_GLM_HPP_
2 #define BLOBS_MATH_GLM_HPP_
3
4 #ifndef GLM_FORCE_RADIANS
5 #  define GLM_FORCE_RADIANS 1
6 #endif
7
8 #include <algorithm>
9 #include <limits>
10 #include <glm/glm.hpp>
11 #include <glm/gtx/norm.hpp>
12 #include <glm/gtx/component_wise.hpp>
13
14 // GLM moved tvec[1234] from glm::detail to glm in 0.9.6
15
16 #if GLM_VERSION < 96
17
18 namespace glm {
19         template<class T, precision P = defaultp>
20         using tvec1 = detail::tvec1<T, P>;
21         template<class T, precision P = defaultp>
22         using tvec2 = detail::tvec2<T, P>;
23         template<class T, precision P = defaultp>
24         using tvec3 = detail::tvec3<T, P>;
25         template<class T, precision P = defaultp>
26         using tvec4 = detail::tvec4<T, P>;
27 }
28
29 #endif
30
31 template <class T>
32 inline bool allzero(const T &v) noexcept {
33         return glm::length2(v) <
34                 std::numeric_limits<typename T::value_type>::epsilon()
35                 * std::numeric_limits<typename T::value_type>::epsilon();
36 }
37
38 template <class T>
39 inline bool anynan(const T &v) noexcept {
40         return glm::any(glm::isnan(v));
41 }
42
43 template<class Vec>
44 inline Vec limit(const Vec &v, typename Vec::value_type max) noexcept {
45         typename Vec::value_type len2 = glm::length2(v);
46         typename Vec::value_type max2 = max * max;
47         if (len2 > max2) {
48                 return glm::normalize(v) * max;
49         } else {
50                 return v;
51         }
52 }
53
54 #endif