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

Why randomly failed to generate with same 3D vertices? #36

Closed haruby511 closed 5 years ago

haruby511 commented 5 years ago

I have generated several convex hulls with various meshes. It works fine in most cases but sometimes unknown error returned from Create(). Because of ArgumentException it tells key duplication of a dictionary or hashmap.

Strange thing is that if try to generate again, generation being success even though passing same vertices what was used in previous call.

List<double[]> sources = new List<double[]>(sourcePositions.Count);
sources.AddRange(from p in sourcePositions select new double[] { p.X, p.Y, p.Z });
ConvexHullCreationResult<DefaultVertex, DefaultConvexFace<DefaultVertex>> result = ConvexHull.Create(sources); // Sometimes fail.
if (null == result.Result)
{
    System.Diagnostics.Debug.WriteLine(result.ErrorMessage);
    result = ConvexHull.Create(sources); // Almost success.
}

I'm using NuGet and the Create() catch all of exceptions so I cannot provide more information such as stack trace. I think, removing that catch is better if you don't have proper solution.

micampbell commented 5 years ago

I just pushed a new nuget version (1.1.19.1018). This should - at least - remove the randomness that you are seeing. I don't know that I managed to fix the problem you were having, but if you can now capture the problem cases that are causing errors and send the vertices my way, then I would appreciate it. I hear what your are saying about catching all exceptions. I'm not necessarily a fan of this either, but members of the community wanted it that way.

haruby511 commented 5 years ago

I just updated. I seems the issue has been fixed. Thanks for your efforts.

How about adding a Exception member in the ConvexHullCreationResult<> for caught exception?

micampbell commented 5 years ago

yes, that's a good idea.