CADability icon indicating copy to clipboard operation
CADability copied to clipboard

ConvexHull calculation fails with GeoVectorException

Open dsn27 opened this issue 3 years ago • 0 comments

The calculation of a convex hull will fail with the attached DXF file. ConvexHullError.zip

Code:

var m = cadControl1.CadFrame.Project.GetActiveModel();

List<ICurve> curves = new List<ICurve>(m.AllObjects.Count);
foreach (IGeoObject geo in m.AllObjects)
    if (geo is ICurve geoCurve)
        curves.Add(geoCurve);

if (!Curves.GetCommonPlane(curves, out Plane pln))
    return;

List<ICurve2D> curves2D = new List<ICurve2D>(curves.Count);

foreach (ICurve curve in curves)
    curves2D.Add(curve.GetProjectedCurve(pln));

var cs = CompoundShape.CreateFromList(curves2D.ToArray(), 0.01, true, out GeoObjectList deads);

Path2D ssOutlines = cs.SimpleShapes[0].Outline.AsPath();
for (int i = 1; i < cs.SimpleShapes.Length; i++)
    ssOutlines = SimpleShape.ConnectPaths(ssOutlines, cs.SimpleShapes[i].Outline.AsPath());

//Create Convex Hull
var outlineBorder = ssOutlines.MakeBorder();
var hull = outlineBorder.ConvexHull();
CADability.GeoVectorException
  HResult=0x80131600
  Message=Error in application.
  Source=CADability
  StackTrace:
   at CADability.GeoVector2D.get_Normalized() in C:\Development\Repos\SOFAgh\CADability\CADability\GeoPoint.cs:line 1451
   at CADability.Curve2D.GeneralCurve2D.GetTriangulationBasis(GeoPoint2D[]& points, GeoVector2D[]& directions, Double[]& parameters) in C:\Development\Repos\SOFAgh\CADability\CADability\GeneralCurve2D.cs:line 1591
   at CADability.Curve2D.GeneralCurve2D.MakeTringulation() in C:\Development\Repos\SOFAgh\CADability\CADability\GeneralCurve2D.cs:line 1609
   at CADability.Curve2D.GeneralCurve2D.GetInflectionPoints() in C:\Development\Repos\SOFAgh\CADability\CADability\GeneralCurve2D.cs:line 2867
   at CADability.Shapes.Border.ConvexHull() in C:\Development\Repos\SOFAgh\CADability\CADability\Border.cs:line 4182
   at CADability.App.ChildMdiForm.button2_Click(Object sender, EventArgs e) in C:\Development\Repos\SOFAgh\CADability\CADability.App\ChildMdiForm.cs:line 64
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at CADability.App.Program.Main(String[] args) in C:\Development\Repos\SOFAgh\CADability\CADability.App\Program.cs:line 21

dsn27 avatar Jan 14 '22 17:01 dsn27