7 #include "libgeda_priv.h"
9 char const *rtree_test_data
[] = {
11 "L 40500 40500 40500 50500 3 0 0 0 -1 -1",
12 "L 56500 40500 56500 50500 3 0 0 0 -1 -1",
13 "B 41000 40500 15000 10000 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1",
14 "B 41500 40900 7500 9100 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1",
15 "B 42000 45000 13500 4500 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1",
16 "B 49500 44000 5000 5000 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1",
17 "B 50000 43500 5000 1000 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1",
21 static enum visit_result
rtree_add(OBJECT
*o_current
, void *context
)
23 RTREE
*rtree
= context
;
25 m_rtree_add(rtree
, o_current
);
40 toplevel
= s_toplevel_new();
41 page
= s_page_new(toplevel
, "test");
42 s_toplevel_goto_page(toplevel
, page
);
44 buf
= g_strjoinv("\n", rtree_test_data
);
45 o_read_buffer(toplevel
, toplevel
->page_current
->object_tail
,
46 buf
, strlen(buf
), "test");
49 rtree
= m_rtree_new(0, 0, G_MAXINT
, G_MAXINT
);
50 s_visit_page(toplevel
->page_current
, rtree_add
, rtree
, VISIT_ANY
, 1);
52 found_objects
= m_rtree_find(rtree
, NULL
, 0, 0, G_MAXINT
, G_MAXINT
);
53 if (g_list_length(found_objects
) == 7) {
54 /* Assume that all 7 are right. */
55 pass("rtree find-all");
58 for (iter
= found_objects
; iter
!= NULL
; iter
= iter
->next
) {
59 OBJECT
*o_current
= iter
->data
;
60 switch (o_current
->type
) {
63 representation
= o_line_save(o_current
);
64 printf("%s\n", representation
);
67 representation
= o_box_save(o_current
);
68 printf("%s\n", representation
);
71 printf("%c ...\n", o_current
->type
);
75 fail("rtree find-all (%d)", g_list_length(found_objects
));
77 g_list_free(found_objects
);
79 found_objects
= m_rtree_find(rtree
, NULL
, 40500, 40500, 40500, 50500);
80 if (g_list_length(found_objects
) == 1) {
81 OBJECT
*o_current
= found_objects
->data
;
82 if (o_current
->type
== OBJ_LINE
) {
83 char *representation
= o_line_save(o_current
);
84 if (strcmp(representation
, rtree_test_data
[1]) == 0) {
85 pass("rtree find-line");
87 fail("rtree find-line (details)");
89 g_free(representation
);
91 fail("rtree find-line (type)");
94 fail("rtree find-line (number)");
96 g_list_free(found_objects
);
98 found_objects
= m_rtree_find(rtree
, NULL
, 41000, 40500, 49500, 50500);
99 if (g_list_length(found_objects
) == 1) {
100 OBJECT
*o_current
= found_objects
->data
;
101 if (o_current
->type
== OBJ_BOX
) {
102 char *representation
= o_box_save(o_current
);
103 if (strcmp(representation
, rtree_test_data
[4]) == 0) {
104 pass("rtree find-box-simple");
106 fail("rtree find-box-simple (details)");
108 g_free(representation
);
110 fail("rtree find-box-simple (type)");
113 fail("rtree find-box-simple (number)");
115 g_list_free(found_objects
);
117 return failed
? 1 : 0;