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
path: root/tests
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2017-06-12 16:09:33 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2017-06-12 16:12:36 +0300
commit0f4f4d87542b96942234e10421823dcc6766331c (patch)
treefd545e6a4ed9ad0652e7e7e18fb76a9e1324e748 /tests
parentf52dc2f371923c22a974df7105245f7e0b8148ee (diff)
parentd8957e4ccec4cda1cd72e94045efba6ab2ceb6fd (diff)
Merge branch 'master' into blender2.8
Diffstat (limited to 'tests')
-rw-r--r--tests/gtests/blenlib/BLI_kdopbvh_test.cc92
-rw-r--r--tests/gtests/blenlib/CMakeLists.txt1
-rw-r--r--tests/python/bl_alembic_import_test.py2
-rw-r--r--tests/python/bl_keymap_completeness.py1
-rw-r--r--tests/python/pep8.py1
-rw-r--r--tests/python/rna_info_dump.py1
6 files changed, 97 insertions, 1 deletions
diff --git a/tests/gtests/blenlib/BLI_kdopbvh_test.cc b/tests/gtests/blenlib/BLI_kdopbvh_test.cc
new file mode 100644
index 00000000000..bc8cf58d69d
--- /dev/null
+++ b/tests/gtests/blenlib/BLI_kdopbvh_test.cc
@@ -0,0 +1,92 @@
+/* Apache License, Version 2.0 */
+
+#include "testing/testing.h"
+
+/* TODO: ray intersection, overlap ... etc.*/
+
+extern "C" {
+#include "BLI_compiler_attrs.h"
+#include "BLI_kdopbvh.h"
+#include "BLI_rand.h"
+#include "BLI_math_vector.h"
+#include "MEM_guardedalloc.h"
+}
+
+/* -------------------------------------------------------------------- */
+/* Helper Functions */
+
+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;
+ }
+}
+
+/* -------------------------------------------------------------------- */
+/* Tests */
+
+TEST(kdopbvh, Empty)
+{
+ BVHTree *tree = BLI_bvhtree_new(0, 0.0, 8, 8);
+ BLI_bvhtree_balance(tree);
+ EXPECT_EQ(0, BLI_bvhtree_get_size(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);
+ }
+
+ EXPECT_EQ(BLI_bvhtree_get_size(tree), 1);
+
+ BLI_bvhtree_balance(tree);
+ BLI_bvhtree_free(tree);
+}
+
+/**
+ * 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)
+{
+ struct RNG *rng = BLI_rng_new(random_seed);
+ BVHTree *tree = BLI_bvhtree_new(points_len, 0.0, 8, 8);
+ float (*points)[3] = (float (*)[3])MEM_mallocN(sizeof(float[3]) * points_len, __func__);
+ 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 */
+ for (int i = 0; i < points_len; i++) {
+ const int j = BLI_bvhtree_find_nearest(tree, points[i], NULL, NULL, NULL);
+ 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);
+ }
+#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);
+}
+
+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); }
diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt
index a190d9cd8c5..8b013e7a7a6 100644
--- a/tests/gtests/blenlib/CMakeLists.txt
+++ b/tests/gtests/blenlib/CMakeLists.txt
@@ -37,6 +37,7 @@ set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LIN
BLENDER_TEST(BLI_array_store "bf_blenlib")
BLENDER_TEST(BLI_array_utils "bf_blenlib")
+BLENDER_TEST(BLI_kdopbvh "bf_blenlib;bf_intern_eigen")
BLENDER_TEST(BLI_stack "bf_blenlib")
BLENDER_TEST(BLI_math_color "bf_blenlib")
BLENDER_TEST(BLI_math_geom "bf_blenlib;bf_intern_eigen")
diff --git a/tests/python/bl_alembic_import_test.py b/tests/python/bl_alembic_import_test.py
index 1322a883b72..e9dcbd80a3a 100644
--- a/tests/python/bl_alembic_import_test.py
+++ b/tests/python/bl_alembic_import_test.py
@@ -207,7 +207,7 @@ def main():
import argparse
if '--' in sys.argv:
- argv = [sys.argv[0]] + sys.argv[sys.argv.index('--')+1:]
+ argv = [sys.argv[0]] + sys.argv[sys.argv.index('--') + 1:]
else:
argv = sys.argv
diff --git a/tests/python/bl_keymap_completeness.py b/tests/python/bl_keymap_completeness.py
index 00322907f69..652ed449a3c 100644
--- a/tests/python/bl_keymap_completeness.py
+++ b/tests/python/bl_keymap_completeness.py
@@ -80,5 +80,6 @@ def main():
import sys
sys.exit(1)
+
if __name__ == "__main__":
main()
diff --git a/tests/python/pep8.py b/tests/python/pep8.py
index 0e6250f534b..dde4250f6aa 100644
--- a/tests/python/pep8.py
+++ b/tests/python/pep8.py
@@ -178,5 +178,6 @@ def main():
"--max-line-length=1000"
" '%s'" % f)
+
if __name__ == "__main__":
main()
diff --git a/tests/python/rna_info_dump.py b/tests/python/rna_info_dump.py
index c26d94a1246..da228e52652 100644
--- a/tests/python/rna_info_dump.py
+++ b/tests/python/rna_info_dump.py
@@ -127,5 +127,6 @@ def api_dump(use_properties=True, use_functions=True):
print("END")
+
if __name__ == "__main__":
api_dump()