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:
parent
7511580de7
commit
4c29123d4d
@ -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
|
|
||||||
|
@ -51,38 +51,38 @@ namespace cruft::coord::detail {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// defines the named member variables that a coordinate type is composed of
|
// defines the named member variables that a coordinate type is composed of
|
||||||
#define DEFINE_COORD_STORE(TAG,...) \
|
#define DEFINE_COORD_STORE(TAG,...) \
|
||||||
namespace cruft::coord { \
|
namespace cruft::coord { \
|
||||||
template <typename T> \
|
template <typename T> \
|
||||||
struct store< \
|
struct store< \
|
||||||
VA_ARGS_COUNT(__VA_ARGS__), \
|
VA_ARGS_COUNT(__VA_ARGS__), \
|
||||||
T, \
|
T, \
|
||||||
TAG \
|
TAG \
|
||||||
> { \
|
> { \
|
||||||
union { \
|
union { \
|
||||||
struct { \
|
struct { \
|
||||||
T __VA_ARGS__; \
|
T __VA_ARGS__; \
|
||||||
}; \
|
}; \
|
||||||
T data[VA_ARGS_COUNT(__VA_ARGS__)]; \
|
std::array<T,VA_ARGS_COUNT(__VA_ARGS__)> data; \
|
||||||
}; \
|
}; \
|
||||||
}; \
|
}; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define DEFINE_STORE(KLASS,...) \
|
#define DEFINE_STORE(KLASS,...) \
|
||||||
template <typename T> \
|
template <typename T> \
|
||||||
struct cruft::coord::store< \
|
struct cruft::coord::store< \
|
||||||
VA_ARGS_COUNT(__VA_ARGS__), \
|
VA_ARGS_COUNT(__VA_ARGS__), \
|
||||||
T, \
|
T, \
|
||||||
::cruft::KLASS< \
|
::cruft::KLASS< \
|
||||||
VA_ARGS_COUNT(__VA_ARGS__), \
|
VA_ARGS_COUNT(__VA_ARGS__), \
|
||||||
T \
|
T \
|
||||||
> \
|
> \
|
||||||
> { \
|
> { \
|
||||||
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__; }; \
|
||||||
}; \
|
}; \
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_STORE(extent,w)
|
DEFINE_STORE(extent,w)
|
||||||
@ -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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user