d(x,y)=\cases{\int _a^b\sqrt{1+(f'(x))^2}\hbox{ dx} \x, y<r\cr
           \int _a^b\sqrt{2+(f'(x))^2}\hbox{ dx} \x, else}