Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConvexHull calculation fails with GeoVectorException #69

Open
dsn27 opened this issue Jan 14, 2022 · 0 comments
Open

ConvexHull calculation fails with GeoVectorException #69

dsn27 opened this issue Jan 14, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@dsn27
Copy link
Collaborator

dsn27 commented Jan 14, 2022

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 dsn27 added the bug Something isn't working label Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants