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 <kaapeli@itanic.dy.fi>
+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;
static void validate_subtree(const struct quadtree *node)
{
int i;
validate_subtree(quadtree_find_parent(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
/**
* quadtree_add - add a node to a quadtree
* @parent: parent node