Is there a way to generalize the overlaps in these boxes with a curve?

I’m essentially trying to having each of these boxes touching at their ends with no overlap or gaps, but am struggling to think of a solution. I’ll attach an image and copy of my script below, essentially the objects are placed there from a galapagos optimization. (32.6 KB)