feat: Shape.CreateNgon

This commit is contained in:
Syntriax 2024-01-26 19:01:53 +03:00
parent c6d2bad23e
commit ceb29cc42f
1 changed files with 16 additions and 0 deletions

View File

@ -12,6 +12,22 @@ public record Shape(IList<Vector2D> Vertices) : IEnumerable<Vector2D>
public static Shape CreateCopy(Shape shape) => new(new List<Vector2D>(shape.Vertices)); public static Shape CreateCopy(Shape shape) => new(new List<Vector2D>(shape.Vertices));
public static Shape CreateNgon(int vertexCount) => CreateNgon(vertexCount, Vector2D.Up);
public static Shape CreateNgon(int vertexCount, Vector2D positionToRotate)
{
if (vertexCount < 3)
throw new System.ArgumentException($"{nameof(vertexCount)} must have a value of more than 2.");
List<Vector2D> vertices = new(vertexCount);
float radiansPerVertex = 360f / vertexCount * Math.DegreeToRadian;
for (int i = 0; i < vertexCount; i++)
vertices.Add(positionToRotate.Rotate(i * radiansPerVertex));
return new(vertices);
}
public static Triangle GetSuperTriangle(Shape shape) public static Triangle GetSuperTriangle(Shape shape)
{ {
float minX = float.MaxValue, minY = float.MaxValue; float minX = float.MaxValue, minY = float.MaxValue;