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
* 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
#define __UTIL_COORDS_OPS
#pragma once
#include "fwd.hpp"
#include "traits.hpp"
#include "../array/varray.hpp"
// we specifically rely on vector<bool> to compute a few logical operations
#include "../vector.hpp"
@ -676,14 +676,12 @@ namespace cruft {
///////////////////////////////////////////////////////////////////////////
template <
std::size_t S,
typename T
>
constexpr
T
dot (const T (&a)[S], const T (&b)[S])
{
template <std::size_t S, typename T>
constexpr T
dot (
cruft::varray<S,T> const &a,
cruft::varray<S,T> const &b
) {
T sum = 0;
for (std::size_t i = 0; i < S; ++i)
sum += a[i] * b[i];
@ -719,7 +717,7 @@ namespace cruft {
constexpr auto
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);
}
};
#endif

View File

@ -51,38 +51,38 @@ namespace cruft::coord::detail {
///////////////////////////////////////////////////////////////////////////////
// defines the named member variables that a coordinate type is composed of
#define DEFINE_COORD_STORE(TAG,...) \
namespace cruft::coord { \
template <typename T> \
struct store< \
VA_ARGS_COUNT(__VA_ARGS__), \
T, \
TAG \
> { \
union { \
struct { \
T __VA_ARGS__; \
}; \
T data[VA_ARGS_COUNT(__VA_ARGS__)]; \
}; \
}; \
#define DEFINE_COORD_STORE(TAG,...) \
namespace cruft::coord { \
template <typename T> \
struct store< \
VA_ARGS_COUNT(__VA_ARGS__), \
T, \
TAG \
> { \
union { \
struct { \
T __VA_ARGS__; \
}; \
std::array<T,VA_ARGS_COUNT(__VA_ARGS__)> data; \
}; \
}; \
}
#define DEFINE_STORE(KLASS,...) \
template <typename T> \
struct cruft::coord::store< \
VA_ARGS_COUNT(__VA_ARGS__), \
T, \
::cruft::KLASS< \
VA_ARGS_COUNT(__VA_ARGS__), \
T \
> \
> { \
union { \
T data[VA_ARGS_COUNT(__VA_ARGS__)]; \
struct { T __VA_ARGS__; }; \
}; \
#define DEFINE_STORE(KLASS,...) \
template <typename T> \
struct cruft::coord::store< \
VA_ARGS_COUNT(__VA_ARGS__), \
T, \
::cruft::KLASS< \
VA_ARGS_COUNT(__VA_ARGS__), \
T \
> \
> { \
union { \
std::array<T,VA_ARGS_COUNT(__VA_ARGS__)> data; \
struct { T __VA_ARGS__; }; \
}; \
};
DEFINE_STORE(extent,w)
@ -104,7 +104,7 @@ DEFINE_STORE(vector, x, y, z, w)
namespace cruft::coord {
template <size_t S, typename T, typename SelfT>
struct store {
T data[S];
std::array<T,S> data;
};
}