Skip to content

Commit

Permalink
Fixed missing vec1 overload to length2 and distance2 functions g-truc…
Browse files Browse the repository at this point in the history
  • Loading branch information
Groovounet committed Jun 4, 2016
1 parent 0699896 commit 7aca47b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 82 deletions.
31 changes: 9 additions & 22 deletions glm/gtx/norm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,18 @@ namespace glm
/// @addtogroup gtx_norm
/// @{

//! Returns the squared length of x.
//! From GLM_GTX_norm extension.
template <typename T>
/// Returns the squared length of x.
/// From GLM_GTX_norm extension.
template <typename T, precision P, template <typename, precision> class vecType>
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).
//! From GLM_GTX_norm extension.
template <typename T>
/// Returns the squared distance between p0 and p1, i.e., length2(p0 - p1).
/// From GLM_GTX_norm extension.
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL T distance2(
T const & p0,
T 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);
vecType<T, P> const & p0,
vecType<T, P> const & p1);

//! Returns the L1 norm between x and y.
//! From GLM_GTX_norm extension.
Expand Down
83 changes: 23 additions & 60 deletions glm/gtx/norm.inl
Original file line number Diff line number Diff line change
@@ -1,81 +1,44 @@
/// @ref gtx_norm
/// @file glm/gtx/norm.inl

namespace glm
namespace glm{
namespace detail
{
template <typename T>
GLM_FUNC_QUALIFIER T length2
(
T const & x
)
template <template <typename, precision> class vecType, typename T, precision P, bool Aligned>
struct compute_length2
{
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>
GLM_FUNC_QUALIFIER T length2
(
tvec2<T, P> const & x
)
template <typename genType>
GLM_FUNC_QUALIFIER genType length2(genType x)
{
return dot(x, x);
}

template <typename T, precision P>
GLM_FUNC_QUALIFIER T length2
(
tvec3<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
(
tvec4<T, P> const & x
)
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER T length2(vecType<T, P> const & v)
{
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>
GLM_FUNC_QUALIFIER T distance2
(
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_FUNC_QUALIFIER T distance2(T p0, T p1)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'distance2' accepts only floating-point inputs");
return length2(p1 - p0);
}

template <typename T, precision P>
GLM_FUNC_QUALIFIER T distance2
(
tvec4<T, P> const & p0,
tvec4<T, P> const & p1
)
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER T distance2(vecType<T, P> const & p0, vecType<T, P> const & p1)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'distance2' accepts only floating-point inputs");
return length2(p1 - p0);
}

Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
- Fixed long long warnings when using C++98 on GCC and Clang #482
- Fixed sign with signed integer function on non-x86 architecture
- Fixed strict aliaing warnings #473
- Fixed missing vec1 overload to length2 and distance2 functions #431
##### Deprecation:
- Removed GLM_FORCE_SIZE_FUNC define
Expand Down

0 comments on commit 7aca47b

Please sign in to comment.