public static List <Polyline> Boolean(ClipType clipType, IEnumerable <Polyline> polyA, IEnumerable <Polyline> polyB, Plane pln, double tolerance, bool evenOddFilling) { NGonsCore.Clipper642.Clipper clipper = new NGonsCore.Clipper642.Clipper(); PolyFillType polyfilltype = PolyFillType.pftEvenOdd; if (!evenOddFilling) { polyfilltype = PolyFillType.pftNonZero; } foreach (Polyline plA in polyA) { clipper.AddPath(plA.ToPath2D(pln, tolerance), PolyType.ptSubject, plA.IsClosed); } foreach (Polyline plB in polyB) { clipper.AddPath(plB.ToPath2D(pln, tolerance), PolyType.ptClip, true); } PolyTree polytree = new PolyTree(); clipper.Execute(clipType, polytree, polyfilltype, polyfilltype); List <Polyline> output = new List <Polyline>(); // ReSharper disable once LoopCanBeConvertedToQuery foreach (PolyNode pn in polytree.Iterate()) { if (pn.Contour.Count > 1) { output.Add(pn.Contour.ToPolyline(pln, tolerance, !pn.IsOpen)); } } return(output); }
public static Tuple <List <Polyline>, List <Polyline>, List <Polyline> > BooleanIntersection(List <Curve> curves, List <Curve> cutters, double dist, double scale = 1e10) { //http://www.angusj.com/delphi/clipper/documentation/Docs/Overview/Example.htm // A = NGonsCore.Geometry.Polyline3D.Boolean(ClipType.ctIntersection, polylines, cutters, Plane.WorldXY, 1 / 1e10, true); //this.Component.Message = "Boolean Intersection"; List <Polyline> output = new List <Polyline>(); List <Polyline> cutters_ = CurvesToPolylines(cutters, dist); List <Polyline> innerPolygons = new List <Polyline>(); List <Polyline> edgePolygons = new List <Polyline>(); List <Polyline> edgePolygons_ = new List <Polyline>(); for (int j = 0; j < curves.Count; j++) { Polyline polyline = CurveToPolyline(curves[j]); NGonsCore.Clipper642.Clipper clipper = new NGonsCore.Clipper642.Clipper(); var cutter = PolylineToIntPoints(cutters_, scale); clipper.AddPaths(cutter, PolyType.ptClip, true); var input = PolylineToIntPoint(polyline, scale); clipper.AddPath(input, PolyType.ptSubject, true); /* * foreach(IntPoint intpt in input){ * NGonsCore.Clipper642.Clipper.PointInPolygon(intpt, cutter); * } */ List <List <IntPoint> > solution = new List <List <IntPoint> >(); clipper.Execute(ClipType.ctIntersection, solution); solution = NGonsCore.Clipper642.Clipper.SimplifyPolygons(solution, PolyFillType.pftEvenOdd); List <Polyline> polys = IntPointToPolylines(solution, scale); output.AddRange(polys); if (polys.Count > 0) { if (polys.Count == polyline.Count) { edgePolygons.AddRange(polys); edgePolygons_.Add(polyline); } else { if (Math.Abs((polys[0].Length - polyline.Length)) < 0.01 && polys[0].Count == polyline.Count) { innerPolygons.Add(polys[0]); //innerPolygons.Add(j); } else { edgePolygons.AddRange(polys); edgePolygons_.Add(polyline); // edgePolygons.Add(j); } } } } //innerPolylines = innerPolygons; //edgePolylinesCut = edgePolygons; //edgePolylines = edgePolygons_; // A = cutters_; return(new Tuple <List <Polyline>, List <Polyline>, List <Polyline> >(innerPolygons, edgePolygons, edgePolygons_)); }