From fe4e646405eb3a8e38617411a2f9b1b8f6b8a8cb Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 8 Jun 2022 18:40:08 +0200 Subject: 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. --- source/blender/blenlib/BLI_bounds.hh | 6 ++++-- source/blender/blenlib/tests/BLI_bounds_test.cc | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/BLI_bounds.hh b/source/blender/blenlib/BLI_bounds.hh index d20382ed500..f5a18a0ea48 100644 --- a/source/blender/blenlib/BLI_bounds.hh +++ b/source/blender/blenlib/BLI_bounds.hh @@ -28,10 +28,11 @@ template static std::optional> min_max(Span value if (values.is_empty()) { return std::nullopt; } + const MinMaxResult init{values.first(), values.first()}; return threading::parallel_reduce( values.index_range(), 1024, - MinMaxResult(), + init, [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { @@ -55,10 +56,11 @@ static std::optional> min_max_with_radii(Span values, Span init{values.first(), values.first()}; return threading::parallel_reduce( values.index_range(), 1024, - MinMaxResult(), + init, [&](IndexRange range, const MinMaxResult &init) { MinMaxResult result = init; for (const int i : range) { diff --git a/source/blender/blenlib/tests/BLI_bounds_test.cc b/source/blender/blenlib/tests/BLI_bounds_test.cc index 9c123d4705c..5aa4e710e90 100644 --- a/source/blender/blenlib/tests/BLI_bounds_test.cc +++ b/source/blender/blenlib/tests/BLI_bounds_test.cc @@ -33,6 +33,13 @@ TEST(bounds, MinMaxFloat) EXPECT_EQ(result->max, 3.0f); } +TEST(bounds, MinGreaterThanZero) +{ + Array 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 data = {int2(0, 1), int2(3, -1), int2(0, -2), int2(-1, 1)}; -- cgit v1.2.3