Fixed missing vec1 overload to length2 and distance2 functions #431

master
Christophe Riccio ago%!(EXTRA string=9 years)
parent 39e63661a6
commit bfb64e7657
  1. 31
      glm/gtx/norm.hpp
  2. 83
      glm/gtx/norm.inl
  3. 1
      readme.md

@ -55,31 +55,18 @@ namespace glm
/// @addtogroup gtx_norm /// @addtogroup gtx_norm
/// @{ /// @{
//! Returns the squared length of x. /// Returns the squared length of x.
//! From GLM_GTX_norm extension. /// From GLM_GTX_norm extension.
template <typename T> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL T length2( GLM_FUNC_DECL T length2(
T const & x); vecType<T, P> const & x);
//! Returns the squared length of x.
//! From GLM_GTX_norm extension.
template <typename genType>
GLM_FUNC_DECL typename genType::value_type length2(
genType const & x);
//! Returns the squared distance between p0 and p1, i.e., length2(p0 - p1). /// Returns the squared distance between p0 and p1, i.e., length2(p0 - p1).
//! From GLM_GTX_norm extension. /// From GLM_GTX_norm extension.
template <typename T> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL T distance2( GLM_FUNC_DECL T distance2(
T const & p0, vecType<T, P> const & p0,
T const & p1); vecType<T, P> const & p1);
//! Returns the squared distance between p0 and p1, i.e., length2(p0 - p1).
//! From GLM_GTX_norm extension.
template <typename genType>
GLM_FUNC_DECL typename genType::value_type distance2(
genType const & p0,
genType const & p1);
//! Returns the L1 norm between x and y. //! Returns the L1 norm between x and y.
//! From GLM_GTX_norm extension. //! From GLM_GTX_norm extension.

@ -30,81 +30,44 @@
/// @author Christophe Riccio /// @author Christophe Riccio
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
namespace glm namespace glm{
namespace detail
{ {
template <typename T> template <template <typename, precision> class vecType, typename T, precision P, bool Aligned>
GLM_FUNC_QUALIFIER T length2 struct compute_length2
(
T const & x
)
{ {
return x * x; GLM_FUNC_QUALIFIER static T call(vecType<T, P> const & v)
} {
return dot(v, v);
}
};
}//namespace detail
template <typename T, precision P> template <typename genType>
GLM_FUNC_QUALIFIER T length2 GLM_FUNC_QUALIFIER genType length2(genType x)
(
tvec2<T, P> const & x
)
{ {
return dot(x, x); GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'length2' accepts only floating-point inputs");
} return x * x;
template <typename T, precision P>
GLM_FUNC_QUALIFIER T length2
(
tvec3<T, P> const & x
)
{
return dot(x, x);
} }
template <typename T, precision P> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER T length2 GLM_FUNC_QUALIFIER T length2(vecType<T, P> const & v)
(
tvec4<T, P> const & x
)
{ {
return dot(x, x); GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'length2' accepts only floating-point inputs");
return detail::compute_length2<vecType, T, P, detail::is_aligned<P>::value>::call(v);
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER T distance2 GLM_FUNC_QUALIFIER T distance2(T p0, T p1)
(
T const & p0,
T const & p1
)
{
return length2(p1 - p0);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER T distance2
(
tvec2<T, P> const & p0,
tvec2<T, P> const & p1
)
{
return length2(p1 - p0);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER T distance2
(
tvec3<T, P> const & p0,
tvec3<T, P> const & p1
)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'distance2' accepts only floating-point inputs");
return length2(p1 - p0); return length2(p1 - p0);
} }
template <typename T, precision P> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER T distance2 GLM_FUNC_QUALIFIER T distance2(vecType<T, P> const & p0, vecType<T, P> const & p1)
(
tvec4<T, P> const & p0,
tvec4<T, P> const & p1
)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'distance2' accepts only floating-point inputs");
return length2(p1 - p0); return length2(p1 - p0);
} }

@ -57,6 +57,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
##### Fixes: ##### Fixes:
- Fixed STL for C++11 detection on ICC #510 - Fixed STL for C++11 detection on ICC #510
- Fixed missing vec1 overload to length2 and distance2 functions #431
#### [GLM 0.9.7.5](https://github.com/g-truc/glm/releases/tag/0.9.7.5) - 2016-05-24 #### [GLM 0.9.7.5](https://github.com/g-truc/glm/releases/tag/0.9.7.5) - 2016-05-24
##### Improvements: ##### Improvements:

Loading…
Cancel
Save