From: Timo Kokkonen Date: Tue, 7 Dec 2010 18:20:57 +0000 (+0200) Subject: quadtree.c: Compare vectors, not quadtrees X-Git-Url: http://git.itanic.dy.fi/?p=sdl-planets;a=commitdiff_plain;h=b909a1a7d710bf473ff33f8c369ae130c6bd7020 quadtree.c: Compare vectors, not quadtrees Factor out the vector comparison into a separate function. That way it is more useful if plain vector comparison is needed. Signed-off-by: Timo Kokkonen --- diff --git a/quadtree.c b/quadtree.c index 10c4ec8..80b285a 100644 --- a/quadtree.c +++ b/quadtree.c @@ -15,6 +15,28 @@ static void trap(void) exit(1); } +static int quadtree_compare_coord(const struct vector *a, + const struct vector *b) +{ + int up, left; + + up = b->y < a->y; + left = b->x < a->x; + + if (up && left) + return 0; + if (up && !left) + return 1; + if (left) + return 2; + return 3; +} + +static int quadtree_compare(const struct quadtree *a, const struct quadtree *b) +{ + return quadtree_compare_coord(&a->pos, &b->pos); +} + static void validate_subtree(const struct quadtree *node) { int i; @@ -99,22 +121,6 @@ static void validate_tree(const struct quadtree *node) validate_subtree(quadtree_find_parent(node)); } -static int quadtree_compare(struct quadtree *a, struct quadtree *b) -{ - int up, left; - - up = b->pos.y < a->pos.y; - left = b->pos.x < a->pos.x; - - if (up && left) - return 0; - if (up && !left) - return 1; - if (left) - return 2; - return 3; -} - /** * quadtree_add - add a node to a quadtree * @parent: parent node