]> git.localhorst.tv Git - blank.git/blob - src/geometry/distance.hpp
split geometry lib
[blank.git] / src / geometry / distance.hpp
1 #ifndef BLANK_GEOMETRY_DISTANCE_HPP_
2 #define BLANK_GEOMETRY_DISTANCE_HPP_
3
4 #include <algorithm>
5 #include <limits>
6 #include <glm/glm.hpp>
7
8
9 namespace blank {
10
11 inline float length_squared(const glm::vec3 &v) noexcept {
12         return dot(v, v);
13 }
14
15 inline float distance_squared(const glm::vec3 &a, const glm::vec3 &b) noexcept {
16         return length_squared(a - b);
17 }
18
19 template <class T>
20 inline bool iszero(const T &v) noexcept {
21         return length_squared(v) < std::numeric_limits<typename T::value_type>::epsilon();
22 }
23
24 template<class T>
25 T manhattan_distance(const glm::tvec3<T> &a, const glm::tvec3<T> &b) noexcept {
26         glm::tvec3<T> diff(abs(a - b));
27         return diff.x + diff.y + diff.z;
28 }
29
30 template<class T>
31 T manhattan_radius(const glm::tvec3<T> &v) noexcept {
32         glm::tvec3<T> a(abs(v));
33         return std::max(a.x, std::max(a.y, a.z));
34 }
35
36 }
37
38 #endif