coord/ops: generalise vectors hypot function

This commit is contained in:
Danny Robson 2016-09-23 13:27:44 +10:00
parent 70689fd449
commit 109d47e971
3 changed files with 17 additions and 16 deletions

View File

@ -547,6 +547,23 @@ namespace util {
return k;
}
///////////////////////////////////////////////////////////////////////////
// root of sum of squares
template <
size_t S,
typename T,
template <size_t,typename> class K,
typename = std::enable_if_t<
is_coord_v<K<S,T>>, void
>
>
constexpr
T
hypot (K<S,T> k)
{
return std::sqrt (sum (k * k));
}
///////////////////////////////////////////////////////////////////////////
template <

View File

@ -50,12 +50,6 @@ namespace util {
template <typename T> vector<2,T> to_euler (vector<3,T>);
template <typename T> vector<3,T> from_euler (vector<2,T>);
// root of sum of squares
template <size_t S, typename T>
constexpr
T
hypot (util::vector<S,T>);
// output and serialisation operators
template <size_t S, typename T>
const json::tree::node&

View File

@ -32,13 +32,3 @@ util::vector<S,T>::homog (void) const
static_assert (D > S, "reducing size loses data");
return (*this).template redim<D> (0.f);
}
///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
constexpr
T
util::hypot (util::vector<S,T> v)
{
return std::sqrt (sum (v * v));
}