I have a canvas where I can draw, resize and move rectangles around.
I'm looking for an algorithm to prevent overlap and enable snapping of the rectangle I'm editing with other rectangles.
I'm tried different approaches but I couldn't get one working properly.
All my approaches are based on a simple loop that check the rectangle I'm editing (E) with other rectangles (O[n]).
Preventing overlap is not the problem, my problem is snapping as it can modify E while iterating O.
For example, if I'm moving E near O[1] it will snap with it, but this snap might create an overlap with O[0], overlap that won't be checked.
Before I start doing something recursive or too naïve, I was wondering if anybody knew a better approach.