1 #ifndef GONG_GEOMETRY_DISTANCE_HPP_
2 #define GONG_GEOMETRY_DISTANCE_HPP_
4 #include "../graphics/glm.hpp"
8 #include <glm/gtx/component_wise.hpp>
9 #include <glm/gtx/norm.hpp>
16 inline bool iszero(const T &v) noexcept {
17 return glm::length2(v) < std::numeric_limits<typename T::value_type>::epsilon();
21 inline void limit(Vec &v, float max) noexcept {
22 float len2 = glm::length2(v);
23 float max2 = max * max;
25 v = glm::normalize(v) * max;
29 template<class T, glm::precision P = glm::precision(0)>
30 T manhattan_distance(const TVEC3<T, P> &a, const TVEC3<T, P> &b) noexcept {
31 return glm::compAdd(glm::abs(a - b));
34 template<class T, glm::precision P = glm::precision(0)>
35 T manhattan_radius(const TVEC3<T, P> &v) noexcept {
36 return glm::compMax(glm::abs(v));