SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Test.cpp
Go to the documentation of this file.
1 //
2 // Test.cpp
3 //
4 // This is a direct port of the C version of the RTree test program.
5 //
6 
7 #include <stdio.h>
8 #include "RTree.h"
9 
10 struct Rect
11 {
12  Rect() {}
13 
14  Rect(int a_minX, int a_minY, int a_maxX, int a_maxY)
15  {
16  min[0] = a_minX;
17  min[1] = a_minY;
18 
19  max[0] = a_maxX;
20  max[1] = a_maxY;
21  }
22 
23 
24  int min[2];
25  int max[2];
26 };
27 
28 struct Rect rects[] =
29 {
30  Rect(0, 0, 2, 2), // xmin, ymin, xmax, ymax (for 2 dimensional RTree)
31  Rect(5, 5, 7, 7),
32  Rect(8, 5, 9, 6),
33  Rect(7, 1, 9, 2),
34 };
35 
36 int nrects = sizeof(rects) / sizeof(rects[0]);
37 
38 Rect search_rect(6, 4, 10, 6); // search will find above rects that this one overlaps
39 
40 
41 bool MySearchCallback(int id, void* arg)
42 {
43  printf("Hit data rect %d\n", id);
44  return true; // keep going
45 }
46 
47 
48 void main()
49 {
51 
52  int i, nhits;
53  printf("nrects = %d\n", nrects);
54 
55  for(i=0; i<nrects; i++)
56  {
57  tree.Insert(rects[i].min, rects[i].max, i); // Note, all values including zero are fine in this version
58  }
59 
60  nhits = tree.Search(search_rect.min, search_rect.max, MySearchCallback, NULL);
61 
62  printf("Search resulted in %d hits\n", nhits);
63 
64  getchar(); // Wait for keypress on exit so we can read console output
65 
66  // Output:
67  //
68  // nrects = 4
69  // Hit data rect 1
70  // Hit data rect 2
71  // Search resulted in 2 hits
72 }
virtual void Insert(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], const DATATYPE &a_dataId)
int min[2]
Definition: Test.cpp:24
Rect()
Definition: Test.cpp:12
#define min(a, b)
Definition: polyfonts.c:66
virtual int Search(const ELEMTYPE a_min[NUMDIMS], const ELEMTYPE a_max[NUMDIMS], const CONTEXT &c) const
DK 15.10.2008 - begin.
bool MySearchCallback(int id, void *arg)
Definition: Test.cpp:41
Rect search_rect(6, 4, 10, 6)
struct Rect rects[]
Definition: Test.cpp:28
#define max(a, b)
Definition: polyfonts.c:65
int nrects
Definition: Test.cpp:36
Definition: RTree.h:61
Definition: Test.cpp:10
int max[2]
Definition: Test.cpp:25
Rect(int a_minX, int a_minY, int a_maxX, int a_maxY)
Definition: Test.cpp:14
int main(int argc, char *argv[])