From 9b460f77e516980ad0774b3093751d4c3c34706a Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Fri, 27 Mar 2026 15:32:14 -0400 Subject: [PATCH] test: add DXF import integration test for ellipse-to-arc conversion Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest.Tests/EllipseConverterTests.cs | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/OpenNest.Tests/EllipseConverterTests.cs b/OpenNest.Tests/EllipseConverterTests.cs index aa0a4dd..8c16165 100644 --- a/OpenNest.Tests/EllipseConverterTests.cs +++ b/OpenNest.Tests/EllipseConverterTests.cs @@ -1,6 +1,7 @@ using OpenNest.Geometry; using OpenNest.Math; using Xunit; +using System.Linq; namespace OpenNest.Tests; @@ -204,6 +205,46 @@ public class EllipseConverterTests } } + [Fact] + public void DxfImporter_EllipseInDxf_ProducesArcsNotLines() + { + // Create a DXF in memory with an ellipse and verify import produces arcs + var doc = new ACadSharp.CadDocument(); + var ellipse = new ACadSharp.Entities.Ellipse + { + Center = new CSMath.XYZ(0, 0, 0), + MajorAxisEndPoint = new CSMath.XYZ(10, 0, 0), + RadiusRatio = 0.6, + StartParameter = 0, + EndParameter = System.Math.PI * 2 + }; + doc.Entities.Add(ellipse); + + // Write to temp file and re-import + var tempPath = System.IO.Path.GetTempFileName() + ".dxf"; + try + { + using (var stream = System.IO.File.Create(tempPath)) + using (var writer = new ACadSharp.IO.DxfWriter(stream, doc, false)) + writer.Write(); + + var importer = new OpenNest.IO.DxfImporter { SplinePrecision = 200 }; + var result = importer.Import(tempPath); + + var arcCount = result.Entities.Count(e => e is Arc); + var lineCount = result.Entities.Count(e => e is Line); + + // Should have arcs, not hundreds of lines + Assert.True(arcCount >= 4, $"Expected at least 4 arcs, got {arcCount}"); + Assert.Equal(0, lineCount); + } + finally + { + if (System.IO.File.Exists(tempPath)) + System.IO.File.Delete(tempPath); + } + } + private static double MaxDeviationFromEllipse(Arc arc, Vector ellipseCenter, double semiMajor, double semiMinor, double rotation, int samples) {