From 672819693ddf1d203c304697b63f44059cff09b6 Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 26 Jan 2022 02:23:20 -0600 Subject: refactor: move quadtree and util functions into separate headers and clean up names --- experimental/tectonics/quadtree.test.c | 60 ++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'experimental/tectonics/quadtree.test.c') diff --git a/experimental/tectonics/quadtree.test.c b/experimental/tectonics/quadtree.test.c index 472cc0d..ef504c0 100644 --- a/experimental/tectonics/quadtree.test.c +++ b/experimental/tectonics/quadtree.test.c @@ -1,6 +1,6 @@ #include "minunit.h" #include "tests.h" -#include "tectonics.h" +#include "geometry.h" mu_test test_contains_point(); mu_test test_subdivide(); @@ -31,15 +31,22 @@ mu_test test_contains_point() region.center = (struct point_t){ 0.5, 0.5 }; region.half_dim = 0.5; - mu_assert(contains_point(region, (struct point_t){ 0.5, 0.5 })); - mu_assert(contains_point(region, (struct point_t){ 0.25, 0.5 })); - mu_assert(contains_point(region, (struct point_t){ 0.5, 0.25 })); - mu_assert(contains_point(region, (struct point_t){ 0, 0 })); + mu_assert(quad_contains_point(region, + (struct point_t){ 0.5, 0.5 })); + mu_assert(quad_contains_point(region, + (struct point_t){ 0.25, 0.5 })); + mu_assert(quad_contains_point(region, + (struct point_t){ 0.5, 0.25 })); + mu_assert(quad_contains_point(region, + (struct point_t){ 0, 0 })); - mu_assert(!contains_point(region, (struct point_t){ 1.25, 0.5 })); - mu_assert(!contains_point(region, (struct point_t){ 0.25, 1.5 })); - mu_assert(!contains_point(region, (struct point_t){ 1, 1 })); + mu_assert(!quad_contains_point(region, + (struct point_t){ 1.25, 0.5 })); + mu_assert(!quad_contains_point(region, + (struct point_t){ 0.25, 1.5 })); + mu_assert(!quad_contains_point(region, + (struct point_t){ 1, 1 })); return 0; } @@ -57,7 +64,7 @@ mu_test test_subdivide() node.sw = NULL; node.se = NULL; - subdivide(&node, pts); + quadtree_subdivide(&node, pts); mu_assert_equal(node.id, -1); @@ -101,7 +108,7 @@ mu_test test_insert() node.sw = NULL; node.se = NULL; - insert(&node, pts, 1); + quadtree_insert(&node, pts, 1); mu_assert_equal(node.id, -1); @@ -146,8 +153,8 @@ mu_test test_insert_two() node.sw = NULL; node.se = NULL; - insert(&node, pts, 1); - insert(&node, pts, 2); + quadtree_insert(&node, pts, 1); + quadtree_insert(&node, pts, 2); mu_assert_equal(node.id, -1); @@ -206,8 +213,8 @@ mu_test test_get_closest() node.sw = NULL; node.se = NULL; - insert(&node, pts, 1); - insert(&node, pts, 2); + quadtree_insert(&node, pts, 1); + quadtree_insert(&node, pts, 2); mu_assert_equal(node.nw->nw->id, 2); mu_assert_equal(node.nw->nw->nw, NULL); @@ -218,24 +225,29 @@ mu_test test_get_closest() mu_assert_equal(node.nw->se->id, 1); mu_assert_equal(node.nw->se->nw, NULL); - int closest_75 = get_closest(&node, pts, - (struct point_t){0.75, 0.75}); + int closest_75 = + quadtree_get_closest(&node, pts, + (struct point_t){0.75, 0.75}); mu_assert_equal(closest_75, 0); - int closest_33 = get_closest(&node, pts, - (struct point_t){0.3, 0.3}); + int closest_33 = + quadtree_get_closest(&node, pts, + (struct point_t){0.3, 0.3}); mu_assert_equal(closest_33, 1); - int closest_22 = get_closest(&node, pts, - (struct point_t){0.2, 0.2}); + int closest_22 = + quadtree_get_closest(&node, pts, + (struct point_t){0.2, 0.2}); mu_assert_equal(closest_22, 2); - int closest_252 = get_closest(&node, pts, - (struct point_t){0.251, 0.21}); + int closest_252 = + quadtree_get_closest(&node, pts, + (struct point_t){0.251, 0.21}); mu_assert_equal(closest_252, 2); - int closest_nil = get_closest(&node, pts, - (struct point_t){100, 100}); + int closest_nil = + quadtree_get_closest(&node, pts, + (struct point_t){100, 100}); mu_assert_equal(closest_nil, -1); return 0; -- cgit v1.2.1