BLI: Math: Allow vector of 1 component

This commit is contained in:
Clément Foucault
2023-09-03 16:34:50 +02:00
parent 760aa0e917
commit 8fe1ec100b
@@ -83,6 +83,9 @@ template<typename T, int Size> struct VecBase : public vec_struct_base<T, Size>
BLI_STATIC_ASSERT(alignof(T) <= sizeof(T),
"VecBase is not compatible with aligned type for now.");
/* Workaround issue with template BLI_ENABLE_IF((Size == 2)) not working. */
#define BLI_ENABLE_IF_VEC(_size, _test) int S = _size, BLI_ENABLE_IF((S _test))
static constexpr int type_length = Size;
using base_type = T;
@@ -90,7 +93,7 @@ template<typename T, int Size> struct VecBase : public vec_struct_base<T, Size>
VecBase() = default;
explicit VecBase(T value)
template<BLI_ENABLE_IF_VEC(Size, > 1)> explicit VecBase(T value)
{
for (int i = 0; i < Size; i++) {
(*this)[i] = value;
@@ -102,8 +105,10 @@ template<typename T, int Size> struct VecBase : public vec_struct_base<T, Size>
{
}
/* Workaround issue with template BLI_ENABLE_IF((Size == 2)) not working. */
#define BLI_ENABLE_IF_VEC(_size, _test) int S = _size, BLI_ENABLE_IF((S _test))
template<BLI_ENABLE_IF_VEC(Size, == 1)> VecBase(T _x)
{
(*this)[0] = _x;
}
template<BLI_ENABLE_IF_VEC(Size, == 2)> VecBase(T _x, T _y)
{
@@ -667,6 +672,7 @@ using ushort2 = VecBase<uint16_t, 2>;
using ushort3 = blender::VecBase<uint16_t, 3>;
using ushort4 = blender::VecBase<uint16_t, 4>;
using float1 = VecBase<float, 1>;
using float2 = VecBase<float, 2>;
using float3 = VecBase<float, 3>;
using float4 = VecBase<float, 4>;