I'm working on a simple geometric problem, namely to find the one-dimensional difference $d$ between a square and a circle that touches the square at four points. I thought I had the problem solved, but my solution only works in the domain from $0$ to $\frac{\pi}{4}$ radians. I included my work in a picture at the bottom of the question.
To be clear, my question is this: Is there a better way to solve this problem? If so, what is it? Keep in mind that I am in high school calculus, so I may not know/understand many higher-level concepts, if they apply here.

Your calculations are correct.
Note that the circle that you have is an inscribed not an circumscribed circle.
Also since the angle $\theta $ in your picture is $\pi /4$ your solution simplifies.
$$ D=R(\sec (\theta) -1) = R(\sqrt 2 -1)$$