]> git.itanic.dy.fi Git - sdl-planets/commitdiff
quadtree: Implement quadtree_find_parent
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Mon, 5 Apr 2010 08:42:15 +0000 (11:42 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Mon, 5 Apr 2010 09:15:40 +0000 (12:15 +0300)
This helper function simply returns the highest parent of a given
node.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
quadtree.h

index 94c02cd3b12b2fc0f3902642bb90d54f91f8f1f7..5631013047f6e0e47f51e2fb80ad946ae655689b 100644 (file)
@@ -36,4 +36,14 @@ struct quadtree *quadtree_add(struct quadtree *parent,
 
 int walk_tree(const struct quadtree_iterator *iterator);
 
 
 int walk_tree(const struct quadtree_iterator *iterator);
 
+
+/* quadtree_find_parent - return the highest parent of the node */
+static inline struct quadtree *quadtree_find_parent(struct quadtree *node)
+{
+       while (node->parent)
+               node = node->parent;
+
+       return node;
+}
+
 #endif
 #endif