-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkd-tree.h
43 lines (34 loc) · 1 KB
/
kd-tree.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
#ifndef KD_TREE_H
#define KD_TREE_H
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <time.h>
#include "types.h"
#include "geometry.h"
#include "tree.h"
struct kd_node {
struct node *node;
int dim;
struct kd_node *low;
struct kd_node *high;
};
struct node {
struct point pt;
struct tree *tree;
struct line *branch;
};
void nodes_from_trees(struct tree *trees, int ntrees,
struct node **nodes, int *nnodes);
void sort_nodes(struct node **xnodes, struct node **ynodes,
struct node *nodes, int nnodes);
void build_kd_tree(struct node **xnodes, struct node **ynodes, int nnodes, int dim,
struct kd_node *current);
struct node *nearest_by_tree(struct kd_node *root, struct point *pt);
int nearest_by_tree_range(struct kd_node *root, struct point *pt, float range,
struct node ***in_range, int *nin_range);
void free_kd_tree(struct kd_node *tree);
void print_kd_tree(struct kd_node *root);
void print_node(struct node *node);
void test_kd_tree();
#endif