-
Notifications
You must be signed in to change notification settings - Fork 5
/
quadtree.h
56 lines (47 loc) · 1.3 KB
/
quadtree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include "cthing.h"
#include "data/tree.h"
#include "geom/rect.h"
#include "math/vec.h"
#include "mem/mpool.h"
CT_BEGIN_DECLS
typedef struct CT_QTNode CT_QTNode;
struct CT_QTNode {
CT_QTNode *children[4];
CT_Vec2f *point;
void *data;
union {
struct {
float x, y, w, h, cx, cy;
};
struct {
CT_Vec2f pos, size, centroid;
};
CT_Rect2f bounds;
float coords[6];
};
size_t type;
};
typedef struct {
CT_MPool pool;
CT_QTNode root;
size_t size;
} CT_Quadtree;
typedef int (*CT_QTVisitor)(const CT_QTNode *, void *);
int ct_qtree_init(CT_Quadtree *t,
float x,
float y,
float w,
float h,
size_t poolSize);
void ct_qtree_free(CT_Quadtree *t);
int ct_qtree_insert(CT_Quadtree *t, const CT_Vec2f *p, const void *data);
int ct_qtree_remove(CT_Quadtree *t, const CT_Vec2f *p);
CT_QTNode *ct_qtree_find_leaf(const CT_Quadtree *t, const CT_Vec2f *p);
void ct_qtree_trace_node(const CT_QTNode *node, size_t depth);
void ct_qtree_trace(const CT_Quadtree *t);
int ct_qtree_visit_leaves(const CT_Quadtree *t,
CT_QTVisitor visit,
void *state);
void ct_qtree_visit(const CT_Quadtree *t, CT_QTVisitor visit, void *state);
CT_END_DECLS