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.
This commit is contained in:
@@ -7,8 +7,7 @@ namespace OpenNest.Tests.IO
|
||||
{
|
||||
public class CadImporterTests
|
||||
{
|
||||
private static string TestDxf =>
|
||||
Path.Combine("Bending", "TestData", "4526 A14 PT11.dxf");
|
||||
private static string TestDxf => Path.Combine("Bending", "TestData", "4526 A14 PT11.dxf");
|
||||
|
||||
[Fact]
|
||||
public void Import_LoadsEntitiesAndDetectsBends()
|
||||
@@ -45,8 +44,10 @@ namespace OpenNest.Tests.IO
|
||||
// Exercises the named-detector branch: when BendDetectorName doesn't
|
||||
// match any registered detector, bends should be an empty list
|
||||
// (not a crash, and no fall-through to auto-detect).
|
||||
var result = CadImporter.Import(TestDxf,
|
||||
new CadImportOptions { BendDetectorName = "__nonexistent__" });
|
||||
var result = CadImporter.Import(
|
||||
TestDxf,
|
||||
new CadImportOptions { BendDetectorName = "__nonexistent__" }
|
||||
);
|
||||
|
||||
Assert.Empty(result.Bends);
|
||||
}
|
||||
@@ -62,7 +63,8 @@ namespace OpenNest.Tests.IO
|
||||
result.Bends,
|
||||
quantity: 5,
|
||||
customer: "ACME",
|
||||
editedProgram: null);
|
||||
editedProgram: null
|
||||
);
|
||||
|
||||
Assert.NotNull(drawing);
|
||||
Assert.Equal("4526 A14 PT11", drawing.Name);
|
||||
@@ -80,8 +82,14 @@ namespace OpenNest.Tests.IO
|
||||
{
|
||||
var result = CadImporter.Import(TestDxf);
|
||||
|
||||
var drawing = CadImporter.BuildDrawing(result, result.Entities, result.Bends,
|
||||
quantity: 1, customer: null, editedProgram: null);
|
||||
var drawing = CadImporter.BuildDrawing(
|
||||
result,
|
||||
result.Entities,
|
||||
result.Bends,
|
||||
quantity: 1,
|
||||
customer: null,
|
||||
editedProgram: null
|
||||
);
|
||||
|
||||
Assert.NotNull(drawing.Source.Offset);
|
||||
// After offset extraction, the program's first rapid must start at origin.
|
||||
@@ -95,15 +103,21 @@ namespace OpenNest.Tests.IO
|
||||
{
|
||||
var result = CadImporter.Import(TestDxf);
|
||||
// Suppress the first non-bend-source entity
|
||||
var bendSources = result.Bends
|
||||
.Where(b => b.SourceEntity != null)
|
||||
var bendSources = result
|
||||
.Bends.Where(b => b.SourceEntity != null)
|
||||
.Select(b => b.SourceEntity)
|
||||
.ToHashSet();
|
||||
var hidden = result.Entities.First(e => !bendSources.Contains(e));
|
||||
hidden.IsVisible = false;
|
||||
|
||||
var drawing = CadImporter.BuildDrawing(result, result.Entities, result.Bends,
|
||||
quantity: 1, customer: null, editedProgram: null);
|
||||
var drawing = CadImporter.BuildDrawing(
|
||||
result,
|
||||
result.Entities,
|
||||
result.Bends,
|
||||
quantity: 1,
|
||||
customer: null,
|
||||
editedProgram: null
|
||||
);
|
||||
|
||||
Assert.Contains(hidden.Id, drawing.SuppressedEntityIds);
|
||||
}
|
||||
@@ -115,8 +129,14 @@ namespace OpenNest.Tests.IO
|
||||
var edited = new OpenNest.CNC.Program();
|
||||
edited.MoveTo(new OpenNest.Geometry.Vector(0, 0));
|
||||
|
||||
var drawing = CadImporter.BuildDrawing(result, result.Entities, result.Bends,
|
||||
quantity: 1, customer: null, editedProgram: edited);
|
||||
var drawing = CadImporter.BuildDrawing(
|
||||
result,
|
||||
result.Entities,
|
||||
result.Bends,
|
||||
quantity: 1,
|
||||
customer: null,
|
||||
editedProgram: edited
|
||||
);
|
||||
|
||||
Assert.Same(edited, drawing.Program);
|
||||
}
|
||||
@@ -124,8 +144,10 @@ namespace OpenNest.Tests.IO
|
||||
[Fact]
|
||||
public void ImportDrawing_ComposesImportAndBuild()
|
||||
{
|
||||
var drawing = CadImporter.ImportDrawing(TestDxf,
|
||||
new CadImportOptions { Quantity = 3, Customer = "ACME" });
|
||||
var drawing = CadImporter.ImportDrawing(
|
||||
TestDxf,
|
||||
new CadImportOptions { Quantity = 3, Customer = "ACME" }
|
||||
);
|
||||
|
||||
Assert.NotNull(drawing);
|
||||
Assert.Equal("4526 A14 PT11", drawing.Name);
|
||||
|
||||
@@ -51,7 +51,10 @@ public class ChrFontTests
|
||||
Assert.NotNull(glyph);
|
||||
|
||||
var entities = glyph.ToEntities(1.0, 0, 0);
|
||||
Assert.True(entities.Count >= 2, $"Expected at least 2 entities for 'L', got {entities.Count}");
|
||||
Assert.True(
|
||||
entities.Count >= 2,
|
||||
$"Expected at least 2 entities for 'L', got {entities.Count}"
|
||||
);
|
||||
Assert.All(entities, e => Assert.Equal(EntityType.Line, e.Type));
|
||||
}
|
||||
|
||||
@@ -99,8 +102,10 @@ public class ChrFontTests
|
||||
var abBox = abEntities.GetBoundingBox();
|
||||
var aBox = aEntities.GetBoundingBox();
|
||||
|
||||
Assert.True(abBox.Length > aBox.Length * 1.5,
|
||||
$"AB width ({abBox.Length:F1}) should be significantly wider than A width ({aBox.Length:F1})");
|
||||
Assert.True(
|
||||
abBox.Length > aBox.Length * 1.5,
|
||||
$"AB width ({abBox.Length:F1}) should be significantly wider than A width ({aBox.Length:F1})"
|
||||
);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
@@ -129,18 +134,28 @@ public class ChrFontTests
|
||||
|
||||
var tolerance = 0.5;
|
||||
|
||||
Assert.True(System.Math.Abs(box.Left - refLeft) < tolerance,
|
||||
$"Left: ours={box.Left:F2}, ref={refLeft:F2}, diff={System.Math.Abs(box.Left - refLeft):F2}");
|
||||
Assert.True(System.Math.Abs(box.Right - refRight) < tolerance,
|
||||
$"Right: ours={box.Right:F2}, ref={refRight:F2}, diff={System.Math.Abs(box.Right - refRight):F2}");
|
||||
Assert.True(System.Math.Abs(box.Bottom - refBottom) < tolerance,
|
||||
$"Bottom: ours={box.Bottom:F2}, ref={refBottom:F2}, diff={System.Math.Abs(box.Bottom - refBottom):F2}");
|
||||
Assert.True(System.Math.Abs(box.Top - refTop) < tolerance,
|
||||
$"Top: ours={box.Top:F2}, ref={refTop:F2}, diff={System.Math.Abs(box.Top - refTop):F2}");
|
||||
Assert.True(
|
||||
System.Math.Abs(box.Left - refLeft) < tolerance,
|
||||
$"Left: ours={box.Left:F2}, ref={refLeft:F2}, diff={System.Math.Abs(box.Left - refLeft):F2}"
|
||||
);
|
||||
Assert.True(
|
||||
System.Math.Abs(box.Right - refRight) < tolerance,
|
||||
$"Right: ours={box.Right:F2}, ref={refRight:F2}, diff={System.Math.Abs(box.Right - refRight):F2}"
|
||||
);
|
||||
Assert.True(
|
||||
System.Math.Abs(box.Bottom - refBottom) < tolerance,
|
||||
$"Bottom: ours={box.Bottom:F2}, ref={refBottom:F2}, diff={System.Math.Abs(box.Bottom - refBottom):F2}"
|
||||
);
|
||||
Assert.True(
|
||||
System.Math.Abs(box.Top - refTop) < tolerance,
|
||||
$"Top: ours={box.Top:F2}, ref={refTop:F2}, diff={System.Math.Abs(box.Top - refTop):F2}"
|
||||
);
|
||||
|
||||
var actualCapHeight = box.Top - box.Bottom;
|
||||
Assert.True(System.Math.Abs(actualCapHeight - height) < 0.5,
|
||||
$"Cap height: ours={actualCapHeight:F2}, expected={height:F2}");
|
||||
Assert.True(
|
||||
System.Math.Abs(actualCapHeight - height) < 0.5,
|
||||
$"Cap height: ours={actualCapHeight:F2}, expected={height:F2}"
|
||||
);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
@@ -152,10 +167,14 @@ public class ChrFontTests
|
||||
var entities = font.RenderText("Text", height, Vector.Zero);
|
||||
var box = entities.GetBoundingBox();
|
||||
|
||||
Assert.True(measuredWidth >= box.Length,
|
||||
$"Measured={measuredWidth:F2} should be >= rendered={box.Length:F2}");
|
||||
Assert.True(measuredWidth - box.Length < 2.0,
|
||||
$"Measured={measuredWidth:F2}, rendered={box.Length:F2}, diff={measuredWidth - box.Length:F2}");
|
||||
Assert.True(
|
||||
measuredWidth >= box.Length,
|
||||
$"Measured={measuredWidth:F2} should be >= rendered={box.Length:F2}"
|
||||
);
|
||||
Assert.True(
|
||||
measuredWidth - box.Length < 2.0,
|
||||
$"Measured={measuredWidth:F2}, rendered={box.Length:F2}, diff={measuredWidth - box.Length:F2}"
|
||||
);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
@@ -171,10 +190,15 @@ public class ChrFontTests
|
||||
Assert.True(lines.Count >= 10, $"Expected at least 10 entities for 't', got {lines.Count}");
|
||||
|
||||
var curveLines = lines.Skip(1).Take(lines.Count - 3).ToList();
|
||||
Assert.True(curveLines.Count >= 14, $"Expected at least 14 curve segments, got {curveLines.Count}");
|
||||
Assert.True(
|
||||
curveLines.Count >= 14,
|
||||
$"Expected at least 14 curve segments, got {curveLines.Count}"
|
||||
);
|
||||
|
||||
var lastCurve = curveLines[^1];
|
||||
Assert.True(lastCurve.EndPoint.X > curveLines[0].StartPoint.X,
|
||||
$"Curve should end to the right of where it starts: start X={curveLines[0].StartPoint.X:F1}, end X={lastCurve.EndPoint.X:F1}");
|
||||
Assert.True(
|
||||
lastCurve.EndPoint.X > curveLines[0].StartPoint.X,
|
||||
$"Curve should end to the right of where it starts: start X={curveLines[0].StartPoint.X:F1}, end X={lastCurve.EndPoint.X:F1}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,10 @@ public class DxfRoundtripTests
|
||||
return reimported;
|
||||
}
|
||||
|
||||
private static List<T> FilterByLayer<T>(List<Entity> entities, string layerName) where T : Entity
|
||||
private static List<T> FilterByLayer<T>(List<Entity> entities, string layerName)
|
||||
where T : Entity
|
||||
{
|
||||
return entities
|
||||
.Where(e => e is T && e.Layer?.Name == layerName)
|
||||
.Cast<T>()
|
||||
.ToList();
|
||||
return entities.Where(e => e is T && e.Layer?.Name == layerName).Cast<T>().ToList();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -38,7 +36,7 @@ public class DxfRoundtripTests
|
||||
{
|
||||
new Line(0, 0, 10, 0),
|
||||
new Line(10, 0, 5, 8),
|
||||
new Line(5, 8, 0, 0)
|
||||
new Line(5, 8, 0, 0),
|
||||
};
|
||||
|
||||
var reimported = ExportAndReimport(original);
|
||||
@@ -97,7 +95,7 @@ public class DxfRoundtripTests
|
||||
new Line(0, 0, 10, 0),
|
||||
new Line(10, 0, 10, 5),
|
||||
new Circle(20, 20, 3),
|
||||
new Arc(15, 15, 5, 0.0, System.Math.PI)
|
||||
new Arc(15, 15, 5, 0.0, System.Math.PI),
|
||||
};
|
||||
|
||||
var reimported = ExportAndReimport(original);
|
||||
@@ -120,17 +118,25 @@ public class DxfRoundtripTests
|
||||
new Line(0, 0, 20, 0),
|
||||
new Line(20, 0, 20, 10),
|
||||
new Line(20, 10, 0, 10),
|
||||
new Line(0, 10, 0, 0)
|
||||
new Line(0, 10, 0, 0),
|
||||
};
|
||||
|
||||
var reimported = ExportAndReimport(original);
|
||||
var cutLines = FilterByLayer<Line>(reimported, "Cut");
|
||||
|
||||
// Verify bounding box is preserved regardless of line order
|
||||
var origMinX = original.Cast<Line>().Min(l => System.Math.Min(l.StartPoint.X, l.EndPoint.X));
|
||||
var origMaxX = original.Cast<Line>().Max(l => System.Math.Max(l.StartPoint.X, l.EndPoint.X));
|
||||
var origMinY = original.Cast<Line>().Min(l => System.Math.Min(l.StartPoint.Y, l.EndPoint.Y));
|
||||
var origMaxY = original.Cast<Line>().Max(l => System.Math.Max(l.StartPoint.Y, l.EndPoint.Y));
|
||||
var origMinX = original
|
||||
.Cast<Line>()
|
||||
.Min(l => System.Math.Min(l.StartPoint.X, l.EndPoint.X));
|
||||
var origMaxX = original
|
||||
.Cast<Line>()
|
||||
.Max(l => System.Math.Max(l.StartPoint.X, l.EndPoint.X));
|
||||
var origMinY = original
|
||||
.Cast<Line>()
|
||||
.Min(l => System.Math.Min(l.StartPoint.Y, l.EndPoint.Y));
|
||||
var origMaxY = original
|
||||
.Cast<Line>()
|
||||
.Max(l => System.Math.Max(l.StartPoint.Y, l.EndPoint.Y));
|
||||
|
||||
var rtMinX = cutLines.Min(l => System.Math.Min(l.StartPoint.X, l.EndPoint.X));
|
||||
var rtMaxX = cutLines.Max(l => System.Math.Max(l.StartPoint.X, l.EndPoint.X));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Linq;
|
||||
using OpenNest.Bending;
|
||||
using OpenNest.Geometry;
|
||||
using OpenNest.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenNest.Tests.IO;
|
||||
|
||||
@@ -11,24 +11,28 @@ public class NestBendSerializationTests
|
||||
public void Bends_SurviveNestRoundtrip()
|
||||
{
|
||||
var drawing = TestHelpers.MakeSquareDrawing();
|
||||
drawing.Bends.Add(new Bend
|
||||
{
|
||||
StartPoint = new Vector(0, 5),
|
||||
EndPoint = new Vector(10, 5),
|
||||
Direction = BendDirection.Up,
|
||||
Angle = 90,
|
||||
Radius = 0.06,
|
||||
NoteText = "UP 90° R0.06"
|
||||
});
|
||||
drawing.Bends.Add(new Bend
|
||||
{
|
||||
StartPoint = new Vector(0, 3),
|
||||
EndPoint = new Vector(10, 3),
|
||||
Direction = BendDirection.Down,
|
||||
Angle = 45.5,
|
||||
Radius = 0.125,
|
||||
NoteText = "DOWN 45.5° R0.125"
|
||||
});
|
||||
drawing.Bends.Add(
|
||||
new Bend
|
||||
{
|
||||
StartPoint = new Vector(0, 5),
|
||||
EndPoint = new Vector(10, 5),
|
||||
Direction = BendDirection.Up,
|
||||
Angle = 90,
|
||||
Radius = 0.06,
|
||||
NoteText = "UP 90° R0.06",
|
||||
}
|
||||
);
|
||||
drawing.Bends.Add(
|
||||
new Bend
|
||||
{
|
||||
StartPoint = new Vector(0, 3),
|
||||
EndPoint = new Vector(10, 3),
|
||||
Direction = BendDirection.Down,
|
||||
Angle = 45.5,
|
||||
Radius = 0.125,
|
||||
NoteText = "DOWN 45.5° R0.125",
|
||||
}
|
||||
);
|
||||
|
||||
var nest = new Nest();
|
||||
nest.Drawings.Add(drawing);
|
||||
|
||||
@@ -13,7 +13,8 @@ public class NestWriterVariableTests
|
||||
public void RoundTrip_VariableDefinitions_Preserved()
|
||||
{
|
||||
var nest = CreateNestWithVariableProgram(
|
||||
"width = 48.0 global\ndiameter = 0.3\nG90\nG01X$widthY$diameter");
|
||||
"width = 48.0 global\ndiameter = 0.3\nG90\nG01X$widthY$diameter"
|
||||
);
|
||||
|
||||
var loaded = RoundTrip(nest);
|
||||
var pgm = loaded.Drawings.First().Program;
|
||||
@@ -28,8 +29,7 @@ public class NestWriterVariableTests
|
||||
[Fact]
|
||||
public void RoundTrip_VariableRefs_Preserved()
|
||||
{
|
||||
var nest = CreateNestWithVariableProgram(
|
||||
"width = 48.0\nG90\nG01X$widthY0");
|
||||
var nest = CreateNestWithVariableProgram("width = 48.0\nG90\nG01X$widthY0");
|
||||
|
||||
var loaded = RoundTrip(nest);
|
||||
var pgm = loaded.Drawings.First().Program;
|
||||
@@ -43,8 +43,7 @@ public class NestWriterVariableTests
|
||||
[Fact]
|
||||
public void RoundTrip_InlineFlag_Preserved()
|
||||
{
|
||||
var nest = CreateNestWithVariableProgram(
|
||||
"kerf = 0.06 inline\nG90\nG01X1Y0");
|
||||
var nest = CreateNestWithVariableProgram("kerf = 0.06 inline\nG90\nG01X1Y0");
|
||||
|
||||
var loaded = RoundTrip(nest);
|
||||
var pgm = loaded.Drawings.First().Program;
|
||||
|
||||
@@ -54,7 +54,14 @@ public class SubProgramSerializationTests
|
||||
|
||||
var pgm = new Program(Mode.Absolute);
|
||||
pgm.SubPrograms[42] = sub;
|
||||
pgm.Codes.Add(new SubProgramCall { Id = 42, Program = sub, Offset = new Vector(5, 5) });
|
||||
pgm.Codes.Add(
|
||||
new SubProgramCall
|
||||
{
|
||||
Id = 42,
|
||||
Program = sub,
|
||||
Offset = new Vector(5, 5),
|
||||
}
|
||||
);
|
||||
// Add perimeter so the drawing has non-zero geometry
|
||||
pgm.Codes.Add(new RapidMove(0, 0));
|
||||
pgm.Codes.Add(new LinearMove(10, 0));
|
||||
|
||||
Reference in New Issue
Block a user