tree/find_closest_element: find both boundaries in single while loop