/* * (x) (y) * / \ / \ * /\ (y) (x) /\ * /_a\ / \ ==> / \ / c\ * /\ /\ /\ /\/____\ * /_b\ / c\ /_a\ /_b\ * /____\ */ static c_avl_node_t *rotate_left (c_avl_tree_t *t, c_avl_node_t *x) { c_avl_node_t *p; c_avl_node_t *y; c_avl_node_t *b; assert (x != NULL); assert (x->right != NULL); p = x->parent; y = x->right; b = y->left; x->right = b; if (b != NULL) b->parent = x; x->parent = y; y->left = x; y->parent = p; assert ((p == NULL) || (p->left == x) || (p->right == x)); if (p == NULL) t->root = y; else if (p->left == x) p->left = y; else p->right = y; x->height = calc_height (x); y->height = calc_height (y); return (y); } /* void rotate_left */
static void rebalance (c_avl_tree_t *t, c_avl_node_t *n) { int b_top; int b_bottom; while (n != NULL) { b_top = BALANCE (n); assert ((b_top >= -2) && (b_top <= 2)); if (b_top == -2) { assert (n->right != NULL); b_bottom = BALANCE (n->right); assert ((b_bottom >= -1) && (b_bottom <= 1)); if (b_bottom == 1) n = rotate_right_left (t, n); else n = rotate_left (t, n); } else if (b_top == 2) { assert (n->left != NULL); b_bottom = BALANCE (n->left); assert ((b_bottom >= -1) && (b_bottom <= 1)); if (b_bottom == -1) n = rotate_left_right (t, n); else n = rotate_right (t, n); } else { int height = calc_height (n); if (height == n->height) break; n->height = height; } assert (n->height == calc_height (n)); n = n->parent; } /* while (n != NULL) */ } /* void rebalance */
void measure_slide(slide *sl) { if(sl->image_file != NULL) { sl->des_w = sl->render->w; sl->des_h = sl->render->h; } else { sl->des_w = calc_width(sl); sl->des_h = calc_height(sl); } sl->scr_w = to_screen_coords(sl->des_w); sl->scr_h = to_screen_coords(sl->des_h); }