diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-06-07 16:28:34 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-06-07 19:31:06 +0300 |
commit | ec493d79fa7d8f6885d31cae8f3d0cac47604a3c (patch) | |
tree | 26f3319aebab1ac0326aa584e37d1ce842543d1d /source/blender/blenlib/BLI_math_vector.hh | |
parent | 7974d2bff6f363b75c8317cf1dad3e943fd85df6 (diff) |
BLI: Math: Add `math::divide_ceil` and `math::ceil_to_multiple`
`math::divide_ceil` is just the vector implementation of `divide_ceil_u`.
`math::ceil_to_multiple` is similar but finaly multiply by the divisor.
It is handy to handle tile buffers resolutions.
Diffstat (limited to 'source/blender/blenlib/BLI_math_vector.hh')
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.hh | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.hh b/source/blender/blenlib/BLI_math_vector.hh index 7983bbccb35..e5273d050a6 100644 --- a/source/blender/blenlib/BLI_math_vector.hh +++ b/source/blender/blenlib/BLI_math_vector.hh @@ -159,6 +159,26 @@ inline T safe_mod(const vec_base<T, Size> &a, const T &b) return result; } +template<typename T, int Size, BLI_ENABLE_IF((is_math_integral_type<T>))> +inline vec_base<T, Size> ceil_to_multiple(const vec_base<T, Size> &a, const vec_base<T, Size> &b) +{ + vec_base<T, Size> result; + for (int i = 0; i < Size; i++) { + result[i] = ((a[i] + b[i] - 1) / b[i]) * b[i]; + } + return result; +} + +template<typename T, int Size, BLI_ENABLE_IF((is_math_integral_type<T>))> +inline vec_base<T, Size> divide_ceil(const vec_base<T, Size> &a, const vec_base<T, Size> &b) +{ + vec_base<T, Size> result; + for (int i = 0; i < Size; i++) { + result[i] = (a[i] + b[i] - 1) / b[i]; + } + return result; +} + template<typename T, int Size> inline void min_max(const vec_base<T, Size> &vector, vec_base<T, Size> &min, |