DesignEngrLab / MIConvexHull

A .Net fast convex hull library for 2, 3, and higher dimensions.
http://designengrlab.github.io/MIConvexHull/
MIT License
341 stars 60 forks source link

DetermineDimension() out of range #5

Closed ANTONBORODA closed 8 years ago

ANTONBORODA commented 8 years ago

Hello. There seems to an issue with DetermineDimension() in ConvexHullAlgorithm.Initialize.cs. It uses NumberOfVertices as an indexer: dimensions.Add(Vertices[r.Next(NumberOfVertices)].Position.Length); which is taken from array length of input. If random produces a maximum number - an out of range exception will be produced because array indexer is 0 based. It probably should be dimensions.Add(Vertices[r.Next(NumberOfVertices-1)].Position.Length);

Thank you.

micampbell commented 8 years ago

I don't believe it is necessary to add the "-1" as Random.Next is exclusive of the upper-bound (https://msdn.microsoft.com/en-us/library/zd1bc8e5(v=vs.110).aspx). If you did get this error, I'd be curious to understand why. Maybe one of your vertices is null (?).

ANTONBORODA commented 8 years ago

I got out of range exception running latest NuGet package in IIS environment. After adding -1 - error was never observed again with the same data set. Vertex might be null, I'll verify the input data just to make sure.

ANTONBORODA commented 8 years ago

I am sorry, this was related to our code.