5 * Created by Bryan Donlan on Tue 10 Jan 2006.
6 * Copyright (c) 2006 Bryan Donlan. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library 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 GNU
16 * Lesser General Public License for more details.
27 bool operator()(const Region
&r1
, const Region
&r2
)
30 do { if (r1.v != r2.v) return r1.v < r2.v; } while (0)
31 CMP(xmin
); CMP(xmax
); CMP(ymin
); CMP(ymax
);
36 struct R2
: public Region
{
39 std::cerr
<< "R2 dest " << to_s() << " ok " << ok
<< std::endl
;
43 R2(const Region
&r
) : Region(r
), ok(true) {}
44 R2(int x1
, int x2
, int y1
, int y2
) : Region(x1
,x2
,y1
,y2
), ok(true) {}
47 Region
random_in(const Region
&tr
) {
48 double rp1
= (double)rand() / (double)RAND_MAX
;
49 double rp2
= (double)rand() / (double)RAND_MAX
;
51 int pt1
= tr
.xmin
+ rp1
* (double)(tr
.xmax
- tr
.xmin
);
52 int pt2
= tr
.ymin
+ rp1
* (double)(tr
.ymax
- tr
.ymin
);
54 return Region(pt1
, pt1
, pt2
, pt2
);
59 std::cerr
<< "rbr=" << sizeof(RBranch
<Region
>) << "rn=" << sizeof(RNode
<Region
>) << "rd=" << sizeof(RData
<Region
>) << std::endl
;
61 std::vector
<R2
> testVec
;
64 for (int i
= 0; i
< 500; i
++) {
65 int x1
= rand(); // % 50000;
66 int x2
= x1
+ rand() % 125;
67 int y1
= rand(); // % 50000;
68 int y2
= y1
+ rand() % 125;
81 Region
r(x1
, x2
, y1
, y2
);
83 if (tree
.find_one(r
)) {
88 testVec
.push_back(R2(r
));
94 for (std::vector
<R2
>::iterator i
= testVec
.begin(); i
!= testVec
.end(); i
++) {
98 // fprintf(stderr, "\rins %06d", ct);
100 std::cerr
<< std::endl
<< "size=" << tree
.size() << "inner=" << tree
.inner_size() << std::endl
;
103 for (std::vector
<R2
>::iterator i
= testVec
.begin(); i
!= testVec
.end(); i
++) {
105 fprintf(stderr
, "\rchk %06d", ct
);
106 std::cout
<< "Verify of " << (*i
).to_s() << "... ";
107 Region q
= random_in(*i
);
108 assert(q
.overlaps((*i
)));
109 std::cout
<< q
.to_s() << "... ";
112 std::vector
<RTree
<R2
>::ptr
> results
= tree
.find(q
);
113 std::cout
<< results
.size() << " results ... ";
114 for (std::vector
<RTree
<R2
>::ptr
>::iterator ci
= results
.begin(); ci
!= results
.end(); ci
++) {
115 if ((*ci
).data() == *i
) {
122 results
= tree
.find(q
);
124 std::cout
<< results
.size() << " results postdel ... ";
125 for (std::vector
<RTree
<R2
>::ptr
>::iterator ci
= results
.begin(); ci
!= results
.end(); ci
++) {
126 if ((*ci
).data() == *i
) {
137 std::cout
<< std::endl
;
142 std::cout
<< "Not all ok";
144 std::cout
<< "All ok";
145 std::cout
<< std::endl
;
148 std::cout
<< "sz=" << tree
.size() << "isz=" << tree
.inner_size() << std::endl
;
149 std::cout
<< "alloc/free test: " << std::endl
;
150 tree
.insert(Region(1,2,3,4), R2(1,2,3,4));
151 } catch (std::exception
&e
) {
152 std::cout
<< "abort: " << e
.what();
154 std::cout
<< std::endl
;
155 fprintf(stderr
, "\n");