ogxd / kmeans-clustering-unity

2D and 3D clustering in Unity using k-means
Other
46 stars 9 forks source link

IndexOutOfRangeException: Index was outside the bounds of the array. #2

Open Shadercloud opened 1 year ago

Shadercloud commented 1 year ago

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]];
        }
ogxd commented 1 year ago

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