File: test.c

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (63 lines) | stat: -rw-r--r-- 2,156 bytes parent folder | download | duplicates (2)
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
57
58
59
60
61
62
63
/****************************************************************************
 * MODULE:       R-Tree library
 *
 * AUTHOR(S):    Antonin Guttman - original code
 *               Daniel Green (green@superliminal.com) - major clean-up
 *                               and implementation of bounding spheres
 *
 * PURPOSE:      Multidimensional index
 *
 * COPYRIGHT:    (C) 2001 by the GRASS Development Team
 *
 *               This program is free software under the GNU General Public
 *               License (>=v2). Read the file COPYING that comes with GRASS
 *               for details.
 *****************************************************************************/

#include <stdio.h>
#include "index.h"

struct Rect rects[] = {
    {{0, 0, 0, 2, 2,
      0}}, /* xmin, ymin, zmin, xmax, ymax, zmax (for 3 dimensional RTree) */
    {{5, 5, 0, 7, 7, 0}},
    {{8, 5, 0, 9, 6, 0}},
    {{7, 1, 0, 9, 2, 0}}};

int nrects = sizeof(rects) / sizeof(rects[0]);

struct Rect search_rect = {
    {6, 4, 0, 10, 6,
     0} /* search will find above rects that this one overlaps */
};

int MySearchCallback(int id, void *arg)
{
    /* Note: -1 to make up for the +1 when data was inserted */
    fprintf(stdout, "Hit data rect %d\n", id - 1);
    return 1; /* keep going */
}

int main()
{
    struct RTree *rtree = RTreeNewIndex(2);
    int i, nhits;

    fprintf(stdout, "nrects = %d\n", nrects);
    /*
     * Insert all the data rects.
     * Notes about the arguments:
     * parameter 1 is the rect being inserted,
     * parameter 2 is its ID. NOTE: *** ID MUST NEVER BE ZERO ***, hence the +1,
     * parameter 3 is the root of the tree. Note: its address is passed
     * because it can change as a result of this call, therefore no other parts
     * of this code should stash its address since it could change undernieth.
     * parameter 4 is always zero which means to add from the root.
     */
    for (i = 0; i < nrects; i++)
        RTreeInsertRect(&rects[i], i + 1, rtree); /* i+1 is rect ID. */
    nhits = RTreeSearch(rtree, &search_rect, MySearchCallback, 0);
    fprintf(stdout, "Search resulted in %d hits\n", nhits);

    return 0;
}