diff --git a/source/blender/blenlib/BLI_bounds.hh b/source/blender/blenlib/BLI_bounds.hh index 66f94775f68..05e18805dd1 100644 --- a/source/blender/blenlib/BLI_bounds.hh +++ b/source/blender/blenlib/BLI_bounds.hh @@ -18,61 +18,6 @@ namespace blender::bounds { -/** - * Find the smallest and largest values element-wise in the span. - */ -template [[nodiscard]] inline std::optional> min_max(Span values) -{ - if (values.is_empty()) { - return std::nullopt; - } - const Bounds init{values.first(), values.first()}; - return threading::parallel_reduce( - values.index_range(), - 1024, - init, - [&](IndexRange range, const Bounds &init) { - Bounds result = init; - for (const int i : range) { - math::min_max(values[i], result.min, result.max); - } - return result; - }, - [](const Bounds &a, const Bounds &b) { - return Bounds{math::min(a.min, b.min), math::max(a.max, b.max)}; - }); -} - -/** - * Find the smallest and largest values element-wise in the span, adding the radius to each element - * first. The template type T is expected to have an addition operator implemented with RadiusT. - */ -template -[[nodiscard]] inline std::optional> min_max_with_radii(Span values, - Span radii) -{ - BLI_assert(values.size() == radii.size()); - if (values.is_empty()) { - return std::nullopt; - } - const Bounds init{values.first(), values.first()}; - return threading::parallel_reduce( - values.index_range(), - 1024, - init, - [&](IndexRange range, const Bounds &init) { - Bounds result = init; - for (const int i : range) { - result.min = math::min(values[i] - radii[i], result.min); - result.max = math::max(values[i] + radii[i], result.max); - } - return result; - }, - [](const Bounds &a, const Bounds &b) { - return Bounds{math::min(a.min, b.min), math::max(a.max, b.max)}; - }); -} - template [[nodiscard]] inline Bounds merge(const Bounds &a, const Bounds &b) { return {math::min(a.min, b.min), math::max(a.max, b.max)}; @@ -94,4 +39,55 @@ template return std::nullopt; } +/** + * Find the smallest and largest values element-wise in the span. + */ +template [[nodiscard]] inline std::optional> min_max(const Span values) +{ + if (values.is_empty()) { + return std::nullopt; + } + const Bounds init{values.first(), values.first()}; + return threading::parallel_reduce( + values.index_range(), + 1024, + init, + [&](const IndexRange range, const Bounds &init) { + Bounds result = init; + for (const int i : range) { + math::min_max(values[i], result.min, result.max); + } + return result; + }, + [](const Bounds &a, const Bounds &b) { return merge(a, b); }); +} + +/** + * Find the smallest and largest values element-wise in the span, adding the radius to each element + * first. The template type T is expected to have an addition operator implemented with RadiusT. + */ +template +[[nodiscard]] inline std::optional> min_max_with_radii(const Span values, + const Span radii) +{ + BLI_assert(values.size() == radii.size()); + if (values.is_empty()) { + return std::nullopt; + } + const Bounds init{values.first(), values.first()}; + return threading::parallel_reduce( + values.index_range(), + 1024, + init, + [&](const IndexRange range, const Bounds &init) { + Bounds result = init; + for (const int i : range) { + result.min = math::min(values[i] - radii[i], result.min); + result.max = math::max(values[i] + radii[i], result.max); + } + return result; + }, + [](const Bounds &a, const Bounds &b) { return merge(a, b); }); +} + } // namespace blender::bounds