Skip to content

Commit

Permalink
Assign ID to points upon creation
Browse files Browse the repository at this point in the history
  • Loading branch information
leonmavr committed Sep 18, 2024
1 parent 4f7f7e2 commit a5ec5d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/quad.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#define IND_SE 2
#define IND_SW 3

extern int g_capacity;

typedef struct point_t {
int x;
int y;
Expand Down
9 changes: 8 additions & 1 deletion src/quad.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit a5ec5d7

Please sign in to comment.