Blender V4.3
BLI_kdtree_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
7#include "BLI_kdtree.h"
8
9#include <cmath>
10
11/* -------------------------------------------------------------------- */
12/* Tests */
13
14static void standard_test()
15{
16 for (int tree_size = 30; tree_size < 500; tree_size++) {
17 int tree_index = 0;
18 KDTree_1d *tree = BLI_kdtree_1d_new(tree_size);
19 int mask = tree_size & 31;
20 bool occupied[32] = {false};
21
22 for (int i = 0; i < tree_size; i++) {
23 int index = i & mask;
24 occupied[index] = true;
25 float value = fmodf(index * 7.121f, 0.6037f); /* Co-prime. */
26 float key[1] = {value};
27 BLI_kdtree_1d_insert(tree, tree_index++, key);
28 }
29 int expected = 0;
30 for (int j = 0; j < 32; j++) {
31 if (occupied[j]) {
32 expected++;
33 }
34 }
35
36 int dedup_count = BLI_kdtree_1d_deduplicate(tree);
37 EXPECT_EQ(dedup_count, expected);
38 BLI_kdtree_1d_free(tree);
39 }
40}
41
42static void deduplicate_test()
43{
44 for (int tree_size = 1; tree_size < 40; tree_size++) {
45 int tree_index = 0;
46 KDTree_1d *tree = BLI_kdtree_1d_new(tree_size);
47 for (int i = 0; i < tree_size; i++) {
48 float key[1] = {1.0f};
49 BLI_kdtree_1d_insert(tree, tree_index++, key);
50 }
51 int dedup_count = BLI_kdtree_1d_deduplicate(tree);
52 EXPECT_EQ(dedup_count, 1);
53 BLI_kdtree_1d_free(tree);
54 }
55}
56
57TEST(kdtree, Standard)
58{
60}
61
62TEST(kdtree, Deduplicate)
63{
65}
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
A KD-tree for nearest neighbor search.
static void deduplicate_test()
TEST(kdtree, Standard)
static void standard_test()
#define fmodf(x, y)
KDTree_3d * tree
ccl_device_inline float4 mask(const int4 mask, const float4 a)