public static Line GetUnionLine([NotNull] this List <Line> lines) { using var wasteLines = new DisposableSet <Line>(); Line prew = null !; Line?unionLine = null; foreach (var l in lines) { if (prew == null) { prew = l; continue; } var line = prew.GetUnionLine(l); wasteLines.Add(line); unionLine = prew; prew = line; } if (unionLine == null) { return((Line)prew.Clone()); } wasteLines.Remove(prew); return(prew); }
public static Hatch CreateHatch(this Region region, bool createOut, [CanBeNull] out DisposableSet <Polyline> externalLoops) { externalLoops = createOut ? new DisposableSet <Polyline>() : null; var plsByLoop = region.GetPoints2dByLoopType(); var extLoops = plsByLoop.Where(p => p.Value != BrepLoopType.LoopInterior).ToList(); var intLoops = plsByLoop.Where(p => p.Value == BrepLoopType.LoopInterior).ToList(); if (!extLoops.Any()) { return(null); } var h = new Hatch(); h.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); foreach (var item in extLoops) { var pts2dCol = item.Key; pts2dCol.Add(item.Key[0]); h.AppendLoop(HatchLoopTypes.External, pts2dCol, new DoubleCollection(new double[extLoops.Count + 1])); if (createOut) { externalLoops.Add(pts2dCol.Cast <Point2d>().ToList().CreatePolyline()); } } if (intLoops.Any()) { foreach (var item in intLoops) { var pts2dCol = item.Key; pts2dCol.Add(item.Key[0]); h.AppendLoop(HatchLoopTypes.SelfIntersecting, pts2dCol, new DoubleCollection(new double[intLoops.Count + 1])); } } h.EvaluateHatch(true); return(h); }