I once implemented rounded rectangles by drawing circles with regards to arbitrary p-norms [1,2] – I did not think about it at the time, but the derivatives are probably quite nice. (It did have the advantage of using the same code for rounded rectangles and for circles.)
Pretty sure that's how squircles are supposed to be mathematically implemented—at least in the option based on superellipses: https://en.wikipedia.org/wiki/Squircle