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

View File

@@ -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));
}
/// <summary>

View File

@@ -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);

View File

@@ -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)

View File

@@ -30,11 +30,11 @@ namespace OpenNest
IProgress<NestProgress> 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<Part> best = null;
var bestScore = default(FillScore);

View File

@@ -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<SequencedPart>(parts.Count);
foreach (var row in rows)

View File

@@ -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)
};
}
}

View File

@@ -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:

View File

@@ -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)

View File

@@ -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:

View File

@@ -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;