Just placing circles

I’m writing on an circle placing algorithm for my circle UI. Actually, i haven’t expected such big performance issues while properly placing some circles. 

In my test scene i create 500 circles

  • neighbored and of different size
  • placed as close as possible to center
  • but not within a restricted area (the empty round space)

My first attempt: 

v1.png

This took ~17 seconds, because it tried to find the really best place, testing all combinations. This means it needs exponential time, but also gives a perfect result.

 

 v2.png

This time, i set the maximum of checked circles to 70, because it gets slow at ~100 . It took less than a second to calculate and its close enough to my needs. No one will create this much circle ui elements. 

 

Just for fun, i set it to 10. Checking only the last 10 circles for a good place in the neighborhood. Just ~0.06 seconds later it shows this beautiful artifact.

v3.png

 

After all, this code isn’t fully optimized. Just compiled with GHC -O3 . Oh and since this is just a test, the code isn’t even well written. 😉