The search was missing a check whether the current node is the
nearest. Obviously without this check we never found anything else
except the initial node as the nearest node.
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
vector_sub(&nearest->pos, pos, &tmp);
distance = vector_abs(&tmp);
vector_sub(&nearest->pos, pos, &tmp);
distance = vector_abs(&tmp);
+ if (tree != nearest) {
+ vector_sub(&tree->pos, pos, &tmp);
+ dist = vector_abs(&tmp);
+ if (dist < distance) {
+ nearest = tree;
+ distance = dist;
+ }
+ }
+
if (!is_within(&nearest->pos, corner)) {
if (debug)
printf("Discarding nearest %p "
if (!is_within(&nearest->pos, corner)) {
if (debug)
printf("Discarding nearest %p "