From 3b6733c5048561d3fe0cd7cc1e8a24041d8207f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Mon, 10 Jan 2022 20:11:54 +0100 Subject: BLI_math_vec_types: Add bit shift operators --- source/blender/blenlib/BLI_math_vec_types.hh | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/source/blender/blenlib/BLI_math_vec_types.hh b/source/blender/blenlib/BLI_math_vec_types.hh index ae8cb0056bb..2e0b17d8bc4 100644 --- a/source/blender/blenlib/BLI_math_vec_types.hh +++ b/source/blender/blenlib/BLI_math_vec_types.hh @@ -444,6 +444,48 @@ template struct vec_base : public vec_struct_base BLI_VEC_OP_IMPL(ret, i, ret[i] = ~a[i]); } + /** Bit-shift operators. */ + + BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b[i]); + } + + BLI_INT_OP(T) friend vec_base operator<<(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] << b); + } + + BLI_INT_OP(T) vec_base &operator<<=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b); + } + + BLI_INT_OP(T) vec_base &operator<<=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] <<= b[i]); + } + + BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, const vec_base &b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b[i]); + } + + BLI_INT_OP(T) friend vec_base operator>>(const vec_base &a, T b) + { + BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] >> b); + } + + BLI_INT_OP(T) vec_base &operator>>=(T b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b); + } + + BLI_INT_OP(T) vec_base &operator>>=(const vec_base &b) + { + BLI_VEC_OP_IMPL_SELF(i, (*this)[i] >>= b[i]); + } + /** Modulo operators. */ BLI_INT_OP(T) friend vec_base operator%(const vec_base &a, const vec_base &b) -- cgit v1.2.3