Ejemplo n.º 1
0
        private static void OnPathSegment(CsPotrace.Curve Curve, double oX, double oY, double scale, List <string> rv, Graphics g)
        {
            if (double.IsNaN(Curve.LinearLenght))             // problem?
            {
                return;
            }

            if (Curve.Kind == CsPotrace.CurveKind.Line)
            {
                //trace line
                if (g != null)
                {
                    g.DrawLine(Pens.DarkGray, (float)Curve.A.X, (float)Curve.A.Y, (float)Curve.B.X, (float)Curve.B.Y);
                }

                rv.Add(String.Format("G1 X{0} Y{1}", formatnumber(Curve.B.X + oX, scale), formatnumber(Curve.B.Y + oY, scale)));
            }

            if (Curve.Kind == CsPotrace.CurveKind.Bezier)
            {
                CubicBezier cb = new CubicBezier(new Vector2((float)Curve.A.X, (float)Curve.A.Y),
                                                 new Vector2((float)Curve.ControlPointA.X, (float)Curve.ControlPointA.Y),
                                                 new Vector2((float)Curve.ControlPointB.X, (float)Curve.ControlPointB.Y),
                                                 new Vector2((float)Curve.B.X, (float)Curve.B.Y));

                if (g != null)
                {
                    g.DrawBezier(Pens.Green,
                                 AsPointF(cb.P1),
                                 AsPointF(cb.C1),
                                 AsPointF(cb.C2),
                                 AsPointF(cb.P2));
                }

                try
                {
                    List <BiArc> bal = Algorithm.ApproxCubicBezier(cb, 5, 2);
                    foreach (BiArc ba in bal)
                    {
                        if (!double.IsNaN(ba.A1.Length) && !double.IsNaN(ba.A1.LinearLength))
                        {
                            rv.Add(GetArcGC(ba.A1, oX, oY, scale, g));
                        }

                        if (!double.IsNaN(ba.A2.Length) && !double.IsNaN(ba.A2.LinearLength))
                        {
                            rv.Add(GetArcGC(ba.A2, oX, oY, scale, g));
                        }
                    }
                }
                catch
                {
                    if (g != null)
                    {
                        g.DrawLine(Pens.DarkGray, (float)Curve.A.X, (float)Curve.A.Y, (float)Curve.B.X, (float)Curve.B.Y);
                    }
                    rv.Add(String.Format("G1 X{0} Y{1}", formatnumber(Curve.B.X + oX, scale), formatnumber(Curve.B.Y + oY, scale)));
                }
            }
        }
Ejemplo n.º 2
0
        private static string  GetHolePath(CsPotrace.Curve[] Curves)
        {
            StringBuilder path = new StringBuilder();

            for (int i = Curves.Length - 1; i >= 0; i--)
            {
                CsPotrace.Curve Curve = Curves[i];


                if (i == Curves.Length - 1)
                {
                    path.AppendLine("M" + Curve.B.X.ToString("0.0", enUsCulture) + " " + Curve.B.Y.ToString("0.0", enUsCulture));
                }

                if (Curve.Kind == CsPotrace.CurveKind.Bezier)
                {
                    path.Append("C" + Curve.ControlPointB.X.ToString("0.0", enUsCulture) + " " + Curve.ControlPointB.Y.ToString("0.0", enUsCulture) + " " +
                                Curve.ControlPointA.X.ToString("0.0", enUsCulture) + " " + Curve.ControlPointA.Y.ToString("0.0", enUsCulture) + " " +
                                Curve.A.X.ToString("0.0", enUsCulture) + " " + Curve.A.Y.ToString("0.0", enUsCulture));
                }
                if (Curve.Kind == CsPotrace.CurveKind.Line)
                {
                    path.Append("L" + Curve.B.X.ToString("0.0", enUsCulture) + " " + Curve.B.Y.ToString("0.0", enUsCulture));
                }
                if (i == 0)
                {
                    path.Append("Z");
                }
                else
                {
                    path.AppendLine("");
                }
            }



            return(path.ToString());
        }