Wrapped nearest point calculation into a function