58 RTreeInitLeafBranch, RTreeInitNodeBranchM, RTreeInitNodeBranchF};
70 RTreeInitBranch[type](&(n->
branch[i]),
t);
118 for (i = 0; i <
MAXCARD; i++) {
127 b1->child =
b2->child;
137 int i, first_time = 1;
139 if ((n)->
level > 0) {
140 for (i = 0; i <
t->nodecard; i++) {
141 if (
t->valid_child(&(n->
branch[i].child))) {
152 for (i = 0; i <
t->leafcard; i++) {
153 if (n->
branch[i].child.id) {
189 for (i = 0; i <
t->nodecard; i++) {
190 if (
t->valid_child(&(n->
branch[i].child))) {
197 for (
j = 0;
j <
t->leafcard;
j++) {
238 int i, first_time = 1;
245 return RTreePickLeafBranch(
r, n,
t);
247 for (i = 0; i <
t->nodecard; i++) {
248 if (
t->valid_child(&(n->
branch[i].child))) {
271 if ((n)->level > 0) {
275 RTreeInitNodeBranchM(&(n->
branch[i]),
t);
277 RTreeInitNodeBranchF(&(n->
branch[i]),
t);
282 RTreeInitLeafBranch(&(n->
branch[i]),
t);
295 for (i = 0; i <
nodes; i++) {
296 if (n->
branch[i].child.ptr) {
317static void RTreeSwapDist(
struct dist *a,
struct dist *
b)
329static int RTreeDistIsSorted(
struct dist *d,
int first,
int last)
333 for (i = first; i < last; i++) {
334 if (d[i].distance > d[i + 1].distance)
344static int RTreePartitionDist(
struct dist *d,
int first,
int last)
346 int pivot,
mid = ((first + last) >> 1);
349 if (last - first == 1) {
350 if (d[first].distance > d[last].distance) {
351 RTreeSwapDist(&(d[first]), &(d[last]));
359 if (d[first].distance > d[
mid].distance) {
364 if (d[
larger].distance > d[last].distance) {
367 if (d[
smaller].distance > d[last].distance) {
373 RTreeSwapDist(&(d[
pivot]), &(d[last]));
378 while (first < last) {
379 if (d[first].distance <= d[last].distance) {
380 if (
pivot != first) {
381 RTreeSwapDist(&(d[
pivot]), &(d[first]));
389 RTreeSwapDist(&(d[
pivot]), &(d[last]));
399static void RTreeQuicksortDist(
struct dist *d,
int n)
401 int pivot, first, last;
415 if (!RTreeDistIsSorted(d, first, last)) {
417 pivot = RTreePartitionDist(d, first, last);
455 l = RTreeNewListBranch(
t);
488 for (
j = 0;
j <
t->ndims;
j++) {
495 for (i = 0; i <
maxkids; i++) {
497 rdist[i].distance = 0;
499 for (
j = 0;
j <
t->ndims;
j++) {
500 center_r = (
t->BranchBuf[i].rect.boundary[
j +
t->ndims_alloc] +
501 t->BranchBuf[i].rect.boundary[
j]) /
507 RTreeInitBranch[type](&(n->
branch[i]),
t);
513 for (
j = 0;
j <
t->ndims;
j++) {
515 (
b->rect.boundary[
j +
t->ndims_alloc] +
b->rect.boundary[
j]) / 2;
552 if ((n)->level > 0) {
553 for (i = 0; i <
maxkids; i++) {
554 if (!
t->valid_child(&(n->
branch[i].child))) {
564 else if ((n)->level == 0) {
565 for (i = 0; i <
maxkids; i++) {
566 if (n->
branch[i].child.id == 0) {
578 if (n->
level <
t->rootlevel && overflow[n->
level]) {
580 RTreeRemoveBranches(n,
b,
ee, cover,
t);
581 overflow[n->
level] = 0;
606 for (i = 0; i < depth; i++)
628 else if (n->
level > 0)
634 for (i = 0; i <
maxkids; i++) {
643 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