Fix: Incorrect curves and pointcloud bounding boxes

The generic bounds utility used an incorrect initial value. The value
cannot be zero-initialized, because that breaks the case where all
values are greater than zero.
This commit is contained in:
Hans Goudey
2022-06-08 18:40:08 +02:00
parent a3e7280bd8
commit fe4e646405
2 changed files with 11 additions and 2 deletions

View File

@@ -28,10 +28,11 @@ template<typename T> static std::optional<MinMaxResult<T>> min_max(Span<T> value
if (values.is_empty()) {
return std::nullopt;
}
const MinMaxResult<T> init{values.first(), values.first()};
return threading::parallel_reduce(
values.index_range(),
1024,
MinMaxResult<T>(),
init,
[&](IndexRange range, const MinMaxResult<T> &init) {
MinMaxResult<T> result = init;
for (const int i : range) {
@@ -55,10 +56,11 @@ static std::optional<MinMaxResult<T>> min_max_with_radii(Span<T> values, Span<Ra
if (values.is_empty()) {
return std::nullopt;
}
const MinMaxResult<T> init{values.first(), values.first()};
return threading::parallel_reduce(
values.index_range(),
1024,
MinMaxResult<T>(),
init,
[&](IndexRange range, const MinMaxResult<T> &init) {
MinMaxResult<T> result = init;
for (const int i : range) {

View File

@@ -33,6 +33,13 @@ TEST(bounds, MinMaxFloat)
EXPECT_EQ(result->max, 3.0f);
}
TEST(bounds, MinGreaterThanZero)
{
Array<float> data = {1.5f, 3.0f, 1.1f, 100.0f};
auto result = bounds::min_max(data.as_span());
EXPECT_GT(result->min, 1.0f);
}
TEST(bounds, MinMaxRadii)
{
Array<int2> data = {int2(0, 1), int2(3, -1), int2(0, -2), int2(-1, 1)};