polygon1.c: Tidy up label_contour() following node_label() changes
[geda-pcb/gde.git] / src / rtree.h
blob254d64a5d78ab6240f1063eb200ed0b4fc9b5d61
1 /* $Id$ */
3 /*
4 * COPYRIGHT
6 * PCB, interactive printed circuit board design
7 * Copyright (C) 1994,1995,1996 Thomas Nau
8 * Copyright (C) 1998,1999,2000,2001 harry eaton
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * Contact addresses for paper mail and Email:
25 * harry eaton, 6697 Buttonhole Ct, Columbia, MD 21044 USA
26 * haceaton@aplcomm.jhuapl.edu
30 /* this file, rtree.h, was written and is
31 * Copyright (c) 2004 harry eaton, it's based on C. Scott's kdtree.h template
34 /* prototypes for r-tree routines.
37 #ifndef __RTREE_INCLUDED__
38 #define __RTREE_INCLUDED__
40 #include "global.h"
43 /* create an rtree from the list of boxes. if 'manage' is true, then
44 * the tree will take ownership of 'boxlist' and free it when the tree
45 * is destroyed. */
46 rtree_t *r_create_tree (const BoxType * boxlist[], int N, int manage);
47 /* destroy an rtree */
48 void r_destroy_tree (rtree_t ** rtree);
50 Boolean r_delete_entry (rtree_t * rtree, const BoxType * which);
51 void r_insert_entry (rtree_t * rtree, const BoxType * which, int manage);
52 void r_substitute (rtree_t * rtree, const BoxType * before,
53 const BoxType * after);
55 /* generic search routine */
56 /* region_in_search should return true if "what you're looking for" is
57 * within the specified region; regions, like rectangles, are closed on
58 * top and left and open on bottom and right.
59 * rectangle_in_region should return true if the given rectangle is
60 * "what you're looking for".
61 * The search will find all rectangles matching the criteria given
62 * by region_in_search and rectangle_in_region and return a count of
63 * how many things rectangle_in_region returned true for. closure is
64 * used to abort the search if desired from within rectangel_in_region
65 * Look at the implementation of r_region_is_empty for how to
66 * abort the search if that is the desired behavior.
69 int r_search (rtree_t * rtree, const BoxType * starting_region,
70 int (*region_in_search) (const BoxType * region, void *cl),
71 int (*rectangle_in_region) (const BoxType * box, void *cl),
72 void *closure);
73 static inline int r_search_pt (rtree_t * rtree, const PointType * pt,
74 int radius,
75 int (*region_in_search) (const BoxType * region, void *cl),
76 int (*rectangle_in_region) (const BoxType * box, void *cl),
77 void *closure)
79 BoxType box;
81 box.X1 = pt->X - radius;
82 box.X2 = pt->X + radius;
83 box.Y1 = pt->Y - radius;
84 box.Y2 = pt->Y + radius;
86 return r_search(rtree, &box, region_in_search, rectangle_in_region, closure);
89 /* -- special-purpose searches build upon r_search -- */
90 /* return 0 if there are any rectangles in the given region. */
91 int r_region_is_empty (rtree_t * rtree, const BoxType * region);
93 void __r_dump_tree (struct rtree_node *, int);
94 #endif