X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgeometry%2Fdistance.hpp;h=91568082c3e06f8a001b0035840a8540f0857834;hb=985dff25f7fde96308a66e5b01bc226589fd0825;hp=b53fcd7c679c7630051ba7911ecdd35818161b48;hpb=ee920127d653b8a3cfbee1efefde909ffa177662;p=blank.git diff --git a/src/geometry/distance.hpp b/src/geometry/distance.hpp index b53fcd7..9156808 100644 --- a/src/geometry/distance.hpp +++ b/src/geometry/distance.hpp @@ -1,40 +1,38 @@ #ifndef BLANK_GEOMETRY_DISTANCE_HPP_ #define BLANK_GEOMETRY_DISTANCE_HPP_ +#include "../graphics/glm.hpp" + #include #include -#include +#include +#include namespace blank { -inline float length_squared(const glm::vec3 &v) noexcept { - return dot(v, v); -} - -inline float distance_squared(const glm::vec3 &a, const glm::vec3 &b) noexcept { - return length_squared(a - b); -} - -inline float distance(const glm::vec3 &a, const glm::vec3 &b) noexcept { - return length(a - b); -} - template inline bool iszero(const T &v) noexcept { - return length_squared(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 { - glm::tvec3 diff(abs(a - b)); - return diff.x + diff.y + diff.z; +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 { - glm::tvec3 a(abs(v)); - return std::max(a.x, std::max(a.y, a.z)); +template +T manhattan_radius(const TVEC3 &v) noexcept { + return glm::compMax(glm::abs(v)); } }