Files
OpenNest/OpenNest.Core/Shapes/NgonShape.cs
T
aj aec0523062 style: apply CSharpier formatting to all C# sources
Repo-wide sweep with the pinned CSharpier 1.3.0 tool. Whitespace and
line-wrapping only; OpenNest.Engine.Tests (109) and OpenNest.IO.Tests
pass after reformat, full solution builds 0 errors.

Added .csharpierignore so csproj/config XML keeps its existing layout
(CSharpier's XML wrapping churns attributes with zero benefit).

Formatting is now enforceable: dotnet csharpier check . passes.
2026-09-20 16:41:50 -04:00

48 lines
1.3 KiB
C#

using System.Collections.Generic;
using OpenNest.Geometry;
namespace OpenNest.Shapes
{
public class NgonShape : ShapeDefinition
{
public int Sides { get; set; }
public double Width { get; set; }
public override string GenerateName() => $"{Sides}-Sided Polygon {Dim(Width)}";
public override void SetPreviewDefaults()
{
Sides = 8;
Width = 8;
}
public override Drawing GetDrawing()
{
var n = Sides < 3 ? 3 : Sides;
var center = Width / 2.0;
var circumRadius = Width / (2.0 * System.Math.Cos(System.Math.PI / n));
var step = 2.0 * System.Math.PI / n;
var start = System.Math.PI / n;
var vertices = new Vector[n];
for (var i = 0; i < n; i++)
{
var angle = start + i * step;
vertices[i] = new Vector(
center + circumRadius * System.Math.Cos(angle),
center + circumRadius * System.Math.Sin(angle)
);
}
var entities = new List<Entity>();
for (var i = 0; i < n; i++)
{
var next = (i + 1) % n;
entities.Add(new Line(vertices[i], vertices[next]));
}
return CreateDrawing(entities);
}
}
}