BrepTrim curves intersection with 2d lines (CurveLine intersection freezes)

Hi,
With the code below I want to cut a line (defined by 2 points in the xy plane) with the 2d curves of the BrepTrims of a BrepLoop. At the 2nd call of CurveLine(…) the program freezes. The Brep I use is a very simple one (see attached file). Does anyone have an idea?
I use Rhino 6 with RhinoCommonSimpleSurface.3dm (23.6 KB)

Regards
Jürgen

        double intersection_tolerance = 0.001;
        double overlap_tolerance = 0.0;

        Line line = new Line(new Point3d(-5, 8, 0), new Point3d(10, 1, 0));
        doc.Objects.AddLine(line);

        for (int i = 0; i < brep.Faces.Count; i++)
        {
            BrepFace bf = brep.Faces[i];
            Rhino.Geometry.Collections.BrepLoopList bll = bf.Loops;

            for (int j = 0; j < bll.Count; j++)
            {
                BrepLoop bl = bll[j];
                Rhino.Geometry.Collections.BrepTrimList btl = bl.Trims;

                for (int k = 0; k < btl.Count; k++)
                {
                    BrepTrim bt = btl[k];

                    Curve curve = bt.TrimCurve;
                    doc.Objects.AddCurve(curve);
                                            
                    var events = Rhino.Geometry.Intersect.Intersection.CurveLine(curve, line, intersection_tolerance, overlap_tolerance);

                    // Process the results
                    if (events != null)
                    {
                        for (int m = 0; m < events.Count; m++)
                        {
                            var ccx_event = events[m];
                            doc.Objects.AddPoint(ccx_event.PointA);
                            if (ccx_event.PointA.DistanceTo(ccx_event.PointB) > 1E-6)
                            {
                                doc.Objects.AddPoint(ccx_event.PointB);
                            }
                        }
                    }                       
                }
            }
        }
        doc.Views.Redraw();

Hello - I’m moving this to the developer forum.
https://discourse.mcneel.com/c/rhino-developer

-Pascal

Hi @juergen.holl,

Let me know if the attached is what you’re looking for.

– Dale

TestJuergen.cs (1.9 KB)

Hi Dale,
Yes, the DuplicateCurve and ChangeDimension to 3 resolves the problem. Thank you very much for your help.

  • Juergen