optimize circle-box algorithm