1 /////////////////////////////////////////////////////////////////////////////////////////////////// 2 // OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net) 3 /////////////////////////////////////////////////////////////////////////////////////////////////// 4 // Created : 2005-12-21 5 // Updated : 2008-07-24 6 // Licence : This source is under MIT License 7 // File : glm/gtx/norm.inl 8 /////////////////////////////////////////////////////////////////////////////////////////////////// 9 10 namespace glm 11 { 12 template <typename T> 13 GLM_FUNC_QUALIFIER T length2 14 ( 15 T const & x 16 ) 17 { 18 return x * x; 19 } 20 21 template <typename T, precision P> 22 GLM_FUNC_QUALIFIER T length2 23 ( 24 detail::tvec2<T, P> const & x 25 ) 26 { 27 return dot(x, x); 28 } 29 30 template <typename T, precision P> 31 GLM_FUNC_QUALIFIER T length2 32 ( 33 detail::tvec3<T, P> const & x 34 ) 35 { 36 return dot(x, x); 37 } 38 39 template <typename T, precision P> 40 GLM_FUNC_QUALIFIER T length2 41 ( 42 detail::tvec4<T, P> const & x 43 ) 44 { 45 return dot(x, x); 46 } 47 48 template <typename T> 49 GLM_FUNC_QUALIFIER T distance2 50 ( 51 T const & p0, 52 T const & p1 53 ) 54 { 55 return length2(p1 - p0); 56 } 57 58 template <typename T, precision P> 59 GLM_FUNC_QUALIFIER T distance2 60 ( 61 detail::tvec2<T, P> const & p0, 62 detail::tvec2<T, P> const & p1 63 ) 64 { 65 return length2(p1 - p0); 66 } 67 68 template <typename T, precision P> 69 GLM_FUNC_QUALIFIER T distance2 70 ( 71 detail::tvec3<T, P> const & p0, 72 detail::tvec3<T, P> const & p1 73 ) 74 { 75 return length2(p1 - p0); 76 } 77 78 template <typename T, precision P> 79 GLM_FUNC_QUALIFIER T distance2 80 ( 81 detail::tvec4<T, P> const & p0, 82 detail::tvec4<T, P> const & p1 83 ) 84 { 85 return length2(p1 - p0); 86 } 87 88 template <typename T, precision P> 89 GLM_FUNC_QUALIFIER T l1Norm 90 ( 91 detail::tvec3<T, P> const & a, 92 detail::tvec3<T, P> const & b 93 ) 94 { 95 return abs(b.x - a.x) + abs(b.y - a.y) + abs(b.z - a.z); 96 } 97 98 template <typename T, precision P> 99 GLM_FUNC_QUALIFIER T l1Norm 100 ( 101 detail::tvec3<T, P> const & v 102 ) 103 { 104 return abs(v.x) + abs(v.y) + abs(v.z); 105 } 106 107 template <typename T, precision P> 108 GLM_FUNC_QUALIFIER T l2Norm 109 ( 110 detail::tvec3<T, P> const & a, 111 detail::tvec3<T, P> const & b 112 ) 113 { 114 return length(b - a); 115 } 116 117 template <typename T, precision P> 118 GLM_FUNC_QUALIFIER T l2Norm 119 ( 120 detail::tvec3<T, P> const & v 121 ) 122 { 123 return length(v); 124 } 125 126 template <typename T, precision P> 127 GLM_FUNC_QUALIFIER T lxNorm 128 ( 129 detail::tvec3<T, P> const & x, 130 detail::tvec3<T, P> const & y, 131 unsigned int Depth 132 ) 133 { 134 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)); 135 } 136 137 template <typename T, precision P> 138 GLM_FUNC_QUALIFIER T lxNorm 139 ( 140 detail::tvec3<T, P> const & v, 141 unsigned int Depth 142 ) 143 { 144 return pow(pow(v.x, T(Depth)) + pow(v.y, T(Depth)) + pow(v.z, T(Depth)), T(1) / T(Depth)); 145 } 146 147 }//namespace glm 148