From a5ec5d7a1eac273bd3948a6565ddac0dd7027510 Mon Sep 17 00:00:00 2001 From: leonmavr <0xleo.git@gmail.com> Date: Wed, 18 Sep 2024 21:07:01 +0200 Subject: [PATCH] Assign ID to points upon creation --- include/quad.h | 2 ++ src/quad.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/quad.h b/include/quad.h index 186166e..f39b854 100644 --- a/include/quad.h +++ b/include/quad.h @@ -9,6 +9,8 @@ #define IND_SE 2 #define IND_SW 3 +extern int g_capacity; + typedef struct point_t { int x; int y; diff --git a/src/quad.c b/src/quad.c index 4cef9d0..426c3f4 100644 --- a/src/quad.c +++ b/src/quad.c @@ -11,7 +11,10 @@ #define MAX(a, b) ((a) > (b) ? (a) : (b)) -static int g_capacity = 2; // Maximum number of points per node +// Maximum number of points per node +int g_capacity = 2; +// unique ID to assign to each point +static size_t qtree_node_ids = 0; static node_t* node_new(rect_t* boundary); static bool node_is_leaf(node_t* node); @@ -23,11 +26,15 @@ static void node_merge(node_t* node); static void node_del_all(node_t* node); static void node_graph(node_t* node); + + node_t* node_new(rect_t* boundary) { node_t *node = malloc(sizeof(node_t)); node->boundary = *boundary; node->count = 0; node->points = malloc(g_capacity * sizeof(point_t)); + for (int i = 0; i < g_capacity; ++i) + node->points[i].id = qtree_node_ids++; node->nw = NULL; node->ne = NULL; node->sw = NULL;