From ec493d79fa7d8f6885d31cae8f3d0cac47604a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Tue, 7 Jun 2022 15:28:34 +0200 Subject: 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. --- source/blender/blenlib/BLI_math_vector.hh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 &a, const T &b) return result; } +template))> +inline vec_base ceil_to_multiple(const vec_base &a, const vec_base &b) +{ + vec_base result; + for (int i = 0; i < Size; i++) { + result[i] = ((a[i] + b[i] - 1) / b[i]) * b[i]; + } + return result; +} + +template))> +inline vec_base divide_ceil(const vec_base &a, const vec_base &b) +{ + vec_base result; + for (int i = 0; i < Size; i++) { + result[i] = (a[i] + b[i] - 1) / b[i]; + } + return result; +} + template inline void min_max(const vec_base &vector, vec_base &min, -- cgit v1.2.3