Exemplo n.º 1
0
        private static void AddSegmentToPath(Microsoft.Msagl.Splines.ICurve seg, ref System.Drawing.Drawing2D.GraphicsPath p)
        {
            const float radiansToDegrees = (float)(180.0 / Math.PI);

            Microsoft.Msagl.Splines.LineSegment line = seg as Microsoft.Msagl.Splines.LineSegment;
            if (line != null)
            {
                p.AddLine(PointF(line.Start), PointF(line.End));
            }
            else
            {
                Microsoft.Msagl.Splines.CubicBezierSegment cb = seg as Microsoft.Msagl.Splines.CubicBezierSegment;
                if (cb != null)
                {
                    p.AddBezier(PointF(cb.B(0)), PointF(cb.B(1)), PointF(cb.B(2)), PointF(cb.B(3)));
                }
                else
                {
                    Microsoft.Msagl.Splines.Ellipse ellipse = seg as Microsoft.Msagl.Splines.Ellipse;
                    if (ellipse != null)
                    {
                        p.AddArc((float)(ellipse.Center.X - ellipse.AxisA.Length), (float)(ellipse.Center.Y - ellipse.AxisB.Length),
                                 (float)(2 * ellipse.AxisA.Length), (float)(2 * ellipse.AxisB.Length), (float)(ellipse.ParStart * radiansToDegrees),
                                 (float)((ellipse.ParEnd - ellipse.ParStart) * radiansToDegrees));
                    }
                }
            }
        }
Exemplo n.º 2
0
 private static System.Drawing.Drawing2D.GraphicsPath FillTheGraphicsPath(Microsoft.Msagl.Splines.ICurve iCurve)
 {
     Microsoft.Msagl.Splines.Curve         curve = iCurve as Microsoft.Msagl.Splines.Curve;
     System.Drawing.Drawing2D.GraphicsPath path  = new System.Drawing.Drawing2D.GraphicsPath();
     foreach (Microsoft.Msagl.Splines.ICurve seg in curve.Segments)
     {
         AddSegmentToPath(seg, ref path);
     }
     return(path);
 }
Exemplo n.º 3
0
        static bool WithinEpsilon(Microsoft.Msagl.Splines.ICurve bc, double start, double end)
        {
            int    n = 3; //hack !!!!
            double d = (end - start) / n;
            P2     s = bc[start];
            P2     e = bc[end];

            return(DistToSegm(bc[start + d], s, e) < epsilon
                   &&
                   DistToSegm(bc[start + d * (n - 1)], s, e) < epsilon);
        }
Exemplo n.º 4
0
        internal static List <ObjectWithBox> TessellateCurve(DEdge dedge, double radiusForUnderlyingPolylineCorners)
        {
            DrawingEdge edge = dedge.DrawingEdge;

            Microsoft.Msagl.Splines.ICurve bc = edge.Attr.EdgeCurve;
            double lineWidth         = edge.Attr.LineWidth;
            List <ObjectWithBox> ret = new List <ObjectWithBox>();
            int  n = 1;
            bool done;

            do
            {
                double d = (bc.ParEnd - bc.ParStart) / (double)n;
                done = true;
                if (n <= 64)//don't break a segment into more than 64 parts
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (!WithinEpsilon(bc, d * i, d * (i + 1)))
                        {
                            n   *= 2;
                            done = false;
                            break;
                        }
                    }
                }
            }while (!done);

            double del = (bc.ParEnd - bc.ParStart) / n;

            for (int j = 0; j < n; j++)
            {
                Line line = new Line(dedge, bc[del * (double)j], bc[del * (double)(j + 1)], lineWidth);
                ret.Add(line);
            }

            //if (dedge.Label != null)
            //    ret.Add(new LabelGeometry(dedge.Label, edge.Label.Left,
            //                              edge.Label.Bottom, new P2(edge.Label.Size.Width, edge.Label.Size.Height)));


            if (edge.Attr.ArrowAtTarget)
            {
                ret.Add(new Line(dedge, (P2)edge.Attr.EdgeCurve.End, edge.Attr.ArrowAtTargetPosition, edge.Attr.LineWidth));
            }



            if (edge.Attr.ArrowAtSource)
            {
                ret.Add(
                    new Line(dedge, edge.Attr.EdgeCurve.Start, edge.Attr.ArrowAtSourcePosition, edge.Attr.LineWidth));
            }

            if (radiusForUnderlyingPolylineCorners > 0)
            {
                AddUnderlyingPolylineTessellation(ret, dedge, radiusForUnderlyingPolylineCorners);
            }

            return(ret);
        }