示例#1
0
        /// <summary>
        /// Converts the specified <see cref="PolygonGrid"/> to a <see
        /// cref="PathFigureCollection"/>.</summary>
        /// <param name="grid">
        /// The <see cref="PolygonGrid"/> to convert.</param>
        /// <returns>
        /// A frozen <see cref="PathFigureCollection"/> containing one <see cref="PathFigure"/> for
        /// each polygonal <see cref="PolygonGrid.Element"/> in the specified <paramref
        /// name="grid"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="grid"/> is a null reference.</exception>
        /// <remarks>
        /// <b>ToFigures</b> returns the results of <see cref="ToFigure"/> for each <see
        /// cref="PolygonGrid.Element"/> in the specified <paramref name="grid"/>, shifted by the
        /// corresponding <see cref="PolygonGrid.GridToDisplay"/> result. Each polygonal <see
        /// cref="PolygonGrid.Element"/> is therefore represented by one <see cref="PathFigure"/>.
        /// </remarks>

        public static PathFigureCollection ToFigures(this PolygonGrid grid)
        {
            int width = grid.Size.Width, height = grid.Size.Height;
            var figures = new PathFigureCollection(width * height);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    PointD     offset = grid.GridToDisplay(x, y);
                    PathFigure figure = grid.Element.ToFigure(offset);
                    figures.Add(figure);
                }
            }

            figures.Freeze();
            return(figures);
        }