coord: use std::array for data storage

This allows us to more easily forward array dimensions with some level
of expectation that the data will be packed.
This commit is contained in:
Danny Robson 2019-01-31 13:46:13 +11:00
parent 7511580de7
commit 4c29123d4d
2 changed files with 40 additions and 45 deletions

View File

@ -3,14 +3,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
* *
* Copyright 2012-2017 Danny Robson <danny@nerdcruft.net> * Copyright 2012-2019 Danny Robson <danny@nerdcruft.net>
*/ */
#ifndef __UTIL_COORDS_OPS #pragma once
#define __UTIL_COORDS_OPS
#include "fwd.hpp" #include "fwd.hpp"
#include "traits.hpp" #include "traits.hpp"
#include "../array/varray.hpp"
// we specifically rely on vector<bool> to compute a few logical operations // we specifically rely on vector<bool> to compute a few logical operations
#include "../vector.hpp" #include "../vector.hpp"
@ -676,14 +676,12 @@ namespace cruft {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
template < template <std::size_t S, typename T>
std::size_t S, constexpr T
typename T dot (
> cruft::varray<S,T> const &a,
constexpr cruft::varray<S,T> const &b
T ) {
dot (const T (&a)[S], const T (&b)[S])
{
T sum = 0; T sum = 0;
for (std::size_t i = 0; i < S; ++i) for (std::size_t i = 0; i < S; ++i)
sum += a[i] * b[i]; sum += a[i] * b[i];
@ -719,7 +717,7 @@ namespace cruft {
constexpr auto constexpr auto
dot (A a, B b) dot (A a, B b)
{ {
return dot (a.data, b.data); return dot (varray (a.data), varray (b.data));
} }
@ -1552,6 +1550,3 @@ namespace std {
return ::cruft::invoke<CoordT> (::cruft::sin<typename CoordT::value_type>, val); return ::cruft::invoke<CoordT> (::cruft::sin<typename CoordT::value_type>, val);
} }
}; };
#endif

View File

@ -63,7 +63,7 @@ namespace cruft::coord { \
struct { \ struct { \
T __VA_ARGS__; \ T __VA_ARGS__; \
}; \ }; \
T data[VA_ARGS_COUNT(__VA_ARGS__)]; \ std::array<T,VA_ARGS_COUNT(__VA_ARGS__)> data; \
}; \ }; \
}; \ }; \
} }
@ -80,7 +80,7 @@ struct cruft::coord::store< \
> \ > \
> { \ > { \
union { \ union { \
T data[VA_ARGS_COUNT(__VA_ARGS__)]; \ std::array<T,VA_ARGS_COUNT(__VA_ARGS__)> data; \
struct { T __VA_ARGS__; }; \ struct { T __VA_ARGS__; }; \
}; \ }; \
}; };
@ -104,7 +104,7 @@ DEFINE_STORE(vector, x, y, z, w)
namespace cruft::coord { namespace cruft::coord {
template <size_t S, typename T, typename SelfT> template <size_t S, typename T, typename SelfT>
struct store { struct store {
T data[S]; std::array<T,S> data;
}; };
} }