Get the latest Blender, older versions, or experimental builds.
Stay up-to-date with the new features in the latest Blender releases.
Access production assets and knowledge from the open movies.
Documentation on the usage and features in Blender.
Latest development updates, by Blender developers.
Guidelines, release notes and development docs.
A platform to collect and share results of the Blender Benchmark.
The yearly event that brings the community together.
Support core development with a monthly contribution.
Perform a single donation with more payment options available.
Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.
/* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
/** \file
* \ingroup bli
*
* Generic algorithms for finding the largest and smallest elements in a span.
*/
#include <optional>
#include "BLI_bounds_types.hh"
#include "BLI_math_vector.hh"
#include "BLI_task.hh"
namespace blender::bounds {
/**
* Find the smallest and largest values element-wise in the span.
template<typename T> static std::optional<Bounds<T>> min_max(Span<T> values)
{
if (values.is_empty()) {
return std::nullopt;
}
const Bounds<T> init{values.first(), values.first()};
return threading::parallel_reduce(
values.index_range(),
1024,
init,
[&](IndexRange range, const Bounds<T> &init) {
Bounds<T> result = init;
for (const int i : range) {
math::min_max(values[i], result.min, result.max);
return result;
},
[](const Bounds<T> &a, const Bounds<T> &b) {
return Bounds<T>{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<typename T, typename RadiusT>
static std::optional<Bounds<T>> min_max_with_radii(Span<T> values, Span<RadiusT> radii)
BLI_assert(values.size() == radii.size());
result.min = math::min(values[i] - radii[i], result.min);
result.max = math::max(values[i] + radii[i], result.max);
} // namespace blender::bounds