BLI: Math: Add xy() and xyz() swizzle functions
Thoses are added for better component masking syntax. This avoids the harder to read `float2(my_vec4)`. This is not meant to be fully usable swizzling support but could be extended in the future.
This commit is contained in:
@@ -174,6 +174,18 @@ template<typename T, int Size> struct VecBase : public vec_struct_base<T, Size>
|
||||
}
|
||||
}
|
||||
|
||||
/** Swizzling. */
|
||||
|
||||
template<BLI_ENABLE_IF_VEC(Size, >= 3)> VecBase<T, 2> xy() const
|
||||
{
|
||||
return *reinterpret_cast<VecBase<T, 2> *>(&x);
|
||||
}
|
||||
|
||||
template<BLI_ENABLE_IF_VEC(Size, >= 4)> VecBase<T, 3> xyz() const
|
||||
{
|
||||
return *reinterpret_cast<VecBase<T, 3> *>(&x);
|
||||
}
|
||||
|
||||
#undef BLI_ENABLE_IF_VEC
|
||||
|
||||
/** Conversion from pointers (from C-style vectors). */
|
||||
|
||||
Reference in New Issue
Block a user