Here I got a tiny math exercise for you to calculate.
(1): At first we've a quarter circle with the radius R.
(2): In addition we've a small circle with radius r. It touches the line R and the quarter arc.
(3): Furthermore we get a rectangle that touches the small circle and the quarter arc.
(4): The length of line x is requested.
So, and now you can calculate. The solution is to be found here.