X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgeometry%2Fdistance.hpp;h=ef2f8a2fee5c570bd4dac293a8c190c0399b16cf;hb=242b87a5fb412f9006e4b7debc1408cf7ac83000;hp=b53fcd7c679c7630051ba7911ecdd35818161b48;hpb=ee920127d653b8a3cfbee1efefde909ffa177662;p=blank.git diff --git a/src/geometry/distance.hpp b/src/geometry/distance.hpp index b53fcd7..ef2f8a2 100644 --- a/src/geometry/distance.hpp +++ b/src/geometry/distance.hpp @@ -4,37 +4,34 @@ #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 length2(v) < std::numeric_limits::epsilon(); +} + +template +inline void limit(Vec &v, float max) noexcept { + float len2 = length2(v); + float max2 = max * max; + if (len2 > max2) { + v = 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; + return compAdd(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)); + return compMax(abs(v)); } }