9
3

norm.inl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /// @ref gtx_norm
  2. #include "../detail/qualifier.hpp"
  3. namespace glm{
  4. namespace detail
  5. {
  6. template<length_t L, typename T, qualifier Q, bool Aligned>
  7. struct compute_length2
  8. {
  9. GLM_FUNC_QUALIFIER static T call(vec<L, T, Q> const& v)
  10. {
  11. return dot(v, v);
  12. }
  13. };
  14. }//namespace detail
  15. template<typename genType>
  16. GLM_FUNC_QUALIFIER genType length2(genType x)
  17. {
  18. GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'length2' accepts only floating-point inputs");
  19. return x * x;
  20. }
  21. template<length_t L, typename T, qualifier Q>
  22. GLM_FUNC_QUALIFIER T length2(vec<L, T, Q> const& v)
  23. {
  24. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'length2' accepts only floating-point inputs");
  25. return detail::compute_length2<L, T, Q, detail::is_aligned<Q>::value>::call(v);
  26. }
  27. template<typename T>
  28. GLM_FUNC_QUALIFIER T distance2(T p0, T p1)
  29. {
  30. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'distance2' accepts only floating-point inputs");
  31. return length2(p1 - p0);
  32. }
  33. template<length_t L, typename T, qualifier Q>
  34. GLM_FUNC_QUALIFIER T distance2(vec<L, T, Q> const& p0, vec<L, T, Q> const& 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. template<typename T, qualifier Q>
  40. GLM_FUNC_QUALIFIER T l1Norm(vec<3, T, Q> const& a, vec<3, T, Q> const& b)
  41. {
  42. return abs(b.x - a.x) + abs(b.y - a.y) + abs(b.z - a.z);
  43. }
  44. template<typename T, qualifier Q>
  45. GLM_FUNC_QUALIFIER T l1Norm(vec<3, T, Q> const& v)
  46. {
  47. return abs(v.x) + abs(v.y) + abs(v.z);
  48. }
  49. template<typename T, qualifier Q>
  50. GLM_FUNC_QUALIFIER T l2Norm(vec<3, T, Q> const& a, vec<3, T, Q> const& b
  51. )
  52. {
  53. return length(b - a);
  54. }
  55. template<typename T, qualifier Q>
  56. GLM_FUNC_QUALIFIER T l2Norm(vec<3, T, Q> const& v)
  57. {
  58. return length(v);
  59. }
  60. template<typename T, qualifier Q>
  61. GLM_FUNC_QUALIFIER T lxNorm(vec<3, T, Q> const& x, vec<3, T, Q> const& y, unsigned int Depth)
  62. {
  63. return pow(pow(abs(y.x - x.x), T(Depth)) + pow(abs(y.y - x.y), T(Depth)) + pow(abs(y.z - x.z), T(Depth)), T(1) / T(Depth));
  64. }
  65. template<typename T, qualifier Q>
  66. GLM_FUNC_QUALIFIER T lxNorm(vec<3, T, Q> const& v, unsigned int Depth)
  67. {
  68. return pow(pow(abs(v.x), T(Depth)) + pow(abs(v.y), T(Depth)) + pow(abs(v.z), T(Depth)), T(1) / T(Depth));
  69. }
  70. template<typename T, qualifier Q>
  71. GLM_FUNC_QUALIFIER T lMaxNorm(vec<3, T, Q> const& a, vec<3, T, Q> const& b)
  72. {
  73. return compMax(abs(b - a));
  74. }
  75. template<typename T, qualifier Q>
  76. GLM_FUNC_QUALIFIER T lMaxNorm(vec<3, T, Q> const& v)
  77. {
  78. return compMax(abs(v));
  79. }
  80. }//namespace glm