I'm looking for the optimal algorithm in Swift 3x or 4 to determine if there are any clusters of like-colored balls in a bin. I need to make this calculation many times per second on iOS so would it be appropriate to use the accelerate framework? I'm not sure how to approach this problem.
given a bin full of balls, in dynamic motion, I would like, for example, to be able to apply number labels to the balls as in this diagram.
the numbers would animate, updating in each frame, to identify the size of their cluster.
there would be a reasonable finite distance, such as r * 1.1 for including a neighboring ball in a given cluster.
the clusters of balls could go into an array of clusters, perhaps...
I liked the idea in the comments below with bucket container nodes, but the comment is reminiscent of Fermat. Could anybody elaborate on that in swift code?
