diff --git a/OpenNest.Core/Plate.cs b/OpenNest.Core/Plate.cs index c3c4ba0..87c257a 100644 --- a/OpenNest.Core/Plate.cs +++ b/OpenNest.Core/Plate.cs @@ -119,6 +119,9 @@ namespace OpenNest Size = new Size(Size.Length, Size.Width); + // After Size swap above, new Size.Width = old Length (old X extent), + // new Size.Length = old Width (old Y extent). + // Convention: Length = X axis, Width = Y axis. if (rotationDirection == RotationType.CW) { Rotate(oneAndHalfPI); @@ -128,19 +131,19 @@ namespace OpenNest switch (Quadrant) { case 1: - Offset(0, Size.Length); + Offset(0, Size.Width); break; case 2: - Offset(-Size.Width, 0); + Offset(-Size.Length, 0); break; case 3: - Offset(0, -Size.Length); + Offset(0, -Size.Width); break; case 4: - Offset(Size.Width, 0); + Offset(Size.Length, 0); break; default: @@ -161,19 +164,19 @@ namespace OpenNest switch (Quadrant) { case 1: - Offset(Size.Width, 0); + Offset(Size.Length, 0); break; case 2: - Offset(0, Size.Length); + Offset(0, Size.Width); break; case 3: - Offset(-Size.Width, 0); + Offset(-Size.Length, 0); break; case 4: - Offset(0, -Size.Length); + Offset(0, -Size.Width); break; default: @@ -200,19 +203,19 @@ namespace OpenNest switch (Quadrant) { case 1: - centerpt = new Vector(Size.Width * 0.5, Size.Length * 0.5); + centerpt = new Vector(Size.Length * 0.5, Size.Width * 0.5); break; case 2: - centerpt = new Vector(-Size.Width * 0.5, Size.Length * 0.5); + centerpt = new Vector(-Size.Length * 0.5, Size.Width * 0.5); break; case 3: - centerpt = new Vector(-Size.Width * 0.5, -Size.Length * 0.5); + centerpt = new Vector(-Size.Length * 0.5, -Size.Width * 0.5); break; case 4: - centerpt = new Vector(Size.Width * 0.5, -Size.Length * 0.5); + centerpt = new Vector(Size.Length * 0.5, -Size.Width * 0.5); break; default: @@ -294,6 +297,7 @@ namespace OpenNest { var plateBox = new Box(); + // Convention: Size.Length = X axis (horizontal), Size.Width = Y axis (vertical) switch (Quadrant) { case 1: @@ -302,26 +306,26 @@ namespace OpenNest break; case 2: - plateBox.X = (float)-Size.Width; + plateBox.X = (float)-Size.Length; plateBox.Y = 0; break; case 3: - plateBox.X = (float)-Size.Width; - plateBox.Y = (float)-Size.Length; + plateBox.X = (float)-Size.Length; + plateBox.Y = (float)-Size.Width; break; case 4: plateBox.X = 0; - plateBox.Y = (float)-Size.Length; + plateBox.Y = (float)-Size.Width; break; default: return new Box(); } - plateBox.Width = Size.Width; - plateBox.Length = Size.Length; + plateBox.Width = Size.Length; + plateBox.Length = Size.Width; if (!includeParts) return plateBox; @@ -382,29 +386,30 @@ namespace OpenNest var bounds = Parts.GetBoundingBox(); - double width; - double length; + // Convention: Length = X axis, Width = Y axis + double xExtent; + double yExtent; switch (Quadrant) { case 1: - width = System.Math.Abs(bounds.Right) + EdgeSpacing.Right; - length = System.Math.Abs(bounds.Top) + EdgeSpacing.Top; + xExtent = System.Math.Abs(bounds.Right) + EdgeSpacing.Right; + yExtent = System.Math.Abs(bounds.Top) + EdgeSpacing.Top; break; case 2: - width = System.Math.Abs(bounds.Left) + EdgeSpacing.Left; - length = System.Math.Abs(bounds.Top) + EdgeSpacing.Top; + xExtent = System.Math.Abs(bounds.Left) + EdgeSpacing.Left; + yExtent = System.Math.Abs(bounds.Top) + EdgeSpacing.Top; break; case 3: - width = System.Math.Abs(bounds.Left) + EdgeSpacing.Left; - length = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom; + xExtent = System.Math.Abs(bounds.Left) + EdgeSpacing.Left; + yExtent = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom; break; case 4: - width = System.Math.Abs(bounds.Right) + EdgeSpacing.Right; - length = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom; + xExtent = System.Math.Abs(bounds.Right) + EdgeSpacing.Right; + yExtent = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom; break; default: @@ -412,8 +417,8 @@ namespace OpenNest } Size = new Size( - Rounding.RoundUpToNearest(width, roundingFactor), - Rounding.RoundUpToNearest(length, roundingFactor)); + Rounding.RoundUpToNearest(yExtent, roundingFactor), + Rounding.RoundUpToNearest(xExtent, roundingFactor)); } /// diff --git a/OpenNest.Engine/BestFit/Tiling/TileEvaluator.cs b/OpenNest.Engine/BestFit/Tiling/TileEvaluator.cs index f498ae3..8db666e 100644 --- a/OpenNest.Engine/BestFit/Tiling/TileEvaluator.cs +++ b/OpenNest.Engine/BestFit/Tiling/TileEvaluator.cs @@ -8,8 +8,8 @@ namespace OpenNest.Engine.BestFit.Tiling { public TileResult Evaluate(BestFitResult bestFit, Plate plate) { - var plateWidth = plate.Size.Width - plate.EdgeSpacing.Left - plate.EdgeSpacing.Right; - var plateHeight = plate.Size.Length - plate.EdgeSpacing.Top - plate.EdgeSpacing.Bottom; + var plateWidth = plate.Size.Length - plate.EdgeSpacing.Left - plate.EdgeSpacing.Right; + var plateHeight = plate.Size.Width - plate.EdgeSpacing.Top - plate.EdgeSpacing.Bottom; var result1 = TryTile(bestFit, plateWidth, plateHeight, false); var result2 = TryTile(bestFit, plateWidth, plateHeight, true); diff --git a/OpenNest.Engine/DefaultNestEngine.cs b/OpenNest.Engine/DefaultNestEngine.cs index 8cb765e..df10036 100644 --- a/OpenNest.Engine/DefaultNestEngine.cs +++ b/OpenNest.Engine/DefaultNestEngine.cs @@ -71,7 +71,7 @@ namespace OpenNest // Top pair candidates — check if pairs tile better in this box. var bestFits = BestFitCache.GetOrCompute( - drawing, Plate.Size.Width, Plate.Size.Length, Plate.PartSpacing); + drawing, Plate.Size.Length, Plate.Size.Width, Plate.PartSpacing); var topPairs = bestFits.Where(r => r.Keep).Take(3); foreach (var pair in topPairs) diff --git a/OpenNest.Engine/PairFiller.cs b/OpenNest.Engine/PairFiller.cs index b448c96..8d69362 100644 --- a/OpenNest.Engine/PairFiller.cs +++ b/OpenNest.Engine/PairFiller.cs @@ -30,11 +30,11 @@ namespace OpenNest IProgress progress = null) { var bestFits = BestFitCache.GetOrCompute( - item.Drawing, plateSize.Width, plateSize.Length, partSpacing); + item.Drawing, plateSize.Length, plateSize.Width, partSpacing); var candidates = SelectPairCandidates(bestFits, workArea); Debug.WriteLine($"[PairFiller] Total: {bestFits.Count}, Kept: {bestFits.Count(r => r.Keep)}, Trying: {candidates.Count}"); - Debug.WriteLine($"[PairFiller] Plate: {plateSize.Width:F2}x{plateSize.Length:F2}, WorkArea: {workArea.Width:F2}x{workArea.Length:F2}"); + Debug.WriteLine($"[PairFiller] Plate: {plateSize.Length:F2}x{plateSize.Width:F2}, WorkArea: {workArea.Width:F2}x{workArea.Length:F2}"); List best = null; var bestScore = default(FillScore); diff --git a/OpenNest.Engine/Sequencing/AdvancedSequencer.cs b/OpenNest.Engine/Sequencing/AdvancedSequencer.cs index fa285aa..106b60c 100644 --- a/OpenNest.Engine/Sequencing/AdvancedSequencer.cs +++ b/OpenNest.Engine/Sequencing/AdvancedSequencer.cs @@ -28,7 +28,7 @@ namespace OpenNest.Engine.Sequencing rows.Sort((a, b) => a.RowY.CompareTo(b.RowY)); // Determine initial direction based on exit point - var leftToRight = exit.X > plate.Size.Width * 0.5; + var leftToRight = exit.X > plate.Size.Length * 0.5; var result = new List(parts.Count); foreach (var row in rows) diff --git a/OpenNest.Engine/Sequencing/PlateHelper.cs b/OpenNest.Engine/Sequencing/PlateHelper.cs index 1a46327..04e3282 100644 --- a/OpenNest.Engine/Sequencing/PlateHelper.cs +++ b/OpenNest.Engine/Sequencing/PlateHelper.cs @@ -6,16 +6,16 @@ namespace OpenNest.Engine.Sequencing { public static Vector GetExitPoint(Plate plate) { - var w = plate.Size.Width; - var l = plate.Size.Length; + var xExtent = plate.Size.Length; + var yExtent = plate.Size.Width; return plate.Quadrant switch { - 1 => new Vector(w, l), - 2 => new Vector(0, l), + 1 => new Vector(xExtent, yExtent), + 2 => new Vector(0, yExtent), 3 => new Vector(0, 0), - 4 => new Vector(w, 0), - _ => new Vector(w, l) + 4 => new Vector(xExtent, 0), + _ => new Vector(xExtent, yExtent) }; } } diff --git a/OpenNest.IO/DxfExporter.cs b/OpenNest.IO/DxfExporter.cs index aac67a3..2cfa222 100644 --- a/OpenNest.IO/DxfExporter.cs +++ b/OpenNest.IO/DxfExporter.cs @@ -145,30 +145,30 @@ namespace OpenNest.IO { case 1: pt1 = new XYZ(0, 0, 0); - pt2 = new XYZ(0, plate.Size.Length, 0); - pt3 = new XYZ(plate.Size.Width, plate.Size.Length, 0); - pt4 = new XYZ(plate.Size.Width, 0, 0); + pt2 = new XYZ(0, plate.Size.Width, 0); + pt3 = new XYZ(plate.Size.Length, plate.Size.Width, 0); + pt4 = new XYZ(plate.Size.Length, 0, 0); break; case 2: pt1 = new XYZ(0, 0, 0); - pt2 = new XYZ(0, plate.Size.Length, 0); - pt3 = new XYZ(-plate.Size.Width, plate.Size.Length, 0); - pt4 = new XYZ(-plate.Size.Width, 0, 0); + pt2 = new XYZ(0, plate.Size.Width, 0); + pt3 = new XYZ(-plate.Size.Length, plate.Size.Width, 0); + pt4 = new XYZ(-plate.Size.Length, 0, 0); break; case 3: pt1 = new XYZ(0, 0, 0); - pt2 = new XYZ(0, -plate.Size.Length, 0); - pt3 = new XYZ(-plate.Size.Width, -plate.Size.Length, 0); - pt4 = new XYZ(-plate.Size.Width, 0, 0); + pt2 = new XYZ(0, -plate.Size.Width, 0); + pt3 = new XYZ(-plate.Size.Length, -plate.Size.Width, 0); + pt4 = new XYZ(-plate.Size.Length, 0, 0); break; case 4: pt1 = new XYZ(0, 0, 0); - pt2 = new XYZ(0, -plate.Size.Length, 0); - pt3 = new XYZ(plate.Size.Width, -plate.Size.Length, 0); - pt4 = new XYZ(plate.Size.Width, 0, 0); + pt2 = new XYZ(0, -plate.Size.Width, 0); + pt3 = new XYZ(plate.Size.Length, -plate.Size.Width, 0); + pt4 = new XYZ(plate.Size.Length, 0, 0); break; default: diff --git a/OpenNest/Controls/DrawControl.cs b/OpenNest/Controls/DrawControl.cs index dbaf2ca..3d9f2fc 100644 --- a/OpenNest/Controls/DrawControl.cs +++ b/OpenNest/Controls/DrawControl.cs @@ -205,7 +205,7 @@ namespace OpenNest.Controls public virtual void ZoomToArea(Box box, bool redraw = true) { - ZoomToArea(box.X, box.Y, box.Length, box.Width, redraw); + ZoomToArea(box.X, box.Y, box.Width, box.Length, redraw); } public virtual void ZoomToArea(double x, double y, double width, double height, bool redraw = true) diff --git a/OpenNest/Controls/PlateView.cs b/OpenNest/Controls/PlateView.cs index 630a950..c61d6b4 100644 --- a/OpenNest/Controls/PlateView.cs +++ b/OpenNest/Controls/PlateView.cs @@ -435,24 +435,24 @@ namespace OpenNest.Controls break; case 2: - plateRect.Location = PointWorldToGraph(-Plate.Size.Width, 0); + plateRect.Location = PointWorldToGraph(-Plate.Size.Length, 0); edgeSpacingRect.Location = PointWorldToGraph( - Plate.EdgeSpacing.Left - Plate.Size.Width, + Plate.EdgeSpacing.Left - Plate.Size.Length, Plate.EdgeSpacing.Bottom); break; case 3: - plateRect.Location = PointWorldToGraph(-Plate.Size.Width, -Plate.Size.Length); + plateRect.Location = PointWorldToGraph(-Plate.Size.Length, -Plate.Size.Width); edgeSpacingRect.Location = PointWorldToGraph( - Plate.EdgeSpacing.Left - Plate.Size.Width, - Plate.EdgeSpacing.Bottom - Plate.Size.Length); + Plate.EdgeSpacing.Left - Plate.Size.Length, + Plate.EdgeSpacing.Bottom - Plate.Size.Width); break; case 4: - plateRect.Location = PointWorldToGraph(0, -Plate.Size.Length); + plateRect.Location = PointWorldToGraph(0, -Plate.Size.Width); edgeSpacingRect.Location = PointWorldToGraph( Plate.EdgeSpacing.Left, - Plate.EdgeSpacing.Bottom - Plate.Size.Length); + Plate.EdgeSpacing.Bottom - Plate.Size.Width); break; default: diff --git a/OpenNest/Forms/BestFitViewerForm.cs b/OpenNest/Forms/BestFitViewerForm.cs index 5d590a7..e168c50 100644 --- a/OpenNest/Forms/BestFitViewerForm.cs +++ b/OpenNest/Forms/BestFitViewerForm.cs @@ -77,7 +77,7 @@ namespace OpenNest.Forms var sw = Stopwatch.StartNew(); var all = BestFitCache.GetOrCompute( - drawing, plate.Size.Width, plate.Size.Length, plate.PartSpacing); + drawing, plate.Size.Length, plate.Size.Width, plate.PartSpacing); computeSeconds = sw.ElapsedMilliseconds / 1000.0; totalResults = all.Count;