good use of the Pythagorean theorem :) was just looking at your code the only thing i saw missing was what if they overlap. the one you are over should pop to the top so i added this
...