diff --git a/OpenNest.WinForms.Tests/Controls/CutOffSegmentLabelTests.cs b/OpenNest.WinForms.Tests/Controls/CutOffSegmentLabelTests.cs
index d197181e..53e9d7ee 100644
--- a/OpenNest.WinForms.Tests/Controls/CutOffSegmentLabelTests.cs
+++ b/OpenNest.WinForms.Tests/Controls/CutOffSegmentLabelTests.cs
@@ -19,7 +19,8 @@ public class CutOffSegmentLabelTests
view.Matrix = new Matrix();
view.Plate.Size = new OpenNest.Geometry.Size(100, 100);
view.Plate.Quadrant = 1;
- view.Plate.Parts.Add(new Part(new Drawing("Block", Square(20)), new Vector(40, 40)));
+ view.Plate.Parts.Add(new Part(
+ new Drawing("Block", TestPrograms.Square(20)), new Vector(40, 40)));
view.Plate.CutOffs.Add(new CutOff(new Vector(50, 0), CutOffAxis.Vertical));
view.Plate.RegenerateCutOffs(new CutOffSettings());
@@ -50,7 +51,8 @@ public class CutOffSegmentLabelTests
view.Matrix = new Matrix(1, 0, 0, -1, 0, 0);
view.Plate.Size = new OpenNest.Geometry.Size(100, 100);
view.Plate.Quadrant = 4;
- view.Plate.Parts.Add(new Part(new Drawing("Block", Square(20)), new Vector(40, -60)));
+ view.Plate.Parts.Add(new Part(
+ new Drawing("Block", TestPrograms.Square(20)), new Vector(40, -60)));
view.Plate.CutOffs.Add(new CutOff(new Vector(50, 0), CutOffAxis.Vertical));
view.Plate.RegenerateCutOffs(new CutOffSettings());
@@ -95,15 +97,4 @@ public class CutOffSegmentLabelTests
}
return count;
}
-
- private static OpenNest.CNC.Program Square(double size)
- {
- var program = new OpenNest.CNC.Program();
- program.MoveTo(0, 0);
- program.LineTo(size, 0);
- program.LineTo(size, size);
- program.LineTo(0, size);
- program.LineTo(0, 0);
- return program;
- }
}
diff --git a/OpenNest.WinForms.Tests/Controls/CutSimulationOverlayTests.cs b/OpenNest.WinForms.Tests/Controls/CutSimulationOverlayTests.cs
index 5c8c8451..9f351da2 100644
--- a/OpenNest.WinForms.Tests/Controls/CutSimulationOverlayTests.cs
+++ b/OpenNest.WinForms.Tests/Controls/CutSimulationOverlayTests.cs
@@ -15,22 +15,11 @@ public class CutSimulationOverlayTests
Units = Units.Inches,
};
- private static Program Square(double size)
- {
- var program = new Program();
- program.Codes.Add(new RapidMove(0, 0));
- program.Codes.Add(new LinearMove(size, 0));
- program.Codes.Add(new LinearMove(size, size));
- program.Codes.Add(new LinearMove(0, size));
- program.Codes.Add(new LinearMove(0, 0));
- return program;
- }
-
private static Plate TwoSquares()
{
var plate = new Plate(48, 96);
- plate.Parts.Add(new Part(new Drawing("a", Square(10)), new Vector(5, 5)));
- plate.Parts.Add(new Part(new Drawing("b", Square(10)), new Vector(25, 5)));
+ plate.Parts.Add(new Part(new Drawing("a", TestPrograms.Square(10)), new Vector(5, 5)));
+ plate.Parts.Add(new Part(new Drawing("b", TestPrograms.Square(10)), new Vector(25, 5)));
return plate;
}
diff --git a/OpenNest.WinForms.Tests/Controls/LayoutPartLabelZoomTests.cs b/OpenNest.WinForms.Tests/Controls/LayoutPartLabelZoomTests.cs
index 0a449e9c..e380efbf 100644
--- a/OpenNest.WinForms.Tests/Controls/LayoutPartLabelZoomTests.cs
+++ b/OpenNest.WinForms.Tests/Controls/LayoutPartLabelZoomTests.cs
@@ -18,7 +18,8 @@ public class LayoutPartLabelZoomTests
{
using var view = new PlateView(ColorSchemeRegistry.Get("Workshop"));
view.Matrix = new Matrix(scale, 0, 0, scale, 0, 0);
- var layout = LayoutPart.Create(new Part(new Drawing("Washer", Square(10)), new Vector(1, 1)), view);
+ var layout = LayoutPart.Create(
+ new Part(new Drawing("Washer", TestPrograms.Square(10)), new Vector(1, 1)), view);
using var withoutId = new Bitmap(80, 80);
using (var g = Graphics.FromImage(withoutId))
@@ -78,15 +79,4 @@ public class LayoutPartLabelZoomTests
return false;
return true;
}
-
- private static OpenNest.CNC.Program Square(double size)
- {
- var program = new OpenNest.CNC.Program();
- program.MoveTo(0, 0);
- program.LineTo(size, 0);
- program.LineTo(size, size);
- program.LineTo(0, size);
- program.LineTo(0, 0);
- return program;
- }
}
diff --git a/OpenNest.WinForms.Tests/Controls/PlateViewReorderTests.cs b/OpenNest.WinForms.Tests/Controls/PlateViewReorderTests.cs
index 4e146326..2ff72392 100644
--- a/OpenNest.WinForms.Tests/Controls/PlateViewReorderTests.cs
+++ b/OpenNest.WinForms.Tests/Controls/PlateViewReorderTests.cs
@@ -10,7 +10,8 @@ public class PlateViewReorderTests
{
var plate = new Plate(100, 100);
foreach (var x in new[] { 1.0, 12.0, 23.0 })
- plate.Parts.Add(new Part(new Drawing($"part {x}", Square()), new Vector(x, 1)));
+ plate.Parts.Add(new Part(
+ new Drawing($"part {x}", TestPrograms.ClockwiseSquare(10)), new Vector(x, 1)));
using var view = new PlateView { Plate = plate };
var parts = plate.Parts.ToArray();
var raised = 0;
@@ -33,8 +34,10 @@ public class PlateViewReorderTests
public void KeepsOneLayoutPerOccurrenceOfARepeatedPart() => StaTestThread.Run(() =>
{
var plate = new Plate(100, 100);
- var repeated = new Part(new Drawing("repeated", Square()), new Vector(1, 1));
- var other = new Part(new Drawing("other", Square()), new Vector(12, 1));
+ var repeated = new Part(
+ new Drawing("repeated", TestPrograms.ClockwiseSquare(10)), new Vector(1, 1));
+ var other = new Part(
+ new Drawing("other", TestPrograms.ClockwiseSquare(10)), new Vector(12, 1));
plate.Parts.Add(repeated);
plate.Parts.Add(repeated);
plate.Parts.Add(other);
@@ -55,7 +58,8 @@ public class PlateViewReorderTests
{
var plate = new Plate(100, 100);
foreach (var x in new[] { 1.0, 12.0 })
- plate.Parts.Add(new Part(new Drawing($"part {x}", Square()), new Vector(x, 1)));
+ plate.Parts.Add(new Part(
+ new Drawing($"part {x}", TestPrograms.ClockwiseSquare(10)), new Vector(x, 1)));
var parts = plate.Parts.ToArray();
var view = new PlateView { Plate = plate };
var raised = 0;
@@ -64,20 +68,10 @@ public class PlateViewReorderTests
view.Dispose();
plate.Parts.Reorder(new[] { parts[1], parts[0] });
- plate.Parts.Add(new Part(new Drawing("late", Square()), new Vector(23, 1)));
+ plate.Parts.Add(new Part(
+ new Drawing("late", TestPrograms.ClockwiseSquare(10)), new Vector(23, 1)));
Assert.Equal(0, raised);
Assert.Equal(layouts, view.LayoutParts);
}, TimeSpan.FromMinutes(1), "The STA test did not complete.");
-
- private static CNC.Program Square()
- {
- var program = new CNC.Program();
- program.MoveTo(0, 0);
- program.LineTo(0, 10);
- program.LineTo(10, 10);
- program.LineTo(10, 0);
- program.LineTo(0, 0);
- return program;
- }
}
diff --git a/OpenNest.WinForms.Tests/Controls/ShapePreviewConcurrencyTests.cs b/OpenNest.WinForms.Tests/Controls/ShapePreviewConcurrencyTests.cs
index 14cf976f..fcf87483 100644
--- a/OpenNest.WinForms.Tests/Controls/ShapePreviewConcurrencyTests.cs
+++ b/OpenNest.WinForms.Tests/Controls/ShapePreviewConcurrencyTests.cs
@@ -7,17 +7,6 @@ namespace OpenNest.WinForms.Tests.Controls;
public class ShapePreviewConcurrencyTests
{
- private static Program Square(double size)
- {
- var program = new Program();
- program.Codes.Add(new RapidMove(0, 0));
- program.Codes.Add(new LinearMove(size, 0));
- program.Codes.Add(new LinearMove(size, size));
- program.Codes.Add(new LinearMove(0, size));
- program.Codes.Add(new LinearMove(0, 0));
- return program;
- }
-
// Parallel test collections paint previews on separate STA threads at once.
// GDI+ objects are not thread-safe, so any pen, brush or font shared between
// views fails with "Object is currently in use elsewhere".
@@ -38,7 +27,7 @@ public class ShapePreviewConcurrencyTests
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
using var preview = new ShapePreviewControl { Size = new Size(200, 200) };
- preview.ShowDrawing(new Drawing("square", Square(10)));
+ preview.ShowDrawing(new Drawing("square", TestPrograms.Square(10)));
preview.SetInfo("10 x 10", "1 part");
using var bitmap = new Bitmap(200, 200);
diff --git a/OpenNest.WinForms.Tests/Forms/ExpandSpacingMenuTests.cs b/OpenNest.WinForms.Tests/Forms/ExpandSpacingMenuTests.cs
index 3e90a394..027b52fc 100644
--- a/OpenNest.WinForms.Tests/Forms/ExpandSpacingMenuTests.cs
+++ b/OpenNest.WinForms.Tests/Forms/ExpandSpacingMenuTests.cs
@@ -18,8 +18,10 @@ public class ExpandSpacingMenuTests
var nest = new Nest("expand job");
var plate = nest.CreatePlate();
plate.Size = new Size(100, 100);
- plate.Parts.Add(new Part(new Drawing("left", Square()), new Vector(1, 1)));
- plate.Parts.Add(new Part(new Drawing("right", Square()), new Vector(12, 1)));
+ plate.Parts.Add(new Part(
+ new Drawing("left", TestPrograms.ClockwiseSquare(10)), new Vector(1, 1)));
+ plate.Parts.Add(new Part(
+ new Drawing("right", TestPrograms.ClockwiseSquare(10)), new Vector(12, 1)));
using var editor = new EditNestForm(nest) { MdiParent = host };
editor.PlateView.SetOverlapAutoCheck(null); // Background overlap workers are irrelevant here.
editor.Show();
@@ -49,17 +51,6 @@ public class ExpandSpacingMenuTests
Assert.False(host.IsExpandSpacingBusy(editor));
}, TimeSpan.FromMinutes(1), "The STA test did not complete.");
- private static CNC.Program Square()
- {
- var program = new CNC.Program();
- program.MoveTo(0, 0);
- program.LineTo(0, 10);
- program.LineTo(10, 10);
- program.LineTo(10, 0);
- program.LineTo(0, 0);
- return program;
- }
-
private static ToolStripMenuItem Menu(MainForm host, string name) =>
(ToolStripMenuItem)host.MainMenuStrip!.Items.Find(name, true).Single();
diff --git a/OpenNest.WinForms.Tests/Forms/MainFormCharacterizationTests.cs b/OpenNest.WinForms.Tests/Forms/MainFormCharacterizationTests.cs
index 28b03ce0..81c39518 100644
--- a/OpenNest.WinForms.Tests/Forms/MainFormCharacterizationTests.cs
+++ b/OpenNest.WinForms.Tests/Forms/MainFormCharacterizationTests.cs
@@ -18,8 +18,10 @@ public class MainFormCharacterizationTests
var nest = new Nest("guards");
var plate = nest.CreatePlate();
plate.Size = new Size(100, 100);
- plate.Parts.Add(new Part(new Drawing("left", Square()), new Vector(1, 1)));
- plate.Parts.Add(new Part(new Drawing("right", Square()), new Vector(12, 1)));
+ plate.Parts.Add(new Part(
+ new Drawing("left", TestPrograms.ClockwiseSquare(10)), new Vector(1, 1)));
+ plate.Parts.Add(new Part(
+ new Drawing("right", TestPrograms.ClockwiseSquare(10)), new Vector(12, 1)));
using var editor = new EditNestForm(nest) { MdiParent = host };
editor.PlateView.SetOverlapAutoCheck(null);
editor.Show();
@@ -96,17 +98,6 @@ public class MainFormCharacterizationTests
.GetField($"<{property}>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic)!
.SetValue(target, value);
- private static CNC.Program Square()
- {
- var program = new CNC.Program();
- program.MoveTo(0, 0);
- program.LineTo(0, 10);
- program.LineTo(10, 10);
- program.LineTo(10, 0);
- program.LineTo(0, 0);
- return program;
- }
-
private sealed class Host : MainForm
{
// No startup migrations/automatic new document, and no settings save at close.
diff --git a/OpenNest.WinForms.Tests/Forms/NestReportExportTests.cs b/OpenNest.WinForms.Tests/Forms/NestReportExportTests.cs
index 9b68f3a7..50cb3898 100644
--- a/OpenNest.WinForms.Tests/Forms/NestReportExportTests.cs
+++ b/OpenNest.WinForms.Tests/Forms/NestReportExportTests.cs
@@ -267,10 +267,10 @@ public class NestReportExportTests
private static Nest CreateJob(string name)
{
var nest = new Nest(name) { Units = Units.Inches };
- var drawing = new Drawing("rect", Rectangle());
+ var drawing = new Drawing("rect", TestPrograms.Rectangle(4, 2));
drawing.Quantity.Required = 2;
nest.Drawings.Add(drawing);
- nest.Drawings.Add(new Drawing("spare", Rectangle()));
+ nest.Drawings.Add(new Drawing("spare", TestPrograms.Rectangle(4, 2)));
var first = new Plate(24, 48) { Quantity = 1 };
first.Parts.Add(new Part(drawing, new Vector(2, 2)));
var second = new Plate(24, 48) { Quantity = 2 };
@@ -280,17 +280,6 @@ public class NestReportExportTests
return nest;
}
- private static Program Rectangle()
- {
- var program = new Program();
- program.Codes.Add(new RapidMove(0, 0));
- program.Codes.Add(new LinearMove(4, 0));
- program.Codes.Add(new LinearMove(4, 2));
- program.Codes.Add(new LinearMove(0, 2));
- program.Codes.Add(new LinearMove(0, 0));
- return program;
- }
-
private static ToolStripMenuItem Menu(MainForm host, string name) =>
(ToolStripMenuItem)host.MainMenuStrip!.Items.Find(name, true).Single();
diff --git a/OpenNest.WinForms.Tests/Forms/OperationProgressFormTests.cs b/OpenNest.WinForms.Tests/Forms/OperationProgressFormTests.cs
index 67b6cdb6..269b3aeb 100644
--- a/OpenNest.WinForms.Tests/Forms/OperationProgressFormTests.cs
+++ b/OpenNest.WinForms.Tests/Forms/OperationProgressFormTests.cs
@@ -126,24 +126,15 @@ public class OperationProgressFormTests
private static PlateView TwoPartView()
{
var plate = new Plate(100, 100);
- plate.Parts.Add(new Part(new Drawing("left", Square()), new Vector(1, 1)));
- plate.Parts.Add(new Part(new Drawing("right", Square()), new Vector(12, 1)));
+ plate.Parts.Add(new Part(
+ new Drawing("left", TestPrograms.ClockwiseSquare(10)), new Vector(1, 1)));
+ plate.Parts.Add(new Part(
+ new Drawing("right", TestPrograms.ClockwiseSquare(10)), new Vector(12, 1)));
var view = new PlateView { Plate = plate };
view.SelectAll();
return view;
}
- private static CNC.Program Square()
- {
- var program = new CNC.Program();
- program.MoveTo(0, 0);
- program.LineTo(0, 10);
- program.LineTo(10, 10);
- program.LineTo(10, 0);
- program.LineTo(0, 0);
- return program;
- }
-
private static void PumpFor(TimeSpan duration)
{
var watch = Stopwatch.StartNew();
diff --git a/OpenNest.WinForms.Tests/Forms/PlateExportTests.cs b/OpenNest.WinForms.Tests/Forms/PlateExportTests.cs
index cfef9140..ec4d9adc 100644
--- a/OpenNest.WinForms.Tests/Forms/PlateExportTests.cs
+++ b/OpenNest.WinForms.Tests/Forms/PlateExportTests.cs
@@ -347,12 +347,12 @@ public class PlateExportTests
private static Nest CreateJob()
{
var nest = new Nest("export job") { Units = Units.Inches };
- var drawing = new Drawing("rect", Rectangle());
+ var drawing = new Drawing("rect", TestPrograms.Rectangle(4, 2));
drawing.Source.Path = @"C:\drawings\rect.dxf";
drawing.Source.Offset = new Vector(1.234567891, -0.987654321);
drawing.Quantity.Required = 12;
nest.Drawings.Add(drawing);
- var spare = new Drawing("spare", Rectangle());
+ var spare = new Drawing("spare", TestPrograms.Rectangle(4, 2));
spare.Source.Path = @"C:\drawings\spare.dxf";
spare.Source.Offset = new Vector(-0.25, 0.5);
spare.Quantity.Required = 5;
@@ -369,17 +369,6 @@ public class PlateExportTests
return nest;
}
- private static Program Rectangle()
- {
- var program = new Program();
- program.Codes.Add(new RapidMove(0, 0));
- program.Codes.Add(new LinearMove(4, 0));
- program.Codes.Add(new LinearMove(4, 2));
- program.Codes.Add(new LinearMove(0, 2));
- program.Codes.Add(new LinearMove(0, 0));
- return program;
- }
-
private static string[] ExpectedLines(Plate plate) => plate.Parts.Select(part =>
{
var pt = part.BaseDrawing.Source.Offset.Rotate(part.Rotation);
diff --git a/OpenNest.WinForms.Tests/TestPrograms.cs b/OpenNest.WinForms.Tests/TestPrograms.cs
new file mode 100644
index 00000000..422b23a7
--- /dev/null
+++ b/OpenNest.WinForms.Tests/TestPrograms.cs
@@ -0,0 +1,34 @@
+using OpenNest.CNC;
+
+namespace OpenNest.WinForms.Tests;
+
+/// Part programs the desktop tests share.
+internal static class TestPrograms
+{
+ /// A width x height rectangle from the origin, counterclockwise: +X first.
+ public static Program Rectangle(double width, double height)
+ {
+ var program = new Program();
+ program.MoveTo(0, 0);
+ program.LineTo(width, 0);
+ program.LineTo(width, height);
+ program.LineTo(0, height);
+ program.LineTo(0, 0);
+ return program;
+ }
+
+ /// A size x size square from the origin, counterclockwise: +X first.
+ public static Program Square(double size) => Rectangle(size, size);
+
+ /// A size x size square from the origin, clockwise: up first.
+ public static Program ClockwiseSquare(double size)
+ {
+ var program = new Program();
+ program.MoveTo(0, 0);
+ program.LineTo(0, size);
+ program.LineTo(size, size);
+ program.LineTo(size, 0);
+ program.LineTo(0, 0);
+ return program;
+ }
+}