1

I've a series of labels and icons inside the screen. A label is on the right of corresponding icon.

I must perform a sort of declutter: when two or more labels overlap each other (or a label with an icon), the label must be moved in free space. This for every label. I must move all overlapping labels in order that at the end of calculus there's no more overlapping label/label and label/icon.

I stored all labels in a list and I've tried to create a cycle in which I move a label in a rectangular spiral (centered on its icon), until it stays in free space, then fix it there and move the next label. The problem is that this algorithm is very slow and inefficient (algorithm should work in real time).

How should I organize the labels, and what algorithm I can use in order to rearrange labels?

Jepessen
  • 123
  • 6
  • 1
    I'm not sure if I should/how to mark a duplicate found on SO, but there is an exact duplicate [here](http://stackoverflow.com/questions/3265986/an-algorithm-to-space-out-overlapping-rectangles) - the question and answer are described in detail with nice graphics and code. – J Trana Oct 16 '15 at 04:03

0 Answers0