Interesting. Just seeing it gives me nightmares... what memories?. Years ago that's what you had to do when programming videogames. I myself made a billiards videogame and I had to carry out all these checks (circle-circle, circle-line, circle - polygon), and not only that, because for an exact collision, mandatory in a billiards simulation, when one solid is inside another (in one physics step there is no contact, and in the next one there is one solid inside another one) you have to find the exact point of collision so that the resulting vectors are correct...
Nowadays there are physics engines that incorporate all these calculations and make the programmer's life easier