1/// @ref gtx_norm 2/// @file glm/gtx/norm.inl 3 4#include "../detail/precision.hpp" 5 6namespace glm{ 7namespace detail 8{ 9 template <template <typename, precision> class vecType, typename T, precision P, bool Aligned> 10 struct compute_length2 11 { 12 GLM_FUNC_QUALIFIER static T call(vecType<T, P> const & v) 13 { 14 return dot(v, v); 15 } 16 }; 17}//namespace detail 18 19 template <typename genType> 20 GLM_FUNC_QUALIFIER genType length2(genType x) 21 { 22 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'length2' accepts only floating-point inputs"); 23 return x * x; 24 } 25 26 template <typename T, precision P, template <typename, precision> class vecType> 27 GLM_FUNC_QUALIFIER T length2(vecType<T, P> const & v) 28 { 29 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'length2' accepts only floating-point inputs"); 30 return detail::compute_length2<vecType, T, P, detail::is_aligned<P>::value>::call(v); 31 } 32 33 template <typename T> 34 GLM_FUNC_QUALIFIER T distance2(T p0, T p1) 35 { 36 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'distance2' accepts only floating-point inputs"); 37 return length2(p1 - p0); 38 } 39 40 template <typename T, precision P, template <typename, precision> class vecType> 41 GLM_FUNC_QUALIFIER T distance2(vecType<T, P> const & p0, vecType<T, P> const & p1) 42 { 43 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'distance2' accepts only floating-point inputs"); 44 return length2(p1 - p0); 45 } 46 47 template <typename T, precision P> 48 GLM_FUNC_QUALIFIER T l1Norm 49 ( 50 tvec3<T, P> const & a, 51 tvec3<T, P> const & b 52 ) 53 { 54 return abs(b.x - a.x) + abs(b.y - a.y) + abs(b.z - a.z); 55 } 56 57 template <typename T, precision P> 58 GLM_FUNC_QUALIFIER T l1Norm 59 ( 60 tvec3<T, P> const & v 61 ) 62 { 63 return abs(v.x) + abs(v.y) + abs(v.z); 64 } 65 66 template <typename T, precision P> 67 GLM_FUNC_QUALIFIER T l2Norm 68 ( 69 tvec3<T, P> const & a, 70 tvec3<T, P> const & b 71 ) 72 { 73 return length(b - a); 74 } 75 76 template <typename T, precision P> 77 GLM_FUNC_QUALIFIER T l2Norm 78 ( 79 tvec3<T, P> const & v 80 ) 81 { 82 return length(v); 83 } 84 85 template <typename T, precision P> 86 GLM_FUNC_QUALIFIER T lxNorm 87 ( 88 tvec3<T, P> const & x, 89 tvec3<T, P> const & y, 90 unsigned int Depth 91 ) 92 { 93 return pow(pow(y.x - x.x, T(Depth)) + pow(y.y - x.y, T(Depth)) + pow(y.z - x.z, T(Depth)), T(1) / T(Depth)); 94 } 95 96 template <typename T, precision P> 97 GLM_FUNC_QUALIFIER T lxNorm 98 ( 99 tvec3<T, P> const & v, 100 unsigned int Depth 101 ) 102 { 103 return pow(pow(v.x, T(Depth)) + pow(v.y, T(Depth)) + pow(v.z, T(Depth)), T(1) / T(Depth)); 104 } 105 106}//namespace glm 107