How to detect if two objects become a square ?

Hello, i want to detect if two rectangle gb or four mini square or both ways, they become a big square. I am new and out of idea, can you suggest any doc or video ? anything is fine, thank you.
To more visualise, i have some geometric objects in my scene and they can be merged. If player merged them like in tetris, but in 3d and has to be square shape, and thus player will earn points.

You could calculate the bounding box size of an array of renderers.