コード例 #1
0
        public override void AddToPath(IGraphicsPath graphicsPath)
        {
            var pathData = graphicsPath.PathData;
            var points   = pathData.Points;

            if (points.Length <= 0)
            {
                return;
            }

            // Important for custom line caps. Force the path the close with an explicit line, not just an implicit close of the figure.
            var last = points.Length - 1;

            if (!points[0].Equals(points[last]))
            {
                var i = last;
                while (i > 0 && pathData.Types[i] > 0)
                {
                    --i;
                }
                graphicsPath.AddLine(points[last], points[i]);
            }

            graphicsPath.CloseFigure();
        }
コード例 #2
0
        private static IGraphicsPath ConvertEnvelope(IDisplay display, IEnvelope envelope, IGraphicsPath gp)
        {
            double minx = envelope.minx, miny = envelope.miny;
            double maxx = envelope.maxx, maxy = envelope.maxy;

            display.World2Image(ref minx, ref miny);
            display.World2Image(ref maxx, ref maxy);

            gp.StartFigure();
            gp.AddLine((float)minx, (float)miny, (float)maxx, (float)miny);
            gp.AddLine((float)maxx, (float)miny, (float)maxx, (float)maxy);
            gp.AddLine((float)maxx, (float)maxy, (float)minx, (float)maxy);
            gp.CloseFigure();

            return(gp);
        }
コード例 #3
0
        /// <summary>
        ///     Draws this object to the <see cref="T:EscherTiler.Graphics.IGraphics" /> provided.
        /// </summary>
        /// <param name="graphics">The graphics object to use to draw this object.</param>
        public override void Draw(IGraphics graphics)
        {
            if (_resourceManager == null)
            {
                throw new ObjectDisposedException(nameof(ShapeController));
            }

            graphics.ResourceManager = _resourceManager;

            foreach (Shape shape in Shapes)
            {
                using (IGraphicsPath path = graphics.CreatePath())
                {
                    bool first = true;
                    foreach (Vertex vertex in shape.Vertices)
                    {
                        if (first)
                        {
                            path.Start(vertex.Location);
                        }
                        else
                        {
                            path.AddLine(vertex.Location);
                        }
                        first = false;
                    }

                    path.End();

                    graphics.DrawPath(path);
                }
            }
        }
コード例 #4
0
        private static IGraphicsPath ConvertPolygon(IDisplay display, IPolygon polygon, IGraphicsPath gp)
        {
            //if (polygon == null || polygon.RingCount == 0)
            //    return null;

            for (int r = 0; r < polygon.RingCount; r++)
            {
                bool  first  = true;
                int   count  = 0;
                IRing ring   = polygon[r];
                int   pCount = ring.PointCount;

                //double o_x = -1e10, o_y = -1e10;
                float o_x = float.MinValue, o_y = float.MinValue;
                gp.StartFigure();
                for (int p = 0; p < pCount; p++)
                {
                    IPoint point = ring[p];
                    double x = point.X, y = point.Y;

                    display.World2Image(ref x, ref y);

                    //
                    // Auf 0.1 Pixel runden, sonst kann es bei fast
                    // horizontalen (vertikalen) Linien zu Fehlern kommen
                    // -> Eine hälfte (beim Bruch) wird nicht mehr gezeichnet
                    //
                    x = Math.Round(x, 1);
                    y = Math.Round(y, 1);

                    if (!((float)o_x == (float)x &&
                          (float)o_y == (float)y))
                    {
                        if (!first)
                        {
                            gp.AddLine(
                                (float)o_x,
                                (float)o_y,
                                (float)x,
                                (float)y);
                            count++;
                        }
                        else
                        {
                            first = false;
                        }
                    }
                    o_x = (float)x;
                    o_y = (float)y;
                }
                if (count > 0)
                {
                    gp.CloseFigure();
                }
            }

            return(gp);
        }
コード例 #5
0
ファイル: Line.cs プロジェクト: billings7/EscherTilier
 /// <summary>
 ///     Adds the line to the given <paramref name="path" /> after transforming it by the given
 ///     <paramref name="transform" />.
 /// </summary>
 /// <param name="path">The path to add the line to.</param>
 /// <param name="transform">The transform.</param>
 /// <param name="reverse">If set to <see langword="true" />, add the line from <see cref="Start" /> to <see cref="End" />.</param>
 public void AddToPath(IGraphicsPath path, Matrix3x2 transform, bool reverse)
 {
     path.AddLine(Vector2.Transform(reverse ? Start : End, transform));
 }
コード例 #6
0
ファイル: GraphicsPath.cs プロジェクト: yaram/Eto
 /// <summary>
 /// Adds a line to the path
 /// </summary>
 /// <param name="path">Path to add the line to</param>
 /// <param name="start">Starting point for the line</param>
 /// <param name="end">Ending point for the line</param>
 public static void AddLine(this IGraphicsPath path, PointF start, PointF end)
 {
     path.AddLine(start.X, start.Y, end.X, end.Y);
 }
