Blender  V3.3
BLI_bounds_test.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0 */
2 
3 #include "testing/testing.h"
4 
5 #include "BLI_math_base.hh"
6 
7 #include "BLI_array.hh"
8 #include "BLI_bounds.hh"
9 
10 namespace blender::tests {
11 
12 TEST(bounds, Empty)
13 {
14  Span<float2> empty_span{};
15  EXPECT_TRUE(empty_span.is_empty());
16  auto result = bounds::min_max(empty_span);
17  EXPECT_EQ(result, std::nullopt);
18 }
19 
20 TEST(bounds, MinMax)
21 {
22  Array<float2> data = {float2(0, 1), float2(3, -1), float2(0, -2), float2(-1, 1)};
23  auto result = bounds::min_max(data.as_span());
24  EXPECT_EQ(result->min, float2(-1, -2));
25  EXPECT_EQ(result->max, float2(3, 1));
26 }
27 
28 TEST(bounds, MinMaxFloat)
29 {
30  Array<float> data = {1.0f, 3.0f, 0.0f, -1.0f};
31  auto result = bounds::min_max(data.as_span());
32  EXPECT_EQ(result->min, -1.0f);
33  EXPECT_EQ(result->max, 3.0f);
34 }
35 
36 TEST(bounds, MinGreaterThanZero)
37 {
38  Array<float> data = {1.5f, 3.0f, 1.1f, 100.0f};
39  auto result = bounds::min_max(data.as_span());
40  EXPECT_GT(result->min, 1.0f);
41 }
42 
43 TEST(bounds, MinMaxRadii)
44 {
45  Array<int2> data = {int2(0, 1), int2(3, -1), int2(0, -2), int2(-1, 1)};
46  Array<int> radii = {5, 1, 1, 4};
47  auto result = bounds::min_max_with_radii(data.as_span(), radii.as_span());
48  EXPECT_EQ(result->min, int2(-5, -4));
49  EXPECT_EQ(result->max, int2(5, 6));
50 }
51 
52 TEST(bounds, Large)
53 {
54  Array<int2> data(10000);
55  for (const int64_t i : data.index_range()) {
56  data[i] = int2(i, i);
57  }
58 
59  auto result = bounds::min_max(data.as_span());
60  EXPECT_EQ(result->min, int2(0, 0));
61  EXPECT_EQ(result->max, int2(9999, 9999));
62 }
63 
64 } // namespace blender::tests
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition: btDbvt.cpp:299
static std::optional< MinMaxResult< T > > min_max(Span< T > values)
Definition: BLI_bounds.hh:26
static std::optional< MinMaxResult< T > > min_max_with_radii(Span< T > values, Span< RadiusT > radii)
Definition: BLI_bounds.hh:53
TEST(any, DefaultConstructor)
Definition: BLI_any_test.cc:10
vec_base< float, 2 > float2
vec_base< int32_t, 2 > int2
MutableSpan< float > radii
__int64 int64_t
Definition: stdint.h:89