return new;
}
+static int _walk_tree(struct quadtree *head, const struct quadtree_iterator *it)
+{
+ int direction, count = 0;
+
+ direction = it->direction(head, it->ptr);
+
+ if ((direction & QUADTREE_UPLEFT) && head->child[0])
+ count += _walk_tree(head->child[0], it);
+
+ if ((direction & QUADTREE_UPRIGHT) && head->child[1])
+ count += _walk_tree(head->child[1], it);
+
+ if ((direction & QUADTREE_DOWNLEFT) && head->child[2])
+ count += _walk_tree(head->child[2], it);
+
+ if ((direction & QUADTREE_DOWNRIGHT) && head->child[3])
+ count += _walk_tree(head->child[3], it);
+
+ if ((direction & QUADTREE_SELF) && it->callback) {
+ it->callback(head, it->ptr);
+ count++;
+ }
+
+ return count;
+}
+
+
+int walk_tree(const struct quadtree_iterator *it)
+{
+ return _walk_tree(it->head, it);
+}
t->parent = 0;
}
+#define QUADTREE_UPLEFT 0x1
+#define QUADTREE_UPRIGHT 0x2
+#define QUADTREE_DOWNLEFT 0x4
+#define QUADTREE_DOWNRIGHT 0x8
+#define QUADTREE_SELF 0x10
+
+struct quadtree_iterator {
+ struct quadtree *head;
+ void *ptr;
+
+ int (*direction)(struct quadtree *head, void *ptr);
+ void (*callback)(struct quadtree *head, void *ptr);
+};
+
+int walk_tree(const struct quadtree_iterator *iterator);
+
#endif