The rectangles won't intersect, which is why I made a 1D function.

This is used to align the arrow on the popover in the above screenshot. The incoming rectangles are the frame of the popover and the frame of the button they originate from. They're guaranteed to be adjacent and to not overlap. The intent is to center the arrow under the button or over the popover, depending on which is smaller.