2 Implementation of 2d kd trees.
4 Part of the swftools package.
6 Copyright (c) 2010 Matthias Kramm <kramm@quiss.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
43 typedef enum {KD_RIGHT
=0, KD_DOWN
=1, KD_LEFT
=2, KD_UP
=3} kdtype_t
;
45 typedef struct _kdbbox
{
46 int32_t xmin
, ymin
, xmax
, ymax
;
51 typedef struct _kdbranch kdbranch_t
;
52 typedef struct _kdarea kdarea_t
;
61 kdarea_t
*neighbors
[4];
67 typedef struct _kdtree
{
71 /* usually a subset of the tree, e.g. caused by
72 intersecting the tree with a halfplane */
73 typedef struct _kdarea_list
{
74 struct _kdarea_list
*next
;
75 struct _kdarea_list
*prev
;
79 kdtree_t
* kdtree_new();
80 void kdarea_destroy(kdarea_t
*area
);
81 void kdbranch_destroy(kdbranch_t
*b
);
82 void kdtree_destroy(kdtree_t
*tree
);
83 kdarea_t
* kdtree_find(kdtree_t
*tree
, int x
, int y
);
84 void kdtree_add_box(kdtree_t
*tree
, int32_t x1
, int32_t y1
, int32_t x2
, int32_t y2
, void*data
);
85 void kdtree_print(kdtree_t
*tree
);
87 kdarea_t
*kdarea_neighbor(kdarea_t
*area
, int dir
, int xy
);
89 #define kdarea_left_neighbor(area, y) (kdarea_neighbor((area), KD_LEFT, (y)))
90 #define kdarea_right_neighbor(area, y) (kdarea_neighbor((area), KD_RIGHT, (y)))
91 #define kdarea_top_neighbor(area, x) (kdarea_neighbor((area), KD_TOP, (x)))
92 #define kdarea_bottom_neighbor(area, x) (kdarea_neighbor((area), KD_BOTTOM, (x)))