コード例 #7
0
        public override void AddToPath(IGraphicsPath graphicsPath)
        {
            if (Start == End)
            {
                return;
            }

            if (RadiusX == 0.0f && RadiusY == 0.0f)
            {
                graphicsPath.AddLine(Start, End);
                return;
            }

            var sinPhi = Math.Sin(Angle * RadiansPerDegree);
            var cosPhi = Math.Cos(Angle * RadiansPerDegree);

            var x1dash = cosPhi * (Start.X - End.X) / 2.0 + sinPhi * (Start.Y - End.Y) / 2.0;
            var y1dash = -sinPhi * (Start.X - End.X) / 2.0 + cosPhi * (Start.Y - End.Y) / 2.0;

            Double root;
            var    numerator = RadiusX * RadiusX * RadiusY * RadiusY - RadiusX * RadiusX * y1dash * y1dash -
                               RadiusY * RadiusY * x1dash * x1dash;

            var rx = RadiusX;
            var ry = RadiusY;

            if (numerator < 0.0)
            {
                var s = (Single)Math.Sqrt(1.0 - numerator / (RadiusX * RadiusX * RadiusY * RadiusY));

                rx  *= s;
                ry  *= s;
                root = 0.0;
            }
            else
            {
                root = (Size == SvgArcSize.Large && Sweep == SvgArcSweep.Positive ||
                        Size == SvgArcSize.Small && Sweep == SvgArcSweep.Negative
                    ? -1.0
                    : 1.0) * Math.Sqrt(numerator /
                                       (RadiusX * RadiusX * y1dash * y1dash + RadiusY * RadiusY * x1dash * x1dash));
            }

            var cxdash = root * rx * y1dash / ry;
            var cydash = -root * ry * x1dash / rx;

            var cx = cosPhi * cxdash - sinPhi * cydash + (Start.X + End.X) / 2.0;
            var cy = sinPhi * cxdash + cosPhi * cydash + (Start.Y + End.Y) / 2.0;

            var theta1 = CalculateVectorAngle(1.0, 0.0, (x1dash - cxdash) / rx, (y1dash - cydash) / ry);
            var dtheta = CalculateVectorAngle((x1dash - cxdash) / rx, (y1dash - cydash) / ry, (-x1dash - cxdash) / rx,
                                              (-y1dash - cydash) / ry);

            if (Sweep == SvgArcSweep.Negative && dtheta > 0)
            {
                dtheta -= 2.0 * Math.PI;
            }
            else if (Sweep == SvgArcSweep.Positive && dtheta < 0)
            {
                dtheta += 2.0 * Math.PI;
            }

            var segments = (Int32)Math.Ceiling(Math.Abs(dtheta / (Math.PI / 2.0)));
            var delta    = dtheta / segments;
            var t        = 8.0 / 3.0 * Math.Sin(delta / 4.0) * Math.Sin(delta / 4.0) / Math.Sin(delta / 2.0);

            var startX = Start.X;
            var startY = Start.Y;

            for (var i = 0; i < segments; ++i)
            {
                var cosTheta1 = Math.Cos(theta1);
                var sinTheta1 = Math.Sin(theta1);
                var theta2    = theta1 + delta;
                var cosTheta2 = Math.Cos(theta2);
                var sinTheta2 = Math.Sin(theta2);

                var endpointX = cosPhi * rx * cosTheta2 - sinPhi * ry * sinTheta2 + cx;
                var endpointY = sinPhi * rx * cosTheta2 + cosPhi * ry * sinTheta2 + cy;

                var dx1 = t * (-cosPhi * rx * sinTheta1 - sinPhi * ry * cosTheta1);
                var dy1 = t * (-sinPhi * rx * sinTheta1 + cosPhi * ry * cosTheta1);

                var dxe = t * (cosPhi * rx * sinTheta2 + sinPhi * ry * cosTheta2);
                var dye = t * (sinPhi * rx * sinTheta2 - cosPhi * ry * cosTheta2);

                graphicsPath.AddBezier(startX, startY, (Single)(startX + dx1), (Single)(startY + dy1),
                                       (Single)(endpointX + dxe), (Single)(endpointY + dye), (Single)endpointX, (Single)endpointY);

                theta1 = theta2;
                startX = (Single)endpointX;
                startY = (Single)endpointY;
            }
        }
コード例 #8
0
 /// <summary>
 /// Adds a single line to the path
 /// </summary>
 /// <param name="point1">Starting point for the line</param>
 /// <param name="point2">Ending point for the line</param>
 public void AddLine(Point point1, Point point2)
 {
     inner.AddLine(point1, point2);
 }
コード例 #9
0
 public override void AddToPath(IGraphicsPath graphicsPath)
 {
     graphicsPath.AddLine(Start, End);
 }
コード例 #10
0
ファイル: Line.cs プロジェクト: billings7/EscherTilier
 /// <summary>
 ///     Adds the line to the given <paramref name="path" /> after transforming it by the given
 ///     <paramref name="transform" />.
 /// </summary>
 /// <param name="path">The path to add the line to.</param>
 /// <param name="transform">The transform.</param>
 /// <param name="reverse">If set to <see langword="true" />, add the line from <see cref="Start" /> to <see cref="End" />.</param>
 public void AddToPath(IGraphicsPath path, Matrix3x2 transform, bool reverse)
 {
     path.AddLine(Vector2.Transform(reverse ? Start : End, transform));
 }