public bool Compute() { if (InsetFromInputPolygon) { double inset = ToolWidth * InsetFromInputPolygonX; var current = ClipperUtil.ComputeOffsetPolygon(Polygon, -inset, true); foreach (var poly in current) { FillCurveSet2d fillPaths = ComputeFillPaths(poly); if (fillPaths != null) { FillCurves.Add(fillPaths); } } } else { FillCurveSet2d fillPaths = ComputeFillPaths(Polygon); if (fillPaths != null) { FillCurves.Add(fillPaths); } } return(true); }
public bool Compute() { if (InsetFromInputPolygon) { //BoundaryPolygonCache = new SegmentSet2d(Polygon); List <GeneralPolygon2d> current = ClipperUtil.ComputeOffsetPolygon(Polygon, -ToolWidth / 2, true); foreach (GeneralPolygon2d poly in current) { FillCurveSet2d fillPaths = ComputeFillPaths(poly); if (fillPaths != null) { FillCurves.Add(fillPaths); } } } else { List <GeneralPolygon2d> boundary = ClipperUtil.ComputeOffsetPolygon(Polygon, ToolWidth / 2, true); //BoundaryPolygonCache = new SegmentSet2d(boundary); FillCurveSet2d fillPaths = ComputeFillPaths(Polygon); if (fillPaths != null) { FillCurves.Add(fillPaths); } } return(true); }
public List <FillPolyline2d> thin_offset(GeneralPolygon2d p) { List <FillPolyline2d> result = new List <FillPolyline2d>(); // to support non-hole thin offsets we need to return polylines if (p.Holes.Count == 0) { return(result); } // compute desired offset from outer polygon GeneralPolygon2d outer = new GeneralPolygon2d(p.Outer); List <GeneralPolygon2d> offsets = ClipperUtil.ComputeOffsetPolygon(outer, -ToolWidth, true); if (offsets == null || offsets.Count == 0) { return(result); } double clip_dist = ToolWidth * ToolWidthClipMultiplier; foreach (GeneralPolygon2d offset_poly in offsets) { List <FillPolyline2d> clipped = clip_to_band(offset_poly.Outer, p, clip_dist); result.AddRange(clipped); } return(result); }
public bool Compute() { if (InsetFromInputPolygon) { BoundaryPolygonCache = new SegmentSet2d(Polygon); List <GeneralPolygon2d> current = ClipperUtil.ComputeOffsetPolygon(Polygon, -ToolWidth / 2, true); foreach (GeneralPolygon2d poly in current) { SegmentSet2d polyCache = new SegmentSet2d(poly); Paths.Add(ComputeFillPaths(poly, polyCache)); } } else { List <GeneralPolygon2d> boundary = ClipperUtil.ComputeOffsetPolygon(Polygon, ToolWidth / 2, true); BoundaryPolygonCache = new SegmentSet2d(boundary); SegmentSet2d polyCache = new SegmentSet2d(Polygon); Paths.Add(ComputeFillPaths(Polygon, polyCache)); } return(true); }
public bool Compute() { bool enable_thin_check = false; double thin_check_offset = ToolWidth * 0.45; double thin_check_thresh_sqr = ToolWidth * 0.3; thin_check_thresh_sqr *= thin_check_thresh_sqr; // first shell is either polygon, or inset from that polygon List <GeneralPolygon2d> current = null; if (InsetFromInputPolygonX != 0) { current = ComputeInitialInsetPolygon(PreserveInputInsetTopology); } else { current = new List <GeneralPolygon2d>() { Polygon }; } List <GeneralPolygon2d> current_prev = null; if (current.Count == 0) { HandleTinyPolygon(); return(true); } // convert previous layer to shell, and then compute next layer List <GeneralPolygon2d> failedShells = new List <GeneralPolygon2d>(); List <GeneralPolygon2d> nextShellTooThin = new List <GeneralPolygon2d>(); for (int i = 0; i < Layers; ++i) { FillCurveSet2d paths = ShellPolysToPaths(current, i); Shells.Add(paths); List <GeneralPolygon2d> all_next = new List <GeneralPolygon2d>(); foreach (GeneralPolygon2d gpoly in current) { List <GeneralPolygon2d> offsets = ClipperUtil.ComputeOffsetPolygon(gpoly, -PathSpacing, true); List <GeneralPolygon2d> filtered = new List <GeneralPolygon2d>(); foreach (var v in offsets) { bool bTooSmall = (v.Perimeter < DiscardTinyPerimterLengthMM || v.Area < DiscardTinyPolygonAreaMM2); if (bTooSmall) { continue; } if (enable_thin_check && is_too_thin(v, thin_check_offset, thin_check_thresh_sqr)) { nextShellTooThin.Add(v); } else { filtered.Add(v); } } if (filtered.Count == 0) { failedShells.Add(gpoly); } else { all_next.AddRange(filtered); } } current_prev = current; current = all_next; } // failedShells have no space for internal contours. But // we might be able to fit a single line... //foreach (GeneralPolygon2d gpoly in failedShells) { // if (gpoly.Perimeter < DiscardTinyPerimterLengthMM || // gpoly.Area < DiscardTinyPolygonAreaMM2) // continue; // List<FillPolyline2d> thin_shells = thin_offset(gpoly); // Shells[Shells.Count - 1].Append(thin_shells); //} // remaining inner polygons if (InsetInnerPolygons) { InnerPolygons = current; InnerPolygons.AddRange(nextShellTooThin); } else { InnerPolygons = current_prev; InnerPolygons.AddRange(nextShellTooThin); } return(true); }