mapbox / delaunator

An incredibly fast JavaScript library for Delaunay triangulation of 2D points
https://mapbox.github.io/delaunator/
ISC License
2.24k stars 139 forks source link

C# version crash out of range array on hullash #74

Closed w77 closed 2 years ago

w77 commented 2 years ago

hi,

I made a C# version of delaunator but I have the following error with large vertex count. Does it happen to you too ? the error :

index parameter is out of range : -128 -2,147484E+09

so key is -2,147484E+09 and aze is -128

at lines 190 in your code

The code ` key = hashKey(x, y); for (int j = 0; j < hashSize; j++) { try { aze = (int)Math.Round((key + j) % hashSize); start = hullHash[aze];

                }
                catch(IndexOutOfRangeException ex)
                {
                    // Set IndexOutOfRangeException to the new exception's InnerException.
                    Debug.LogError("index parameter is out of range : " + aze + " " + key);
                    throw new ArgumentOutOfRangeException("index parameter is out of range : " + aze, ex);
                }

                if (start != -1 && start != hullNext[start]) break;
            }

`

EDIT : I am using float coords instead of int, maybe it breaks the hash code. EDIT 2 : I made some tests with only 1000 vertices and it happens too frome time to time, again with E+09 float hash.

w77 commented 2 years ago

More : x and y are -infinity :/

mourner commented 2 years ago

Does not happen in JS version, so I'm going to close this unless you can provide a reproducible test case, and assume that's an issue with your ported code.