minor simplifications in c_index_insert.

This commit is contained in:
Antonio Carzaniga 2019-08-20 17:23:54 +02:00
parent 956e652827
commit 576139b448

13
balls.c
View File

@ -173,11 +173,11 @@ static void c_index_add_ball(struct bt_node * n, const struct ball * b) {
} }
static void c_index_insert(struct bt_node * t, struct bt_node * n, struct ball * b) { static void c_index_insert(struct bt_node * t, struct bt_node * n, struct ball * b) {
assert(t);
double w = width; double w = width;
double h = height; double h = height;
double ref_x = 0.0; double ref_x = 0.0;
double ref_y = 0.0; double ref_y = 0.0;
c_index_init_node(n, b);
for (;;) { for (;;) {
c_index_add_ball(t, b); c_index_add_ball(t, b);
if (w > h) { /* horizontal split */ if (w > h) { /* horizontal split */
@ -186,7 +186,7 @@ static void c_index_insert(struct bt_node * t, struct bt_node * n, struct ball *
w = t->ball->x - ref_x; w = t->ball->x - ref_x;
t = t->left; t = t->left;
} else { } else {
t->left = c_index_init_node(n, b); t->left = n;
return; return;
} }
} else { } else {
@ -195,7 +195,7 @@ static void c_index_insert(struct bt_node * t, struct bt_node * n, struct ball *
ref_x = t->ball->x; ref_x = t->ball->x;
t = t->right; t = t->right;
} else { } else {
t->right = c_index_init_node(n, b); t->right = n;
return; return;
} }
} }
@ -205,7 +205,7 @@ static void c_index_insert(struct bt_node * t, struct bt_node * n, struct ball *
h = t->ball->y - ref_y; h = t->ball->y - ref_y;
t = t->left; t = t->left;
} else { } else {
t->left = c_index_init_node(n, b); t->left = n;
return; return;
} }
} else { } else {
@ -214,7 +214,7 @@ static void c_index_insert(struct bt_node * t, struct bt_node * n, struct ball *
ref_y = t->ball->y; ref_y = t->ball->y;
t = t->right; t = t->right;
} else { } else {
t->right = c_index_init_node(n, b); t->right = n;
return; return;
} }
} }
@ -224,9 +224,8 @@ static void c_index_insert(struct bt_node * t, struct bt_node * n, struct ball *
void c_index_build() { void c_index_build() {
c_index_init_node(c_index, balls); c_index_init_node(c_index, balls);
for(int i = 1; i < n_balls; ++i) { for(int i = 1; i < n_balls; ++i)
c_index_insert(c_index, c_index + i, balls + i); c_index_insert(c_index, c_index + i, balls + i);
}
} }
struct bt_node ** c_index_stack = 0; struct bt_node ** c_index_stack = 0;