diff options
Diffstat (limited to 'world/node_tree.c')
-rw-r--r-- | world/node_tree.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/world/node_tree.c b/world/node_tree.c new file mode 100644 index 00000000..f6874711 --- /dev/null +++ b/world/node_tree.c @@ -0,0 +1,107 @@ +#include <fitz.h> + +fz_error * +fz_newtree(fz_tree **treep) +{ + fz_tree *tree; + + tree = *treep = fz_malloc(sizeof (fz_tree)); + if (!tree) + return fz_outofmem; + + tree->refs = 1; + tree->root = nil; + tree->head = nil; + + return nil; +} + +fz_tree * +fz_keeptree(fz_tree *tree) +{ + tree->refs ++; + return tree; +} + +void +fz_droptree(fz_tree *tree) +{ + if (--tree->refs == 0) + { + if (tree->root) + fz_dropnode(tree->root); + fz_free(tree); + } +} + +fz_rect +fz_boundtree(fz_tree *tree, fz_matrix ctm) +{ + if (tree->root) + return fz_boundnode(tree->root, ctm); + return fz_emptyrect; +} + +void +fz_insertnodefirst(fz_node *parent, fz_node *child) +{ + child->parent = parent; + child->next = parent->first; + parent->first = child; + if (!parent->last) + parent->last = child; +} + +void +fz_insertnodelast(fz_node *parent, fz_node *child) +{ + child->parent = parent; + if (!parent->first) + parent->first = child; + else + parent->last->next = child; + parent->last = child; +} + +void +fz_insertnodeafter(fz_node *prev, fz_node *child) +{ + fz_node *parent = prev->parent; + child->parent = parent; + if (parent->last == prev) + parent->last = child; + child->next = prev->next; + prev->next = child; +} + +void +fz_removenode(fz_node *child) +{ + fz_node *parent = child->parent; + fz_node *prev; + fz_node *node; + + if (parent->first == child) + { + parent->first = child->next; + if (parent->last == child) + parent->last = nil; + return; + } + + prev = parent->first; + node = prev->next; + + while (node) + { + if (node == child) + { + prev->next = child->next; + } + prev = node; + node = node->next; + } + + parent->last = prev; +} + |