matrix: add elementwise sum function overload

This commit is contained in:
Danny Robson 2016-08-15 18:45:25 +10:00
parent 2daa70bae0
commit 1f86925237
3 changed files with 14 additions and 0 deletions

View File

@ -103,6 +103,11 @@ namespace util {
matrix<S,T>
abs (const matrix<S,T>&);
template <size_t S, typename T>
constexpr
T
sum (const matrix<S,T>&);
template <typename T> using matrix3 = matrix<3,T>;
template <typename T> using matrix4 = matrix<4,T>;

View File

@ -118,3 +118,10 @@ util::abs (const util::matrix<S,T> &src)
///////////////////////////////////////////////////////////////////////////////
template <size_t S, typename T>
constexpr
T
util::sum (const util::matrix<S,T> &src)
{
return sum (std::cbegin (src), std::cend (src));
}

View File

@ -11,6 +11,8 @@ main (void)
{
util::TAP::logger tap;
tap.expect_eq (sum (util::matrix4f::IDENTITY), 4.f, "element summation");
{
// Identity matrix-vector multiplication
auto v = util::vector4f { 1.f, 2.f, 3.f, 4.f };