kmeans-clustering-unity icon indicating copy to clipboard operation
kmeans-clustering-unity copied to clipboard

IndexOutOfRangeException: Index was outside the bounds of the array.

Open Shadercloud opened this issue 1 year ago • 1 comments

Sometimes I'm getting this error when trying to find Clusters on a Vector2[].

The error points to this line clusters[clustering[i]][clustersCurIdx[clustering[i]]] = i;, in the KMeans class.

int[] clustersCurIdx = new int[clusterCount];
        for (int i = 0; i < clustering.Length; i++) {
            clusters[clustering[i]][clustersCurIdx[clustering[i]]] = i;
            ++clustersCurIdx[clustering[i]];
        }

Shadercloud avatar Jun 23 '23 16:06 Shadercloud

Hi @Shadercloud. Thanks for the issue. I don't actively maintain this repository. Don't hesitate to file a PR if you've fixed it yourself

It looks like a floating point rounding issue at first glance

ogxd avatar Jun 23 '23 16:06 ogxd