Пример #1
0
        /// <overloads>
        /// Draws the specified <see cref="RegularPolygon"/> or <see cref="PolygonGrid"/> to the
        /// specified <see cref="StreamGeometry"/>.</overloads>
        /// <summary>
        /// Draws the specified <see cref="RegularPolygon"/> to the specified <see
        /// cref="StreamGeometry"/>.</summary>
        /// <param name="polygon">
        /// The <see cref="RegularPolygon"/> to draw.</param>
        /// <param name="context">
        /// The <see cref="StreamGeometryContext"/> that receives <paramref name="polygon"/>.
        /// </param>
        /// <param name="offset">
        /// The offset by which to shift <paramref name="polygon"/>.</param>
        /// <param name="isFilled">
        /// <c>true</c> to use the area covered by <paramref name="polygon"/> for hit-testing,
        /// rendering, and clipping; otherwise, <c>false</c>.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="polygon"/> or <paramref name="context"/> is a null reference.
        /// </exception>
        /// <remarks>
        /// <b>Draw</b> issues one <see cref="StreamGeometryContext.BeginFigure"/> call with the
        /// specified <paramref name="isFilled"/> parameter for the first <see
        /// cref="RegularPolygon.Vertices"/> element of the specified <paramref name="polygon"/>,
        /// and then one <see cref="StreamGeometryContext.LineTo"/> call for each remaining element.
        /// All coordinates are shifted by the specified <paramref name="offset"/>.</remarks>

        public static void Draw(this RegularPolygon polygon,
                                StreamGeometryContext context, PointD offset, bool isFilled)
        {
            PointD[] vertices = polygon.Vertices;
            PointD   start    = vertices[0] + offset;

            context.BeginFigure(start.ToWpfPoint(), isFilled, true);

            for (int i = 1; i < vertices.Length; i++)
            {
                PointD next = vertices[i] + offset;
                context.LineTo(next.ToWpfPoint(), true, true);
            }
        }
Пример #2
0
        /// <overloads>
        /// Converts the specified <see cref="RegularPolygon"/> to a closed <see
        /// cref="PathFigure"/>.</overloads>
        /// <summary>
        /// Converts the specified <see cref="RegularPolygon"/> to a closed <see
        /// cref="PathFigure"/>.</summary>
        /// <param name="polygon">
        /// The <see cref="RegularPolygon"/> to convert.</param>
        /// <returns>
        /// A closed and frozen <see cref="PathFigure"/> containing all <see
        /// cref="RegularPolygon.Vertices"/> of the specified <paramref name="polygon"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="polygon"/> is a null reference.</exception>

        public static PathFigure ToFigure(this RegularPolygon polygon)
        {
            PointD[]   vertices = polygon.Vertices;
            PathFigure figure   = new PathFigure();

            figure.StartPoint = vertices[0].ToWpfPoint();
            for (int i = 1; i < vertices.Length; i++)
            {
                figure.Segments.Add(new LineSegment(vertices[i].ToWpfPoint(), true));
            }

            figure.IsClosed = true;
            figure.Freeze();
            return(figure);
        }