X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgeometry%2Fdistance.hpp;h=91568082c3e06f8a001b0035840a8540f0857834;hb=292a23aab0c4d837cb69aafde45a4d0cab980782;hp=b6955af49391e570cd81970e9a75a57bd9787c9f;hpb=f5de855fbd4bf5b0df1cad950cbe9069e41369ca;p=blank.git diff --git a/src/geometry/distance.hpp b/src/geometry/distance.hpp index b6955af..9156808 100644 --- a/src/geometry/distance.hpp +++ b/src/geometry/distance.hpp @@ -1,9 +1,10 @@ #ifndef BLANK_GEOMETRY_DISTANCE_HPP_ #define BLANK_GEOMETRY_DISTANCE_HPP_ +#include "../graphics/glm.hpp" + #include #include -#include #include #include @@ -12,17 +13,26 @@ namespace blank { template inline bool iszero(const T &v) noexcept { - return length2(v) < std::numeric_limits::epsilon(); + return glm::length2(v) < std::numeric_limits::epsilon(); +} + +template +inline void limit(Vec &v, float max) noexcept { + float len2 = glm::length2(v); + float max2 = max * max; + if (len2 > max2) { + v = glm::normalize(v) * max; + } } -template -T manhattan_distance(const glm::tvec3 &a, const glm::tvec3 &b) noexcept { - return compAdd(abs(a - b)); +template +T manhattan_distance(const TVEC3 &a, const TVEC3 &b) noexcept { + return glm::compAdd(glm::abs(a - b)); } -template -T manhattan_radius(const glm::tvec3 &v) noexcept { - return compMax(abs(v)); +template +T manhattan_radius(const TVEC3 &v) noexcept { + return glm::compMax(glm::abs(v)); } }