Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-17 07:17:24 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-17 07:21:24 +0300
commite12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch)
tree8cf3453d12edb177a218ef8009357518ec6cab6a /tests/gtests/blenlib/BLI_kdopbvh_test.cc
parentb3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff)
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'tests/gtests/blenlib/BLI_kdopbvh_test.cc')
-rw-r--r--tests/gtests/blenlib/BLI_kdopbvh_test.cc141
1 files changed, 79 insertions, 62 deletions
diff --git a/tests/gtests/blenlib/BLI_kdopbvh_test.cc b/tests/gtests/blenlib/BLI_kdopbvh_test.cc
index ff4a74b8be8..bd35a491550 100644
--- a/tests/gtests/blenlib/BLI_kdopbvh_test.cc
+++ b/tests/gtests/blenlib/BLI_kdopbvh_test.cc
@@ -17,14 +17,12 @@ extern "C" {
/* -------------------------------------------------------------------- */
/* Helper Functions */
-static void rng_v3_round(
- float *coords, int coords_len,
- struct RNG *rng, int round, float scale)
+static void rng_v3_round(float *coords, int coords_len, struct RNG *rng, int round, float scale)
{
- for (int i = 0; i < coords_len; i++) {
- float f = BLI_rng_get_float(rng) * 2.0f - 1.0f;
- coords[i] = ((float)((int)(f * round)) / (float)round) * scale;
- }
+ for (int i = 0; i < coords_len; i++) {
+ float f = BLI_rng_get_float(rng) * 2.0f - 1.0f;
+ coords[i] = ((float)((int)(f * round)) / (float)round) * scale;
+ }
}
/* -------------------------------------------------------------------- */
@@ -32,86 +30,105 @@ static void rng_v3_round(
TEST(kdopbvh, Empty)
{
- BVHTree *tree = BLI_bvhtree_new(0, 0.0, 8, 8);
- BLI_bvhtree_balance(tree);
- EXPECT_EQ(0, BLI_bvhtree_get_len(tree));
- BLI_bvhtree_free(tree);
+ BVHTree *tree = BLI_bvhtree_new(0, 0.0, 8, 8);
+ BLI_bvhtree_balance(tree);
+ EXPECT_EQ(0, BLI_bvhtree_get_len(tree));
+ BLI_bvhtree_free(tree);
}
TEST(kdopbvh, Single)
{
- BVHTree *tree = BLI_bvhtree_new(1, 0.0, 8, 8);
- {
- float co[3] = {0};
- BLI_bvhtree_insert(tree, 0, co, 1);
- }
+ BVHTree *tree = BLI_bvhtree_new(1, 0.0, 8, 8);
+ {
+ float co[3] = {0};
+ BLI_bvhtree_insert(tree, 0, co, 1);
+ }
- EXPECT_EQ(BLI_bvhtree_get_len(tree), 1);
+ EXPECT_EQ(BLI_bvhtree_get_len(tree), 1);
- BLI_bvhtree_balance(tree);
- BLI_bvhtree_free(tree);
+ BLI_bvhtree_balance(tree);
+ BLI_bvhtree_free(tree);
}
void optimal_check_callback(void *userdata, int index, const float co[3], BVHTreeNearest *nearest)
{
- float (*points)[3] = (float (*)[3])userdata;
+ float(*points)[3] = (float(*)[3])userdata;
- /* BVH_NEAREST_OPTIMAL_ORDER should hit the right node on the first try */
- EXPECT_EQ(nearest->index, -1);
- EXPECT_EQ_ARRAY(co, points[index], 3);
+ /* BVH_NEAREST_OPTIMAL_ORDER should hit the right node on the first try */
+ EXPECT_EQ(nearest->index, -1);
+ EXPECT_EQ_ARRAY(co, points[index], 3);
- nearest->index = index;
- nearest->dist_sq = len_squared_v3v3(co, points[index]);
+ nearest->index = index;
+ nearest->dist_sq = len_squared_v3v3(co, points[index]);
}
/**
* Note that a small epsilon is added to the BVH nodes bounds, even if we pass in zero.
* Use rounding to ensure very close nodes don't cause the wrong node to be found as nearest.
*/
-static void find_nearest_points_test(int points_len, float scale, int round, int random_seed, bool optimal = false)
+static void find_nearest_points_test(
+ int points_len, float scale, int round, int random_seed, bool optimal = false)
{
- struct RNG *rng = BLI_rng_new(random_seed);
- BVHTree *tree = BLI_bvhtree_new(points_len, 0.0, 8, 8);
+ struct RNG *rng = BLI_rng_new(random_seed);
+ BVHTree *tree = BLI_bvhtree_new(points_len, 0.0, 8, 8);
- void *mem = MEM_mallocN(sizeof(float[3]) * points_len, __func__);
- float (*points)[3] = (float (*)[3])mem;
+ void *mem = MEM_mallocN(sizeof(float[3]) * points_len, __func__);
+ float(*points)[3] = (float(*)[3])mem;
- for (int i = 0; i < points_len; i++) {
- rng_v3_round(points[i], 3, rng, round, scale);
- BLI_bvhtree_insert(tree, i, points[i], 1);
- }
- BLI_bvhtree_balance(tree);
+ for (int i = 0; i < points_len; i++) {
+ rng_v3_round(points[i], 3, rng, round, scale);
+ BLI_bvhtree_insert(tree, i, points[i], 1);
+ }
+ BLI_bvhtree_balance(tree);
- /* first find each point */
- BVHTree_NearestPointCallback callback = optimal ? optimal_check_callback : NULL;
- int flags = optimal ? BVH_NEAREST_OPTIMAL_ORDER : 0;
+ /* first find each point */
+ BVHTree_NearestPointCallback callback = optimal ? optimal_check_callback : NULL;
+ int flags = optimal ? BVH_NEAREST_OPTIMAL_ORDER : 0;
- for (int i = 0; i < points_len; i++) {
- const int j = BLI_bvhtree_find_nearest_ex(tree, points[i], NULL, callback, points, flags);
- if (j != i) {
+ for (int i = 0; i < points_len; i++) {
+ const int j = BLI_bvhtree_find_nearest_ex(tree, points[i], NULL, callback, points, flags);
+ if (j != i) {
#if 0
- const float dist = len_v3v3(points[i], points[j]);
- if (dist > (1.0f / (float)round)) {
- printf("%.15f (%d %d)\n", dist, i, j);
- print_v3_id(points[i]);
- print_v3_id(points[j]);
- fflush(stdout);
- }
+ const float dist = len_v3v3(points[i], points[j]);
+ if (dist > (1.0f / (float)round)) {
+ printf("%.15f (%d %d)\n", dist, i, j);
+ print_v3_id(points[i]);
+ print_v3_id(points[j]);
+ fflush(stdout);
+ }
#endif
- EXPECT_GE(j, 0);
- EXPECT_LT(j, points_len);
- EXPECT_EQ_ARRAY(points[i], points[j], 3);
- }
- }
- BLI_bvhtree_free(tree);
- BLI_rng_free(rng);
- MEM_freeN(points);
+ EXPECT_GE(j, 0);
+ EXPECT_LT(j, points_len);
+ EXPECT_EQ_ARRAY(points[i], points[j], 3);
+ }
+ }
+ BLI_bvhtree_free(tree);
+ BLI_rng_free(rng);
+ MEM_freeN(points);
}
-TEST(kdopbvh, FindNearest_1) { find_nearest_points_test(1, 1.0, 1000, 1234); }
-TEST(kdopbvh, FindNearest_2) { find_nearest_points_test(2, 1.0, 1000, 123); }
-TEST(kdopbvh, FindNearest_500) { find_nearest_points_test(500, 1.0, 1000, 12); }
+TEST(kdopbvh, FindNearest_1)
+{
+ find_nearest_points_test(1, 1.0, 1000, 1234);
+}
+TEST(kdopbvh, FindNearest_2)
+{
+ find_nearest_points_test(2, 1.0, 1000, 123);
+}
+TEST(kdopbvh, FindNearest_500)
+{
+ find_nearest_points_test(500, 1.0, 1000, 12);
+}
-TEST(kdopbvh, OptimalFindNearest_1) { find_nearest_points_test(1, 1.0, 1000, 1234, true); }
-TEST(kdopbvh, OptimalFindNearest_2) { find_nearest_points_test(2, 1.0, 1000, 123, true); }
-TEST(kdopbvh, OptimalFindNearest_500) { find_nearest_points_test(500, 1.0, 1000, 12, true); }
+TEST(kdopbvh, OptimalFindNearest_1)
+{
+ find_nearest_points_test(1, 1.0, 1000, 1234, true);
+}
+TEST(kdopbvh, OptimalFindNearest_2)
+{
+ find_nearest_points_test(2, 1.0, 1000, 123, true);
+}
+TEST(kdopbvh, OptimalFindNearest_500)
+{
+ find_nearest_points_test(500, 1.0, 1000, 12, true);
+}