// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Collections.Generic;
using System.Numerics;
namespace SixLabors.ImageSharp.Drawing {
///
/// A shape made up of a single closed path made up of one of more s
///
public class Polygon : Path
{
///
/// Initializes a new instance of the class.
///
/// The collection of points; processed as a series of linear line segments.
public Polygon(PointF[] points)
: this(new LinearLineSegment(points))
{
}
///
/// Initializes a new instance of the class.
///
/// The segments.
public Polygon(params ILineSegment[] segments)
: base(segments)
{
}
///
/// Initializes a new instance of the class.
///
/// The segments.
public Polygon(IEnumerable segments)
: base(segments)
{
}
///
/// Initializes a new instance of the class.
///
/// The segment.
public Polygon(ILineSegment segment)
: base(segment)
{
}
///
/// Initializes a new instance of the class.
///
/// The path.
internal Polygon(Path path)
: base(path)
{
}
///
/// Initializes a new instance of the class using the specified line segments.
///
///
/// If owned is set to , modifications to the segments array after construction may affect
/// the Polygon instance. If owned is , the segments are copied to ensure the Polygon is not affected by
/// external changes.
///
/// An array of line segments that define the edges of the polygon. The order of segments determines the shape of
/// the polygon.
///
/// to indicate that the Polygon instance takes ownership of the segments array;
/// to create a copy of the array.
///
internal Polygon(ILineSegment[] segments, bool owned)
: base(owned ? segments : [.. segments])
{
}
///
public override bool IsClosed => true;
///
public override IPath Transform(Matrix4x4 matrix)
{
if (matrix.IsIdentity)
{
return this;
}
ILineSegment[] segments = new ILineSegment[this.LineSegments.Count];
for (int i = 0; i < segments.Length; i++)
{
segments[i] = this.LineSegments[i].Transform(matrix);
}
return new Polygon(segments, true);
}
}
}