feat: wire up EllipseConverter and SplineConverter in DXF import pipeline
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -30,7 +30,7 @@ public class SolidWorksBendDetectorTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Simplifier_EllipseSegments_FewLargeArcs()
|
||||
public void EllipseConverter_ProducesArcsDirectly()
|
||||
{
|
||||
var path = Path.Combine(AppContext.BaseDirectory, "Bending", "TestData", "4526 A14 PT11 Test.dxf");
|
||||
Assert.True(File.Exists(path), $"Test DXF not found: {path}");
|
||||
@@ -38,36 +38,21 @@ public class SolidWorksBendDetectorTests
|
||||
var importer = new OpenNest.IO.DxfImporter { SplinePrecision = 200 };
|
||||
var result = importer.Import(path);
|
||||
|
||||
// EllipseConverter now produces arcs directly during import,
|
||||
// so the imported entities should contain Arc instances from the ellipses
|
||||
var arcCount = result.Entities.Count(e => e is OpenNest.Geometry.Arc);
|
||||
Assert.True(arcCount > 0, "Expected arcs from ellipse conversion");
|
||||
|
||||
// The GeometrySimplifier should find few or no line runs to simplify,
|
||||
// because ellipses are already converted to arcs at import time
|
||||
var shape = new OpenNest.Geometry.Shape();
|
||||
shape.Entities.AddRange(result.Entities);
|
||||
|
||||
// Default tolerance is 0.5 — should produce very few large arcs
|
||||
var simplifier = new OpenNest.Geometry.GeometrySimplifier();
|
||||
var candidates = simplifier.Analyze(shape);
|
||||
|
||||
// With 0.5 tolerance, 2 ellipses (~400 segments) should reduce to a handful of arcs
|
||||
// Dump for visibility then assert
|
||||
var info = string.Join(", ", candidates.Select(c => $"[{c.StartIndex}..{c.EndIndex}]={c.LineCount}lines R={c.FittedArc.Radius:F3}"));
|
||||
Assert.True(candidates.Count <= 10,
|
||||
$"Expected <=10 arcs but got {candidates.Count}: {info}");
|
||||
|
||||
// Each arc should cover many lines
|
||||
foreach (var c in candidates)
|
||||
Assert.True(c.LineCount >= 3, $"Arc [{c.StartIndex}..{c.EndIndex}] only covers {c.LineCount} lines");
|
||||
|
||||
// Arcs should connect to the original geometry within tolerance
|
||||
foreach (var c in candidates)
|
||||
{
|
||||
var firstLine = (OpenNest.Geometry.Line)shape.Entities[c.StartIndex];
|
||||
var lastLine = (OpenNest.Geometry.Line)shape.Entities[c.EndIndex];
|
||||
var arc = c.FittedArc;
|
||||
|
||||
var startGap = firstLine.StartPoint.DistanceTo(arc.StartPoint());
|
||||
var endGap = lastLine.EndPoint.DistanceTo(arc.EndPoint());
|
||||
|
||||
Assert.True(startGap < 1e-9, $"Start gap {startGap} at candidate [{c.StartIndex}..{c.EndIndex}]");
|
||||
Assert.True(endGap < 1e-9, $"End gap {endGap} at candidate [{c.StartIndex}..{c.EndIndex}]");
|
||||
}
|
||||
$"Expected <=10 simplifier candidates but got {candidates.Count}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -81,8 +66,16 @@ public class SolidWorksBendDetectorTests
|
||||
|
||||
// The DXF has 2 trimmed ellipses forming an oblong slot.
|
||||
// Trimmed ellipses must not generate a closing chord line.
|
||||
// 83 = 72 lines + 4 arcs + 7 circles + ellipse segments (heavily merged by optimizer)
|
||||
Assert.Equal(83, result.Entities.Count);
|
||||
// EllipseConverter now produces arcs instead of line segments,
|
||||
// changing the entity count. Verify arcs are present and no
|
||||
// spurious closing chord exists.
|
||||
var arcCount = result.Entities.Count(e => e is OpenNest.Geometry.Arc);
|
||||
var lineCount = result.Entities.Count(e => e is OpenNest.Geometry.Line);
|
||||
var circleCount = result.Entities.Count(e => e is OpenNest.Geometry.Circle);
|
||||
|
||||
Assert.True(arcCount > 0, "Expected arcs from ellipse conversion");
|
||||
Assert.True(circleCount >= 7, $"Expected at least 7 circles, got {circleCount}");
|
||||
Assert.Equal(115, result.Entities.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user