55 RTreeInitLeafBranch, RTreeInitNodeBranchM, RTreeInitNodeBranchF};
67 RTreeInitBranch[type](&(n->
branch[i]),
t);
115 for (i = 0; i <
MAXCARD; i++) {
124 b1->child =
b2->child;
134 int i, first_time = 1;
136 if ((n)->
level > 0) {
137 for (i = 0; i <
t->nodecard; i++) {
138 if (
t->valid_child(&(n->
branch[i].child))) {
149 for (i = 0; i <
t->leafcard; i++) {
150 if (n->
branch[i].child.id) {
186 for (i = 0; i <
t->nodecard; i++) {
187 if (
t->valid_child(&(n->
branch[i].child))) {
194 for (
j = 0;
j <
t->leafcard;
j++) {
235 int i, first_time = 1;
242 return RTreePickLeafBranch(
r, n,
t);
244 for (i = 0; i <
t->nodecard; i++) {
245 if (
t->valid_child(&(n->
branch[i].child))) {
268 if ((n)->level > 0) {
272 RTreeInitNodeBranchM(&(n->
branch[i]),
t);
274 RTreeInitNodeBranchF(&(n->
branch[i]),
t);
279 RTreeInitLeafBranch(&(n->
branch[i]),
t);
292 for (i = 0; i <
nodes; i++) {
293 if (n->
branch[i].child.ptr) {
314static void RTreeSwapDist(
struct dist *a,
struct dist *
b)
326static int RTreeDistIsSorted(
struct dist *d,
int first,
int last)
330 for (i = first; i < last; i++) {
331 if (d[i].distance > d[i + 1].distance)
341static int RTreePartitionDist(
struct dist *d,
int first,
int last)
343 int pivot,
mid = ((first + last) >> 1);
346 if (last - first == 1) {
347 if (d[first].distance > d[last].distance) {
348 RTreeSwapDist(&(d[first]), &(d[last]));
356 if (d[first].distance > d[
mid].distance) {
361 if (d[
larger].distance > d[last].distance) {
364 if (d[
smaller].distance > d[last].distance) {
370 RTreeSwapDist(&(d[
pivot]), &(d[last]));
375 while (first < last) {
376 if (d[first].distance <= d[last].distance) {
377 if (
pivot != first) {
378 RTreeSwapDist(&(d[
pivot]), &(d[first]));
386 RTreeSwapDist(&(d[
pivot]), &(d[last]));
396static void RTreeQuicksortDist(
struct dist *d,
int n)
398 int pivot, first, last;
412 if (!RTreeDistIsSorted(d, first, last)) {
414 pivot = RTreePartitionDist(d, first, last);
452 l = RTreeNewListBranch(
t);
485 for (
j = 0;
j <
t->ndims;
j++) {
492 for (i = 0; i <
maxkids; i++) {
494 rdist[i].distance = 0;
496 for (
j = 0;
j <
t->ndims;
j++) {
497 center_r = (
t->BranchBuf[i].rect.boundary[
j +
t->ndims_alloc] +
498 t->BranchBuf[i].rect.boundary[
j]) /
504 RTreeInitBranch[type](&(n->
branch[i]),
t);
510 for (
j = 0;
j <
t->ndims;
j++) {
512 (
b->rect.boundary[
j +
t->ndims_alloc] +
b->rect.boundary[
j]) / 2;
549 if ((n)->level > 0) {
550 for (i = 0; i <
maxkids; i++) {
551 if (!
t->valid_child(&(n->
branch[i].child))) {
561 else if ((n)->level == 0) {
562 for (i = 0; i <
maxkids; i++) {
563 if (n->
branch[i].child.id == 0) {
575 if (n->
level <
t->rootlevel && overflow[n->
level]) {
577 RTreeRemoveBranches(n,
b,
ee, cover,
t);
578 overflow[n->
level] = 0;
603 for (i = 0; i < depth; i++)
625 else if (n->
level > 0)
631 for (i = 0; i <
maxkids; i++) {
640 RTreePrintBranch(&(n->
branch[i]), depth + 1,
t);
#define MAXKIDS(level, t)
RectReal RTreeRectSphericalVolume(struct RTree_Rect *, struct RTree *)
void RTreeSplitNode(struct RTree_Node *, struct RTree_Branch *, struct RTree_Node *, struct RTree *)
void RTreeCombineRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree_Rect *, struct RTree *)
int RTreeExpandRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree *)
void RTreeInitRect(struct RTree_Rect *, struct RTree *)
Initialize a rectangle to have all 0 coordinates.
#define RTreeCopyRect(r1, r2, t)
#define assert(condition)
void RTreePrintNode(struct RTree_Node *n, int depth, struct RTree *t)
void RTreeCopyNode(struct RTree_Node *n1, struct RTree_Node *n2, struct RTree *t)
void RTreeCopyBranch(struct RTree_Branch *b1, struct RTree_Branch *b2, struct RTree *t)
void RTreeFreeNode(struct RTree_Node *n)
void RTreeDisconnectBranch(struct RTree_Node *n, int i, struct RTree *t)
void RTreeNodeCover(struct RTree_Node *n, struct RTree_Rect *r, struct RTree *t)
void RTreeDestroyNode(struct RTree_Node *n, int nodes)
void RTreeTabIn(int depth)
struct RTree_Node * RTreeAllocNode(struct RTree *t, int level)
int RTreeAddBranch(struct RTree_Branch *b, struct RTree_Node *n, struct RTree_Node **newnode, struct RTree_ListBranch **ee, struct RTree_Rect *cover, char *overflow, struct RTree *t)
int RTreePickBranch(struct RTree_Rect *r, struct RTree_Node *n, struct RTree *t)
void RTreeInitNode(struct RTree *t, struct RTree_Node *n, int type)
void RTreeFreeBoundary(struct RTree_Rect *r)
Delete the boundary of a rectangle.
RectReal * RTreeAllocBoundary(struct RTree *t)
Allocate the boundary array of a rectangle for a given tree.
int RTreeOverlap(struct RTree_Rect *r, struct RTree_Rect *s, struct RTree *t)
void RTreePrintRect(struct RTree_Rect *R, int depth, struct RTree *t)
struct RTree_Branch * branch