I am building a library to visually drag and sort elements. As I’m dragging an element, I move a placeholder around. The thing is, the placeholder may be among various elements which could be on multiple “lines” which wrap. I am assuming here the elements are laid out horizontally in lines that wrap (so I’m ignoring flexbox with vertical layouts and wraparounds etc.)
So basically, as the pointer moves I compare the element under the pointer, with the placeholder. If they’re on the same line, then I can use a horizontal test to know when to swap the placeholder and the target.
If they’re not on the same line, though, I would need to make some vertical tests, instead. But how can I tell these things? I guess I can see if they are “right next to each other”, and then assume that they are on the same line, but what if they wrapped around?
Currently I’m just testing whether their bounding rectangles intersect in the vertical space, but there could be some edge cases where they’re on the same line but don’t intersect, like one being vertical-align: top and one vertical-align: bottom and they’re pretty small.
Anyway, this is just for edge cases.