wo80 / Triangle.NET

C# / .NET version of Jonathan Shewchuk's Triangle mesh generator.
442 stars 81 forks source link

example 5 throws an exception #35

Closed berenfeld closed 1 year ago

berenfeld commented 1 year ago

just cloned the project as is and built the solution using VS2022 running the examples I got an exception on Example 5

the exception is gone if you remove the quality request (change to var mesh = poly.Triangulate(options); // , quality); in Example5)

System.Exception HResult=0x80131500 Message=The new vertex is at the circumcenter of triangle. Source=Triangle StackTrace: at TriangleNet.Meshing.QualityMesher.SplitTriangle(BadTriangle badtri) in C:\dev2\Triangle.NET\src\Triangle\Meshing\QualityMesher.cs:line 838 at TriangleNet.Meshing.QualityMesher.EnforceQuality() in C:\dev2\Triangle.NET\src\Triangle\Meshing\QualityMesher.cs:line 869 at TriangleNet.Meshing.QualityMesher.Apply(QualityOptions quality, Boolean delaunay) in C:\dev2\Triangle.NET\src\Triangle\Meshing\QualityMesher.cs:line 101 at TriangleNet.Meshing.GenericMesher.Triangulate(IPolygon polygon, ConstraintOptions options, QualityOptions quality) in C:\dev2\Triangle.NET\src\Triangle\Meshing\GenericMesher.cs:line 101 at TriangleNet.Geometry.ExtensionMethods.Triangulate(IPolygon polygon, ConstraintOptions options, QualityOptions quality) in C:\dev2\Triangle.NET\src\Triangle\Geometry\ExtensionMethods.cs:line 50 at TriangleNet.Examples.Example5.Run(Boolean print) in C:\dev2\Triangle.NET\src\Triangle.Examples\Examples\Example5.cs:line 38 at TriangleNet.Program.Main(String[] args) in C:\dev2\Triangle.NET\src\Triangle.Examples\Program.cs:line 18

wo80 commented 1 year ago

Thanks for pointing this out!

Commit https://github.com/wo80/Triangle.NET/commit/2a130cea742ac26da0990f34312f3cc406a68289 breaks the example. The correct fix would be to set the UseLegacyRefinement option. It seems the aCute algorithm doesn't play well with variable area constraints.

var quality = new QualityOptions()
{
    MinimumAngle = 25.0,
    VariableArea = true,
    UseLegacyRefinement = true
};