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>
This commit is contained in:
ajandClaude Sonnet 5.5 committed 2026-11-28 14:40:14 -05:00
1 parent 17e6e65e1c
commit bf9b0df816
2 files changed
+56 -5

No files matched your search

@@ -0,0 +1,31 @@
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);
}
}