internal void SetMultiQuadrantMode() { CurrentQuadrantMode = GerberQuadrantMode.Multi; if (Gerber.ShowProgress) { Console.WriteLine("QuadrantMode: Multi"); } }
internal void SetSingleQuadrantMode() { CurrentQuadrantMode = GerberQuadrantMode.Single; if (Gerber.ShowProgress) { Console.WriteLine("QuadrantMode: Single"); } }
public static List <PointD> CreateCurvePoints(double LastX, double LastY, double X, double Y, double I, double J, InterpolationMode mode, GerberQuadrantMode qmode) { // Console.WriteLine("Current curve mode: {0}", qmode); List <PointD> R = new List <PointD>(); double Radius = Math.Sqrt(I * I + J * J); double CX = LastX + I; double CY = LastY + J; Quadrant Q = Quadrant.xposypos; double HS = Math.Atan2(LastY - CY, LastX - CX); double HE = Math.Atan2(Y - CY, X - CX); if (qmode == GerberQuadrantMode.Multi) { if (mode == InterpolationMode.ClockWise) { while (HS <= HE) { HS += Math.PI * 2; } } else { while (HS >= HE) { HS -= Math.PI * 2; } } } else { double LastDiff = Math.PI * 2; List <QuadR> qR = new List <QuadR>(); qR.Add(new QuadR() { CX = LastX + I, CY = LastY + J }); qR.Add(new QuadR() { CX = LastX - I, CY = LastY + J }); qR.Add(new QuadR() { CX = LastX - I, CY = LastY - J }); qR.Add(new QuadR() { CX = LastX + I, CY = LastY - J }); foreach (var a in qR) { a.Calc(LastX, LastY, X, Y); } int candidates = 0; if (Gerber.ExtremelyVerbose) { var DX = LastX - X; var DY = LastY - Y; var L = Math.Sqrt(DX * DX + DY * DY); if (L < 1.0) { R.Add(new PointD(X, Y)); return(R); } Console.WriteLine("length: {0}", L); } if (mode == InterpolationMode.CounterClockwise) { double LastRat = 10; foreach (var a in qR) { a.FixCounterClockwise(); } foreach (var a in qR) { if (a.Diff <= Math.PI / 2.0) { candidates++; if (Math.Abs(1 - a.DRat) < LastRat) { CX = a.CX; CY = a.CY; HS = a.S; HE = a.E; LastRat = Math.Abs(1 - a.DRat); } if (Gerber.ExtremelyVerbose) { Console.WriteLine("candidate: {0:N1} - {1:N1} - {2:N1}", RadToDeg(a.S), RadToDeg(a.E), RadToDeg(a.Diff)); } } } /* * HS = qR[3].S; * CX = qR[3].CX; * CY = qR[3].CY; * HE = qR[3].E; */ } else { foreach (var a in qR) { a.FixClockwise(); } foreach (var a in qR) { if (a.Diff >= 0 && a.Diff <= Math.PI / 2.0 + 0.00001) { candidates++; if (Math.Abs(a.Diff) < LastDiff) { CX = a.CX; CY = a.CY; HS = a.S; HE = a.E; LastDiff = Math.Abs(a.Diff); } if (Gerber.ExtremelyVerbose) { Console.WriteLine("candidate: {0} - {1} - {2}", a.S, a.E, a.Diff); } } if (Gerber.ExtremelyVerbose) { Console.WriteLine("selected : {0} - {1} - {2}", HS, HE, LastDiff); } } } if (candidates == 0 && Gerber.ExtremelyVerbose) { foreach (var a in qR) { Console.WriteLine("no candidate: {0} - {1} - {2} ( should be smaller than {3}) ", a.S, a.E, a.Diff, Math.PI / 2.0); } } } if (Gerber.ExtremelyVerbose) { Console.WriteLine("HS {0:N1} HE {1:N1} DIFF {2:N1} QUAD {3} CX {4} CY {5}", RadToDeg(HS), RadToDeg(HE), RadToDeg(HE - HS), Q, CX, CY); } int segs = (int)(Gerber.ArcQualityScaleFactor * Math.Max(2.0, Radius) * Math.Abs(HS - HE) / (Math.PI * 2)); if (segs < 10) { segs = 10; } double HEdeg = RadToDeg(HE); double HSdeg = RadToDeg(HS); for (int i = 0; i <= segs; i++) { double P = ((double)i / (double)segs) * (HE - HS) + HS; double nx = Math.Cos(P) * Radius + CX; double ny = Math.Sin(P) * Radius + CY; R.Add(new PointD(nx, ny)); } // R.Add(new PointD(X, Y)); return(R); }