Files
OpenNest/OpenNest.Tests/Reporting/NestPdfWriterArcTests.cs
T
ajandClaude Sonnet 5.5 bf9b0df816 fix(reports): draw arcs as Bezier curves to stop an out-of-memory crash
PDFsharp 6.2.4's XGraphicsPath.AddArc loops until memory runs out on some
arcs ending on a quadrant boundary within rounding, which nested part
geometry produces. Nest reports and part printouts now build arcs from
Bezier curves themselves.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 14:40:14 -05:00

32 lines
1.2 KiB
C#

using System.Collections.Immutable;
using OpenNest.Reporting;
using PdfSharp.Drawing;
namespace OpenNest.Tests.Reporting;
public sealed class NestPdfWriterArcTests
{
// Start and sweep, in model degrees, of arcs ending on a quadrant boundary within rounding.
// PDFsharp's own AddArc runs out of memory on these.
[Theory]
[InlineData(180.00000000000003, 180)]
[InlineData(270.0000000000001, 89.9999999999999)]
[InlineData(359.999, 0.001)]
[InlineData(360, 1e-14)]
[InlineData(0, 360)]
[InlineData(90, -360)]
public void AddContour_DrawsArcsEndingOnAQuadrantBoundary(double start, double sweep)
{
var from = start * System.Math.PI / 180;
var span = sweep * System.Math.PI / 180;
ReportPoint At(double angle) => new(10 * System.Math.Cos(angle), 10 * System.Math.Sin(angle));
var contour = new ReportContour(ImmutableArray.Create(
new ReportSegment(At(from), At(from + span), new ReportPoint(0, 0), 10, from, span)), false);
var fit = Fit.Create(new ReportBounds(-10, -10, 10, 10), new XRect(0, 0, 100, 100));
var exception = Record.Exception(() => NestPdfWriter.AddContour(new XGraphicsPath(), contour, fit));
Assert.Null(exception);
}
}