optimized distance-from-origin iteration