// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.Drawing.Brushes; using SixLabors.ImageSharp.Drawing.Pens; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; using SixLabors.Shapes; namespace SixLabors.ImageSharp.Processing.Overlays { /// /// Adds extensions that allow the drawing of closed linear polygons to the type. /// public static class DrawPolygonExtensions { /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The points. /// The options. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel => source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// /// The type of the color. /// The image this method extends. /// The brush. /// The thickness. /// The points. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel => source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The points. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel => source.DrawPolygon(new SolidBrush(color), thickness, points); /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// /// The type of the color. /// The image this method extends. /// The color. /// The thickness. /// The points. /// The options. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel => source.DrawPolygon(new SolidBrush(color), thickness, points, options); /// /// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// /// The type of the color. /// The image this method extends. /// The pen. /// The points. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, PointF[] points) where TPixel : struct, IPixel => source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); /// /// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// /// The type of the color. /// The image this method extends. /// The pen. /// The points. /// The options. /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel => source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); } }