This project is read-only.
1
Vote

Error when computing Voronoi diagram

description

Sometimes when I call VoronoiMesh.Create method, it throws following exception:
System.ArgumentOutOfRangeException was unhandled
  HResult=-2146233086
  Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  Source=mscorlib
  ParamName=index
  StackTrace:
       at System.Collections.Generic.List`1.get_Item(Int32 index)
       at MIConvexHull.ConvexHullInternal.SortAndRemoveRepeats() in d:\Projects\Programming Experiments\F#\VoronoiMosaic\Lib\MIConvexHull\MIConvexHull\ConvexHull\ConvexHullInternal.cs:line 961
       at MIConvexHull.ConvexHullInternal.InitConvexHull(Boolean removeDuplicates) in d:\Projects\Programming Experiments\F#\VoronoiMosaic\Lib\MIConvexHull\MIConvexHull\ConvexHull\ConvexHullInternal.cs:line 712
       at MIConvexHull.ConvexHullInternal.FindConvexHull(Boolean removeDuplicates) in d:\Projects\Programming Experiments\F#\VoronoiMosaic\Lib\MIConvexHull\MIConvexHull\ConvexHull\ConvexHullInternal.cs:line 887
       at MIConvexHull.ConvexHullInternal.GetConvexHullInternal[TVertex](Boolean onlyCompute) in d:\Projects\Programming Experiments\F#\VoronoiMosaic\Lib\MIConvexHull\MIConvexHull\ConvexHull\ConvexHullInternal.cs:line 1022
       at MIConvexHull.ConvexHullInternal.GetConvexFacesInternal[TVertex,TFace](IEnumerable`1 data) in d:\Projects\Programming Experiments\F#\VoronoiMosaic\Lib\MIConvexHull\MIConvexHull\ConvexHull\ConvexHullInternal.cs:line 1096
       at MIConvexHull.DelaunayTriangulation`2.Create(IEnumerable`1 data) in d:\Projects\Programming Experiments\F#\VoronoiMosaic\Lib\MIConvexHull\MIConvexHull\Triangulation\DelaunayTriangulation.cs:line 46
       at MIConvexHull.VoronoiMesh`3.Create(IEnumerable`1 data) in d:\Projects\Programming Experiments\F#\VoronoiMosaic\Lib\MIConvexHull\MIConvexHull\Triangulation\VoronoiMesh.cs:line 116
       at MIConvexHull.VoronoiMesh.Create[TVertex,TCell,TEdge](IEnumerable`1 data) in d:\Projects\Programming Experiments\F#\VoronoiMosaic\Lib\MIConvexHull\MIConvexHull\Triangulation\VoronoiMesh.cs:line 25
       at VoronoiMosaic.OpenGLPart.RenderFancy(Vector2[] sites, Bitmap bitmap) in D:\Projects\Programming Experiments\F#\VoronoiMosaic\VoronoiMosaic\OpenGLPart.fs:line 263
...
It tries to access element of InputVertices with index == InputVertices.Length.
The bug occurs once in a while, and I haven't noticed any special characterisitcs of input data that are likely to trigger it.

comments

webwarrior0 wrote Apr 6, 2013 at 2:01 PM

I've figured out the cause of this error. It's duplicates in input data.
However, it would be nice to throw more informative exception, so that user knows what's wrong.

mattica wrote Apr 10, 2013 at 9:31 PM

Yes, thanks. We have a better way to handle repeated vertices now. It may be quicker and more robust than the version you commented on (v.53). Please try version 55 or greater.