modest speed improvements to nearest_on_boundary()