coord/ops: add std::{cos,sin} overloads for coords

This commit is contained in:
Danny Robson 2018-03-13 14:36:38 +11:00
parent 3e9e9bff5a
commit 17816021b9
3 changed files with 29 additions and 14 deletions

View File

@ -1404,11 +1404,11 @@ namespace std {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#include <functional>
#include "../hash.hpp" #include "../hash.hpp"
namespace std { namespace std {
//-------------------------------------------------------------------------
template < template <
std::size_t S, std::size_t S,
typename T, typename T,
@ -1427,6 +1427,8 @@ namespace std {
} }
}; };
//-------------------------------------------------------------------------
template < template <
typename CoordT, typename CoordT,
typename = std::enable_if_t< typename = std::enable_if_t<
@ -1435,16 +1437,20 @@ namespace std {
> >
auto cos (CoordT val) auto cos (CoordT val)
{ {
CoordT out; return ::util::apply<CoordT> (::util::cos<typename CoordT::value_type>, val);
}
std::transform (
std::begin (val),
std::end (val),
std::begin (out),
[] (auto i) { return ::std::cos (i); }
);
return out; //-------------------------------------------------------------------------
template <
typename CoordT,
typename = std::enable_if_t<
::util::is_coord_v<CoordT>, void
>
>
auto sin (CoordT val)
{
return ::util::apply<CoordT> (::util::sin<typename CoordT::value_type>, val);
} }
}; };

View File

@ -508,6 +508,16 @@ namespace util {
} }
//-------------------------------------------------------------------------
// thin wrappers around std trig identities.
//
// we have these because it's a little easier to qualify templates when
// passing function objects as compared to explicitly disambiguating raw
// functions (ie, with casts or typedefs).
template <typename ValueT> ValueT cos (ValueT theta) { return ::std::cos (theta); }
template <typename ValueT> ValueT sin (ValueT theta) { return ::std::sin (theta); }
template <typename ValueT> ValueT tan (ValueT theta) { return ::std::tan (theta); }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// combinatorics // combinatorics

View File

@ -19,8 +19,7 @@
#include "debug.hpp" #include "debug.hpp"
#include "vector.hpp" #include "vector.hpp"
#include "coord/ops.hpp"
#include <cmath>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -50,8 +49,8 @@ quaternion<T>::from_euler (vector<3,T> angles)
{ {
auto half = angles / 2; auto half = angles / 2;
auto c = cos (half); auto c = std::cos (half);
auto s = sin (half); auto s = std::sin (half);
return { return {
c.x * c.y * c.z - s.x * s.y * s.z, c.x * c.y * c.z - s.x * s.y * s.z,