internal List <PolyLine> Offset(double margin, int v) { List <PolyLine> Res = new List <PolyLine>(); Polygons clips = new Polygons(); Polygon b = this.toPolygon(); clips.Add(b); Polygons clips2 = Clipper.OffsetPolygons(clips, margin * 100000.0f, JoinType.jtRound); foreach (var r in clips2) { PolyLine PLR = new PolyLine(v++); PLR.fromPolygon(r); Res.Add(PLR); } return(Res); }
public List <PolyLine> CreatePolyLineSet(double X, double Y, int ShapeID, double rotation, double scale, GerberParserState.MirrorMode mirrored) { List <PolyLine> Res = new List <PolyLine>(); if (Parts.Count > 0) { List <PolyLine> ResPre = new List <PolyLine>(); List <PolyLine> ResPreNeg = new List <PolyLine>(); foreach (var a in Parts.Where(x => x.Polarity == true)) { ResPre.AddRange(a.CreatePolyLineSet(0, 0, ShapeID, 0, 1, GerberParserState.MirrorMode.NoMirror)); } foreach (var a in Parts.Where(x => x.Polarity == false)) { ResPreNeg.AddRange(a.CreatePolyLineSet(0, 0, ShapeID, 0, 1, GerberParserState.MirrorMode.NoMirror)); } Polygons Combined = new Polygons(); Polygons Solution = new Polygons(); Polygons clips = new Polygons(); if (ResPreNeg.Count == 0) { foreach (var c in ResPre) { // c.CheckIfHole(); //clips.Add(c.toPolygon()); //cp.AddPolygons(clips, PolyType.ptClip); //cp.Execute(ClipType.ctUnion, Combined, PolyFillType.pftNonZero, PolyFillType.pftEvenOdd); Solution.Add(c.toPolygon()); } foreach (var p in Solution) { PolyLine PL = new PolyLine(ShapeID); PL.fromPolygon(p); Res.Add(PL); } } else { foreach (var c in ResPreNeg) { // c.CheckIfHole(); //clips.Add(c.toPolygon()); //cp.AddPolygons(clips, PolyType.ptClip); //cp.Execute(ClipType.ctUnion, Combined, PolyFillType.pftNonZero, PolyFillType.pftEvenOdd); clips.Add(c.toPolygon()); } foreach (var c in ResPre) { // c.CheckIfHole(); //clips.Add(c.toPolygon()); //cp.AddPolygons(clips, PolyType.ptClip); //cp.Execute(ClipType.ctUnion, Combined, PolyFillType.pftNonZero, PolyFillType.pftEvenOdd); Combined.Add(c.toPolygon()); } Clipper cp = new Clipper(); cp.AddPolygons(Combined, PolyType.ptClip); cp.AddPolygons(clips, PolyType.ptSubject); cp.Execute(ClipType.ctDifference, Solution, PolyFillType.pftNonZero, PolyFillType.pftNonZero); foreach (var p in Solution) { PolyLine PL = new PolyLine(ShapeID); PL.fromPolygon(p); Res.Add(PL); } } } else { if (Shape.Count() > 0) { var PL = new PolyLine(ShapeID); for (int i = 0; i < Shape.Count(); i++) { PL.Add(Shape.Vertices[i].X, Shape.Vertices[i].Y); } PL.Add(Shape.Vertices[0].X, Shape.Vertices[0].Y); PL.Close(); Res.Add(PL); } else { if (Gerber.ShowProgress) { Console.WriteLine("creating empty shape?? {0} {1}", MacroName, ShapeType); } } } if (rotation != 0 || scale != 1 || mirrored != GerberParserState.MirrorMode.NoMirror) { double CA = Math.Cos((rotation * Math.PI * 2) / 360.0); double SA = Math.Sin((rotation * Math.PI * 2) / 360.0); double xscale = scale; double yscale = scale; switch (mirrored) { case GerberParserState.MirrorMode.X: xscale = -xscale; break; case GerberParserState.MirrorMode.XY: xscale = -xscale; yscale = -yscale; break; case GerberParserState.MirrorMode.Y: yscale = -yscale; break; } foreach (var a in Res) { foreach (var p in a.Vertices) { double Xin = p.X; double Yin = p.Y; double nX = Xin * CA - Yin * SA; double nY = Xin * SA + Yin * CA; p.X = nX * xscale; p.Y = nY * yscale; } } } foreach (var a in Res) { foreach (var p in a.Vertices) { p.X += X; p.Y += Y; } } return(Res); }
public List <PolyLine> CreatePolyLineSet(double X, double Y, int ShapeID) { List <PolyLine> Res = new List <PolyLine>(); if (Parts.Count > 0) { List <PolyLine> ResPre = new List <PolyLine>(); foreach (var a in Parts) { ResPre.AddRange(a.CreatePolyLineSet(X, Y, ShapeID)); } Polygons Combined = new Polygons(); Polygons clips = new Polygons(); foreach (var c in ResPre) { // c.CheckIfHole(); //Clipper cp = new Clipper(); //cp.AddPolygons(Combined, PolyType.ptSubject); //clips.Add(c.toPolygon()); //cp.AddPolygons(clips, PolyType.ptClip); //cp.Execute(ClipType.ctUnion, Combined, PolyFillType.pftNonZero, PolyFillType.pftEvenOdd); Combined.Add(c.toPolygon()); } foreach (var p in Combined) { PolyLine PL = new PolyLine(ShapeID); PL.fromPolygon(p); Res.Add(PL); } } else { if (Shape.Count() > 0) { var PL = new PolyLine(ShapeID); for (int i = 0; i < Shape.Count(); i++) { PL.Add(X + Shape.Vertices[i].X, Y + Shape.Vertices[i].Y); } PL.Add(X + Shape.Vertices[0].X, Y + Shape.Vertices[0].Y); PL.Close(); Res.Add(PL); } else { if (Gerber.ShowProgress) { Console.WriteLine("creating empty shape?? {0} {1}", MacroName, ShapeType); } } } return(Res); }