fix: correct Size width/length axis mapping throughout codebase

The Size fix (d4222db) changed Size.Width to Y axis and Size.Length to
X axis but only updated DrawPlate/LayoutViewGL. BoundingBox, WorkArea,
rotations, DXF export, and engine code still used the old Width=X
convention, causing the fill engine to get a swapped work area (60x120
instead of 120x60) and parts to fill in the wrong direction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-17 16:20:24 -04:00
parent a487d33f52
commit 42f2475f3c
10 changed files with 68 additions and 63 deletions
+35 -30
View File
@@ -119,6 +119,9 @@ namespace OpenNest
Size = new Size(Size.Length, Size.Width); 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) if (rotationDirection == RotationType.CW)
{ {
Rotate(oneAndHalfPI); Rotate(oneAndHalfPI);
@@ -128,19 +131,19 @@ namespace OpenNest
switch (Quadrant) switch (Quadrant)
{ {
case 1: case 1:
Offset(0, Size.Length); Offset(0, Size.Width);
break; break;
case 2: case 2:
Offset(-Size.Width, 0); Offset(-Size.Length, 0);
break; break;
case 3: case 3:
Offset(0, -Size.Length); Offset(0, -Size.Width);
break; break;
case 4: case 4:
Offset(Size.Width, 0); Offset(Size.Length, 0);
break; break;
default: default:
@@ -161,19 +164,19 @@ namespace OpenNest
switch (Quadrant) switch (Quadrant)
{ {
case 1: case 1:
Offset(Size.Width, 0); Offset(Size.Length, 0);
break; break;
case 2: case 2:
Offset(0, Size.Length); Offset(0, Size.Width);
break; break;
case 3: case 3:
Offset(-Size.Width, 0); Offset(-Size.Length, 0);
break; break;
case 4: case 4:
Offset(0, -Size.Length); Offset(0, -Size.Width);
break; break;
default: default:
@@ -200,19 +203,19 @@ namespace OpenNest
switch (Quadrant) switch (Quadrant)
{ {
case 1: 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; break;
case 2: 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; break;
case 3: 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; break;
case 4: 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; break;
default: default:
@@ -294,6 +297,7 @@ namespace OpenNest
{ {
var plateBox = new Box(); var plateBox = new Box();
// Convention: Size.Length = X axis (horizontal), Size.Width = Y axis (vertical)
switch (Quadrant) switch (Quadrant)
{ {
case 1: case 1:
@@ -302,26 +306,26 @@ namespace OpenNest
break; break;
case 2: case 2:
plateBox.X = (float)-Size.Width; plateBox.X = (float)-Size.Length;
plateBox.Y = 0; plateBox.Y = 0;
break; break;
case 3: case 3:
plateBox.X = (float)-Size.Width; plateBox.X = (float)-Size.Length;
plateBox.Y = (float)-Size.Length; plateBox.Y = (float)-Size.Width;
break; break;
case 4: case 4:
plateBox.X = 0; plateBox.X = 0;
plateBox.Y = (float)-Size.Length; plateBox.Y = (float)-Size.Width;
break; break;
default: default:
return new Box(); return new Box();
} }
plateBox.Width = Size.Width; plateBox.Width = Size.Length;
plateBox.Length = Size.Length; plateBox.Length = Size.Width;
if (!includeParts) if (!includeParts)
return plateBox; return plateBox;
@@ -382,29 +386,30 @@ namespace OpenNest
var bounds = Parts.GetBoundingBox(); var bounds = Parts.GetBoundingBox();
double width; // Convention: Length = X axis, Width = Y axis
double length; double xExtent;
double yExtent;
switch (Quadrant) switch (Quadrant)
{ {
case 1: case 1:
width = System.Math.Abs(bounds.Right) + EdgeSpacing.Right; xExtent = System.Math.Abs(bounds.Right) + EdgeSpacing.Right;
length = System.Math.Abs(bounds.Top) + EdgeSpacing.Top; yExtent = System.Math.Abs(bounds.Top) + EdgeSpacing.Top;
break; break;
case 2: case 2:
width = System.Math.Abs(bounds.Left) + EdgeSpacing.Left; xExtent = System.Math.Abs(bounds.Left) + EdgeSpacing.Left;
length = System.Math.Abs(bounds.Top) + EdgeSpacing.Top; yExtent = System.Math.Abs(bounds.Top) + EdgeSpacing.Top;
break; break;
case 3: case 3:
width = System.Math.Abs(bounds.Left) + EdgeSpacing.Left; xExtent = System.Math.Abs(bounds.Left) + EdgeSpacing.Left;
length = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom; yExtent = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom;
break; break;
case 4: case 4:
width = System.Math.Abs(bounds.Right) + EdgeSpacing.Right; xExtent = System.Math.Abs(bounds.Right) + EdgeSpacing.Right;
length = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom; yExtent = System.Math.Abs(bounds.Bottom) + EdgeSpacing.Bottom;
break; break;
default: default:
@@ -412,8 +417,8 @@ namespace OpenNest
} }
Size = new Size( Size = new Size(
Rounding.RoundUpToNearest(width, roundingFactor), Rounding.RoundUpToNearest(yExtent, roundingFactor),
Rounding.RoundUpToNearest(length, roundingFactor)); Rounding.RoundUpToNearest(xExtent, roundingFactor));
} }
/// <summary> /// <summary>
@@ -8,8 +8,8 @@ namespace OpenNest.Engine.BestFit.Tiling
{ {
public TileResult Evaluate(BestFitResult bestFit, Plate plate) public TileResult Evaluate(BestFitResult bestFit, Plate plate)
{ {
var plateWidth = plate.Size.Width - plate.EdgeSpacing.Left - plate.EdgeSpacing.Right; var plateWidth = plate.Size.Length - plate.EdgeSpacing.Left - plate.EdgeSpacing.Right;
var plateHeight = plate.Size.Length - plate.EdgeSpacing.Top - plate.EdgeSpacing.Bottom; var plateHeight = plate.Size.Width - plate.EdgeSpacing.Top - plate.EdgeSpacing.Bottom;
var result1 = TryTile(bestFit, plateWidth, plateHeight, false); var result1 = TryTile(bestFit, plateWidth, plateHeight, false);
var result2 = TryTile(bestFit, plateWidth, plateHeight, true); var result2 = TryTile(bestFit, plateWidth, plateHeight, true);
+1 -1
View File
@@ -71,7 +71,7 @@ namespace OpenNest
// Top pair candidates — check if pairs tile better in this box. // Top pair candidates — check if pairs tile better in this box.
var bestFits = BestFitCache.GetOrCompute( 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); var topPairs = bestFits.Where(r => r.Keep).Take(3);
foreach (var pair in topPairs) foreach (var pair in topPairs)
+2 -2
View File
@@ -30,11 +30,11 @@ namespace OpenNest
IProgress<NestProgress> progress = null) IProgress<NestProgress> progress = null)
{ {
var bestFits = BestFitCache.GetOrCompute( var bestFits = BestFitCache.GetOrCompute(
item.Drawing, plateSize.Width, plateSize.Length, partSpacing); item.Drawing, plateSize.Length, plateSize.Width, partSpacing);
var candidates = SelectPairCandidates(bestFits, workArea); var candidates = SelectPairCandidates(bestFits, workArea);
Debug.WriteLine($"[PairFiller] Total: {bestFits.Count}, Kept: {bestFits.Count(r => r.Keep)}, Trying: {candidates.Count}"); 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<Part> best = null; List<Part> best = null;
var bestScore = default(FillScore); var bestScore = default(FillScore);
@@ -28,7 +28,7 @@ namespace OpenNest.Engine.Sequencing
rows.Sort((a, b) => a.RowY.CompareTo(b.RowY)); rows.Sort((a, b) => a.RowY.CompareTo(b.RowY));
// Determine initial direction based on exit point // 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<SequencedPart>(parts.Count); var result = new List<SequencedPart>(parts.Count);
foreach (var row in rows) foreach (var row in rows)
+6 -6
View File
@@ -6,16 +6,16 @@ namespace OpenNest.Engine.Sequencing
{ {
public static Vector GetExitPoint(Plate plate) public static Vector GetExitPoint(Plate plate)
{ {
var w = plate.Size.Width; var xExtent = plate.Size.Length;
var l = plate.Size.Length; var yExtent = plate.Size.Width;
return plate.Quadrant switch return plate.Quadrant switch
{ {
1 => new Vector(w, l), 1 => new Vector(xExtent, yExtent),
2 => new Vector(0, l), 2 => new Vector(0, yExtent),
3 => new Vector(0, 0), 3 => new Vector(0, 0),
4 => new Vector(w, 0), 4 => new Vector(xExtent, 0),
_ => new Vector(w, l) _ => new Vector(xExtent, yExtent)
}; };
} }
} }
+12 -12
View File
@@ -145,30 +145,30 @@ namespace OpenNest.IO
{ {
case 1: case 1:
pt1 = new XYZ(0, 0, 0); pt1 = new XYZ(0, 0, 0);
pt2 = new XYZ(0, plate.Size.Length, 0); pt2 = new XYZ(0, plate.Size.Width, 0);
pt3 = new XYZ(plate.Size.Width, plate.Size.Length, 0); pt3 = new XYZ(plate.Size.Length, plate.Size.Width, 0);
pt4 = new XYZ(plate.Size.Width, 0, 0); pt4 = new XYZ(plate.Size.Length, 0, 0);
break; break;
case 2: case 2:
pt1 = new XYZ(0, 0, 0); pt1 = new XYZ(0, 0, 0);
pt2 = new XYZ(0, plate.Size.Length, 0); pt2 = new XYZ(0, plate.Size.Width, 0);
pt3 = new XYZ(-plate.Size.Width, plate.Size.Length, 0); pt3 = new XYZ(-plate.Size.Length, plate.Size.Width, 0);
pt4 = new XYZ(-plate.Size.Width, 0, 0); pt4 = new XYZ(-plate.Size.Length, 0, 0);
break; break;
case 3: case 3:
pt1 = new XYZ(0, 0, 0); pt1 = new XYZ(0, 0, 0);
pt2 = new XYZ(0, -plate.Size.Length, 0); pt2 = new XYZ(0, -plate.Size.Width, 0);
pt3 = new XYZ(-plate.Size.Width, -plate.Size.Length, 0); pt3 = new XYZ(-plate.Size.Length, -plate.Size.Width, 0);
pt4 = new XYZ(-plate.Size.Width, 0, 0); pt4 = new XYZ(-plate.Size.Length, 0, 0);
break; break;
case 4: case 4:
pt1 = new XYZ(0, 0, 0); pt1 = new XYZ(0, 0, 0);
pt2 = new XYZ(0, -plate.Size.Length, 0); pt2 = new XYZ(0, -plate.Size.Width, 0);
pt3 = new XYZ(plate.Size.Width, -plate.Size.Length, 0); pt3 = new XYZ(plate.Size.Length, -plate.Size.Width, 0);
pt4 = new XYZ(plate.Size.Width, 0, 0); pt4 = new XYZ(plate.Size.Length, 0, 0);
break; break;
default: default:
+1 -1
View File
@@ -205,7 +205,7 @@ namespace OpenNest.Controls
public virtual void ZoomToArea(Box box, bool redraw = true) 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) public virtual void ZoomToArea(double x, double y, double width, double height, bool redraw = true)
+7 -7
View File
@@ -435,24 +435,24 @@ namespace OpenNest.Controls
break; break;
case 2: case 2:
plateRect.Location = PointWorldToGraph(-Plate.Size.Width, 0); plateRect.Location = PointWorldToGraph(-Plate.Size.Length, 0);
edgeSpacingRect.Location = PointWorldToGraph( edgeSpacingRect.Location = PointWorldToGraph(
Plate.EdgeSpacing.Left - Plate.Size.Width, Plate.EdgeSpacing.Left - Plate.Size.Length,
Plate.EdgeSpacing.Bottom); Plate.EdgeSpacing.Bottom);
break; break;
case 3: case 3:
plateRect.Location = PointWorldToGraph(-Plate.Size.Width, -Plate.Size.Length); plateRect.Location = PointWorldToGraph(-Plate.Size.Length, -Plate.Size.Width);
edgeSpacingRect.Location = PointWorldToGraph( edgeSpacingRect.Location = PointWorldToGraph(
Plate.EdgeSpacing.Left - Plate.Size.Width, Plate.EdgeSpacing.Left - Plate.Size.Length,
Plate.EdgeSpacing.Bottom - Plate.Size.Length); Plate.EdgeSpacing.Bottom - Plate.Size.Width);
break; break;
case 4: case 4:
plateRect.Location = PointWorldToGraph(0, -Plate.Size.Length); plateRect.Location = PointWorldToGraph(0, -Plate.Size.Width);
edgeSpacingRect.Location = PointWorldToGraph( edgeSpacingRect.Location = PointWorldToGraph(
Plate.EdgeSpacing.Left, Plate.EdgeSpacing.Left,
Plate.EdgeSpacing.Bottom - Plate.Size.Length); Plate.EdgeSpacing.Bottom - Plate.Size.Width);
break; break;
default: default:
+1 -1
View File
@@ -77,7 +77,7 @@ namespace OpenNest.Forms
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
var all = BestFitCache.GetOrCompute( 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; computeSeconds = sw.ElapsedMilliseconds / 1000.0;
totalResults = all.Count; totalResults = all.Count;