4 * PCB, interactive printed circuit board design
5 * Copyright (C) 1994,1995,1996 Thomas Nau
6 * Copyright (C) 1998,1999,2000,2001 harry eaton
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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Contact addresses for paper mail and Email:
23 * harry eaton, 6697 Buttonhole Ct, Columbia, MD 21044 USA
24 * haceaton@aplcomm.jhuapl.edu
28 /* this file, rtree.h, was written and is
29 * Copyright (c) 2004 harry eaton, it's based on C. Scott's kdtree.h template
32 /* prototypes for r-tree routines.
41 /* create an rtree from the list of boxes. if 'manage' is true, then
42 * the tree will take ownership of 'boxlist' and free it when the tree
44 rtree_t
*r_create_tree (const BoxType
* boxlist
[], int N
, int manage
);
45 /* destroy an rtree */
46 void r_destroy_tree (rtree_t
** rtree
);
48 bool r_delete_entry (rtree_t
* rtree
, const BoxType
* which
);
49 void r_insert_entry (rtree_t
* rtree
, const BoxType
* which
, int manage
);
51 /* generic search routine */
52 /* region_in_search should return true if "what you're looking for" is
53 * within the specified region; regions, like rectangles, are closed on
54 * top and left and open on bottom and right.
55 * rectangle_in_region should return true if the given rectangle is
56 * "what you're looking for".
57 * The search will find all rectangles matching the criteria given
58 * by region_in_search and rectangle_in_region and return a count of
59 * how many things rectangle_in_region returned true for. closure is
60 * used to abort the search if desired from within rectangel_in_region
61 * Look at the implementation of r_region_is_empty for how to
62 * abort the search if that is the desired behavior.
65 int r_search (rtree_t
* rtree
, const BoxType
* starting_region
,
66 int (*region_in_search
) (const BoxType
* region
, void *cl
),
67 int (*rectangle_in_region
) (const BoxType
* box
, void *cl
),
69 static inline int r_search_pt (rtree_t
* rtree
, const PointType
* pt
,
71 int (*region_in_search
) (const BoxType
* region
, void *cl
),
72 int (*rectangle_in_region
) (const BoxType
* box
, void *cl
),
77 box
.X1
= pt
->X
- radius
;
78 box
.X2
= pt
->X
+ radius
;
79 box
.Y1
= pt
->Y
- radius
;
80 box
.Y2
= pt
->Y
+ radius
;
82 return r_search(rtree
, &box
, region_in_search
, rectangle_in_region
, closure
);
85 /* -- special-purpose searches build upon r_search -- */
86 /* return 0 if there are any rectangles in the given region. */
87 int r_region_is_empty (rtree_t
* rtree
, const BoxType
* region
);
89 void __r_dump_tree (struct rtree_node
*, int);