diff --git a/OpenNest.Core/CutOff.cs b/OpenNest.Core/CutOff.cs index 99a7996..571feab 100644 --- a/OpenNest.Core/CutOff.cs +++ b/OpenNest.Core/CutOff.cs @@ -50,13 +50,13 @@ namespace OpenNest { cutPosition = Position.X; lineStart = StartLimit ?? bounds.Y; - lineEnd = EndLimit ?? (bounds.Y + bounds.Length + settings.Overtravel); + lineEnd = EndLimit ?? (bounds.Y + bounds.Width + settings.Overtravel); } else { cutPosition = Position.Y; lineStart = StartLimit ?? bounds.X; - lineEnd = EndLimit ?? (bounds.X + bounds.Width + settings.Overtravel); + lineEnd = EndLimit ?? (bounds.X + bounds.Length + settings.Overtravel); } var exclusions = new List<(double Start, double End)>(); @@ -176,13 +176,13 @@ namespace OpenNest private (double Min, double Max) AxisBounds(Box bb, double clearance) => Axis == CutOffAxis.Vertical - ? (bb.X - clearance, bb.X + bb.Width + clearance) - : (bb.Y - clearance, bb.Y + bb.Length + clearance); + ? (bb.X - clearance, bb.X + bb.Length + clearance) + : (bb.Y - clearance, bb.Y + bb.Width + clearance); private (double Start, double End) CrossAxisBounds(Box bb, double clearance) => Axis == CutOffAxis.Vertical - ? (bb.Y - clearance, bb.Y + bb.Length + clearance) - : (bb.X - clearance, bb.X + bb.Width + clearance); + ? (bb.Y - clearance, bb.Y + bb.Width + clearance) + : (bb.X - clearance, bb.X + bb.Length + clearance); private Program BuildProgram(List<(double Start, double End)> segments, CutOffSettings settings) { diff --git a/OpenNest.Core/Geometry/Arc.cs b/OpenNest.Core/Geometry/Arc.cs index 1982bce..0ed1272 100644 --- a/OpenNest.Core/Geometry/Arc.cs +++ b/OpenNest.Core/Geometry/Arc.cs @@ -420,8 +420,8 @@ namespace OpenNest.Geometry boundingBox.X = minX; boundingBox.Y = minY; - boundingBox.Width = maxX - minX; - boundingBox.Length = maxY - minY; + boundingBox.Length = maxX - minX; + boundingBox.Width = maxY - minY; } public override Entity OffsetEntity(double distance, OffsetSide side) diff --git a/OpenNest.Core/Geometry/BoundingBox.cs b/OpenNest.Core/Geometry/BoundingBox.cs index bd6ab20..c8e9d1c 100644 --- a/OpenNest.Core/Geometry/BoundingBox.cs +++ b/OpenNest.Core/Geometry/BoundingBox.cs @@ -12,8 +12,8 @@ namespace OpenNest.Geometry double minX = boxes[0].X; double minY = boxes[0].Y; - double maxX = boxes[0].X + boxes[0].Width; - double maxY = boxes[0].Y + boxes[0].Length; + double maxX = boxes[0].Right; + double maxY = boxes[0].Top; foreach (var box in boxes) { diff --git a/OpenNest.Core/Geometry/Box.cs b/OpenNest.Core/Geometry/Box.cs index 7145bb7..49b3fdb 100644 --- a/OpenNest.Core/Geometry/Box.cs +++ b/OpenNest.Core/Geometry/Box.cs @@ -14,15 +14,15 @@ namespace OpenNest.Geometry public Box(double x, double y, double w, double h) { Location = new Vector(x, y); - Width = w; - Length = h; + Length = w; + Width = h; } public Vector Location; public Vector Center { - get { return new Vector(X + Width * 0.5, Y + Length * 0.5); } + get { return new Vector(X + Length * 0.5, Y + Width * 0.5); } } public Size Size; @@ -76,12 +76,12 @@ namespace OpenNest.Geometry public Box Translate(double x, double y) { - return new Box(X + x, Y + y, Width, Length); + return new Box(X + x, Y + y, Length, Width); } public Box Translate(Vector offset) { - return new Box(X + offset.X, Y + offset.Y, Width, Length); + return new Box(X + offset.X, Y + offset.Y, Length, Width); } public double Left @@ -91,12 +91,12 @@ namespace OpenNest.Geometry public double Right { - get { return X + Width; } + get { return X + Length; } } public double Top { - get { return Y + Length; } + get { return Y + Width; } } public double Bottom @@ -207,7 +207,7 @@ namespace OpenNest.Geometry public Box Offset(double d) { - return new Box(X - d, Y - d, Width + d * 2, Length + d * 2); + return new Box(X - d, Y - d, Length + d * 2, Width + d * 2); } public override string ToString() diff --git a/OpenNest.Core/Geometry/BoxSplitter.cs b/OpenNest.Core/Geometry/BoxSplitter.cs index 938e31b..5a17532 100644 --- a/OpenNest.Core/Geometry/BoxSplitter.cs +++ b/OpenNest.Core/Geometry/BoxSplitter.cs @@ -9,7 +9,7 @@ var x = large.Left; var y = small.Top; - var w = large.Width; + var w = large.Length; var h = large.Top - y; return new Box(x, y, w, h); @@ -23,7 +23,7 @@ var x = large.Left; var y = large.Bottom; var w = small.Left - x; - var h = large.Length; + var h = large.Width; return new Box(x, y, w, h); } @@ -35,7 +35,7 @@ var x = large.Left; var y = large.Bottom; - var w = large.Width; + var w = large.Length; var h = small.Top - y; return new Box(x, y, w, h); @@ -49,7 +49,7 @@ var x = small.Right; var y = large.Bottom; var w = large.Right - x; - var h = large.Length; + var h = large.Width; return new Box(x, y, w, h); } diff --git a/OpenNest.Core/Geometry/Line.cs b/OpenNest.Core/Geometry/Line.cs index 696ee97..e0317d8 100644 --- a/OpenNest.Core/Geometry/Line.cs +++ b/OpenNest.Core/Geometry/Line.cs @@ -370,23 +370,23 @@ namespace OpenNest.Geometry if (StartPoint.X < EndPoint.X) { boundingBox.X = StartPoint.X; - boundingBox.Width = EndPoint.X - StartPoint.X; + boundingBox.Length = EndPoint.X - StartPoint.X; } else { boundingBox.X = EndPoint.X; - boundingBox.Width = StartPoint.X - EndPoint.X; + boundingBox.Length = StartPoint.X - EndPoint.X; } if (StartPoint.Y < EndPoint.Y) { boundingBox.Y = StartPoint.Y; - boundingBox.Length = EndPoint.Y - StartPoint.Y; + boundingBox.Width = EndPoint.Y - StartPoint.Y; } else { boundingBox.Y = EndPoint.Y; - boundingBox.Length = StartPoint.Y - EndPoint.Y; + boundingBox.Width = StartPoint.Y - EndPoint.Y; } } diff --git a/OpenNest.Core/Geometry/Polygon.cs b/OpenNest.Core/Geometry/Polygon.cs index 449831e..22e2131 100644 --- a/OpenNest.Core/Geometry/Polygon.cs +++ b/OpenNest.Core/Geometry/Polygon.cs @@ -311,8 +311,8 @@ namespace OpenNest.Geometry boundingBox.X = minX; boundingBox.Y = minY; - boundingBox.Width = maxX - minX; - boundingBox.Length = maxY - minY; + boundingBox.Length = maxX - minX; + boundingBox.Width = maxY - minY; } public override Entity OffsetEntity(double distance, OffsetSide side) diff --git a/OpenNest.Core/Part.cs b/OpenNest.Core/Part.cs index b674e8c..7caea6f 100644 --- a/OpenNest.Core/Part.cs +++ b/OpenNest.Core/Part.cs @@ -277,7 +277,7 @@ namespace OpenNest var part = new Part(BaseDrawing, Program, location + offset, new Box(BoundingBox.X + offset.X, BoundingBox.Y + offset.Y, - BoundingBox.Width, BoundingBox.Length)); + BoundingBox.Length, BoundingBox.Width)); return part; } diff --git a/OpenNest.Core/Plate.cs b/OpenNest.Core/Plate.cs index 01949d7..8e58ea9 100644 --- a/OpenNest.Core/Plate.cs +++ b/OpenNest.Core/Plate.cs @@ -424,7 +424,7 @@ namespace OpenNest { var plateBox = new Box(); - // Convention: Size.Length = X axis (horizontal), Size.Width = Y axis (vertical) + // Width = Y axis (vertical), Length = X axis (horizontal) switch (Quadrant) { case 1: @@ -451,8 +451,8 @@ namespace OpenNest return new Box(); } - plateBox.Width = Size.Length; - plateBox.Length = Size.Width; + plateBox.Width = Size.Width; + plateBox.Length = Size.Length; if (!includeParts) return plateBox; @@ -468,11 +468,11 @@ namespace OpenNest ? partsBox.Bottom : plateBox.Bottom; - boundingBox.Width = partsBox.Right > plateBox.Right + boundingBox.Length = partsBox.Right > plateBox.Right ? partsBox.Right - boundingBox.X : plateBox.Right - boundingBox.X; - boundingBox.Length = partsBox.Top > plateBox.Top + boundingBox.Width = partsBox.Top > plateBox.Top ? partsBox.Top - boundingBox.Y : plateBox.Top - boundingBox.Y; @@ -489,8 +489,8 @@ namespace OpenNest box.X += EdgeSpacing.Left; box.Y += EdgeSpacing.Bottom; - box.Width -= EdgeSpacing.Left + EdgeSpacing.Right; - box.Length -= EdgeSpacing.Top + EdgeSpacing.Bottom; + box.Length -= EdgeSpacing.Left + EdgeSpacing.Right; + box.Width -= EdgeSpacing.Top + EdgeSpacing.Bottom; return box; } diff --git a/OpenNest.Core/Splitting/AutoSplitCalculator.cs b/OpenNest.Core/Splitting/AutoSplitCalculator.cs index af36b12..31420ff 100644 --- a/OpenNest.Core/Splitting/AutoSplitCalculator.cs +++ b/OpenNest.Core/Splitting/AutoSplitCalculator.cs @@ -13,8 +13,8 @@ public static class AutoSplitCalculator var lines = new List(); - var verticalSplits = usableWidth > 0 ? (int)System.Math.Ceiling(partBounds.Width / usableWidth) - 1 : 0; - var horizontalSplits = usableHeight > 0 ? (int)System.Math.Ceiling(partBounds.Length / usableHeight) - 1 : 0; + var verticalSplits = usableWidth > 0 ? (int)System.Math.Ceiling(partBounds.Length / usableWidth) - 1 : 0; + var horizontalSplits = usableHeight > 0 ? (int)System.Math.Ceiling(partBounds.Width / usableHeight) - 1 : 0; if (verticalSplits < 0) verticalSplits = 0; if (horizontalSplits < 0) horizontalSplits = 0; @@ -34,14 +34,14 @@ public static class AutoSplitCalculator if (verticalPieces > 1) { - var spacing = partBounds.Width / verticalPieces; + var spacing = partBounds.Length / verticalPieces; for (var i = 1; i < verticalPieces; i++) lines.Add(new SplitLine(partBounds.X + spacing * i, CutOffAxis.Vertical)); } if (horizontalPieces > 1) { - var spacing = partBounds.Length / horizontalPieces; + var spacing = partBounds.Width / horizontalPieces; for (var i = 1; i < horizontalPieces; i++) lines.Add(new SplitLine(partBounds.Y + spacing * i, CutOffAxis.Horizontal)); } diff --git a/OpenNest.Engine/DefaultNestEngine.cs b/OpenNest.Engine/DefaultNestEngine.cs index d628715..0ee2ab0 100644 --- a/OpenNest.Engine/DefaultNestEngine.cs +++ b/OpenNest.Engine/DefaultNestEngine.cs @@ -203,7 +203,7 @@ namespace OpenNest if (newWidth >= workArea.Width && newLength >= workArea.Length) return workArea; - return new Box(workArea.X, workArea.Y, newWidth, newLength); + return new Box(workArea.X, workArea.Y, newLength, newWidth); } private List RunFillPipeline(NestItem item, Box workArea, diff --git a/OpenNest.Engine/Fill/BestCombination.cs b/OpenNest.Engine/Fill/BestCombination.cs index 7c9a193..2b6c534 100644 --- a/OpenNest.Engine/Fill/BestCombination.cs +++ b/OpenNest.Engine/Fill/BestCombination.cs @@ -2,13 +2,15 @@ namespace OpenNest { + internal record CombinationResult(bool Found, int Count1, int Count2); + internal static class BestCombination { - public static bool FindFrom2(double length1, double length2, double overallLength, out int count1, out int count2) + public static CombinationResult FindFrom2(double length1, double length2, double overallLength) { overallLength += Tolerance.Epsilon; - count1 = 0; - count2 = 0; + var count1 = 0; + var count2 = 0; var maxCount1 = (int)System.Math.Floor(overallLength / length1); var bestRemnant = overallLength + 1; @@ -30,7 +32,7 @@ namespace OpenNest break; } - return count1 > 0 || count2 > 0; + return new CombinationResult(count1 > 0 || count2 > 0, count1, count2); } } } diff --git a/OpenNest.Engine/Fill/FillExtents.cs b/OpenNest.Engine/Fill/FillExtents.cs index 47a3732..a058e24 100644 --- a/OpenNest.Engine/Fill/FillExtents.cs +++ b/OpenNest.Engine/Fill/FillExtents.cs @@ -96,7 +96,7 @@ namespace OpenNest.Engine.Fill var boundary2 = new PartBoundary(part2, halfSpacing); // Position part2 to the right of part1 at bounding box width distance. - var startOffset = part1.BoundingBox.Width + part2.BoundingBox.Width + partSpacing; + var startOffset = part1.BoundingBox.Length + part2.BoundingBox.Length + partSpacing; part2.Offset(startOffset, 0); part2.UpdateBounds(); @@ -135,7 +135,7 @@ namespace OpenNest.Engine.Fill // Compute vertical copy distance using bounding boxes as starting point, // then slide down to find true geometry distance. - var pairHeight = pair.Bbox.Length; + var pairHeight = pair.Bbox.Width; var testOffset = new Vector(0, pairHeight); // Create test parts for slide distance measurement. @@ -218,7 +218,7 @@ namespace OpenNest.Engine.Fill private List AdjustColumn(PartPair pair, List column, CancellationToken token) { - var originalPairWidth = pair.Bbox.Width; + var originalPairWidth = pair.Bbox.Length; for (var iteration = 0; iteration < MaxIterations; iteration++) { @@ -294,7 +294,7 @@ namespace OpenNest.Engine.Fill // Check if the pair got wider. var newBbox = PairBbox(p1, p2); - if (newBbox.Width > originalPairWidth + Tolerance.Epsilon) + if (newBbox.Length > originalPairWidth + Tolerance.Epsilon) return null; return AnchorToWorkArea(p1, p2); diff --git a/OpenNest.Engine/Fill/FillLinear.cs b/OpenNest.Engine/Fill/FillLinear.cs index 600e37a..1368d26 100644 --- a/OpenNest.Engine/Fill/FillLinear.cs +++ b/OpenNest.Engine/Fill/FillLinear.cs @@ -11,7 +11,7 @@ namespace OpenNest.Engine.Fill public FillLinear(Box workArea, double partSpacing) { PartSpacing = partSpacing; - WorkArea = new Box(workArea.X, workArea.Y, workArea.Width, workArea.Length); + WorkArea = new Box(workArea.X, workArea.Y, workArea.Length, workArea.Width); } public Box WorkArea { get; } @@ -41,7 +41,7 @@ namespace OpenNest.Engine.Fill private static double GetDimension(Box box, NestDirection direction) { - return direction == NestDirection.Horizontal ? box.Width : box.Length; + return direction == NestDirection.Horizontal ? box.Length : box.Width; } private static double GetStart(Box box, NestDirection direction) diff --git a/OpenNest.Engine/Fill/PairFiller.cs b/OpenNest.Engine/Fill/PairFiller.cs index 194da8a..52a4f33 100644 --- a/OpenNest.Engine/Fill/PairFiller.cs +++ b/OpenNest.Engine/Fill/PairFiller.cs @@ -175,8 +175,8 @@ namespace OpenNest.Engine.Fill var newTop = remaining.Max(p => p.BoundingBox.Top); return new Box(workArea.X, workArea.Y, - workArea.Width, - System.Math.Min(newTop - workArea.Y, workArea.Length)); + workArea.Length, + System.Math.Min(newTop - workArea.Y, workArea.Width)); } private List EvaluateCandidate(BestFitResult candidate, Drawing drawing, @@ -271,8 +271,8 @@ namespace OpenNest.Engine.Fill var topHeight = System.Math.Max(0, workArea.Top - gridBox.Top); var rightWidth = System.Math.Max(0, workArea.Right - gridBox.Right); - var topArea = workArea.Width * topHeight; - var rightArea = rightWidth * System.Math.Min(gridBox.Top - workArea.Y, workArea.Length); + var topArea = workArea.Length * topHeight; + var rightArea = rightWidth * System.Math.Min(gridBox.Top - workArea.Y, workArea.Width); var remnantArea = topArea + rightArea; return (int)(remnantArea * maxUtilization / partArea) + 1; @@ -292,7 +292,7 @@ namespace OpenNest.Engine.Fill var topLength = workArea.Top - topY; if (topLength >= minDim) { - var topBox = new Box(workArea.X, topY, workArea.Width, topLength); + var topBox = new Box(workArea.X, topY, workArea.Length, topLength); var parts = FillRemnantBox(drawing, topBox, token); if (parts != null && parts.Count > (bestRemnant?.Count ?? 0)) bestRemnant = parts; @@ -303,7 +303,7 @@ namespace OpenNest.Engine.Fill var rightWidth = workArea.Right - rightX; if (rightWidth >= minDim) { - var rightBox = new Box(rightX, workArea.Y, rightWidth, workArea.Length); + var rightBox = new Box(rightX, workArea.Y, rightWidth, workArea.Width); var parts = FillRemnantBox(drawing, rightBox, token); if (parts != null && parts.Count > (bestRemnant?.Count ?? 0)) bestRemnant = parts; diff --git a/OpenNest.Engine/Fill/PartBoundary.cs b/OpenNest.Engine/Fill/PartBoundary.cs index 0937119..ffedbbc 100644 --- a/OpenNest.Engine/Fill/PartBoundary.cs +++ b/OpenNest.Engine/Fill/PartBoundary.cs @@ -24,7 +24,7 @@ namespace OpenNest.Engine.Fill public PartBoundary(Part part, double spacing) { var entities = ConvertProgram.ToGeometry(part.Program) - .Where(e => e.Layer != SpecialLayers.Rapid) + .Where(e => e.Layer == SpecialLayers.Cut) .ToList(); var definedShape = new ShapeProfile(entities); diff --git a/OpenNest.Engine/Fill/PatternTiler.cs b/OpenNest.Engine/Fill/PatternTiler.cs index b9260d3..fe50c80 100644 --- a/OpenNest.Engine/Fill/PatternTiler.cs +++ b/OpenNest.Engine/Fill/PatternTiler.cs @@ -13,15 +13,15 @@ namespace OpenNest.Engine.Fill var cellBox = cell.GetBoundingBox(); var halfSpacing = partSpacing / 2; - var cellWidth = cellBox.Width + partSpacing; - var cellHeight = cellBox.Length + partSpacing; + var cellW = cellBox.Width + partSpacing; + var cellL = cellBox.Length + partSpacing; - if (cellWidth <= 0 || cellHeight <= 0) + if (cellW <= 0 || cellL <= 0) return new List(); - // Size.Width = X-axis, Size.Length = Y-axis - var cols = (int)System.Math.Floor(plateSize.Width / cellWidth); - var rows = (int)System.Math.Floor(plateSize.Length / cellHeight); + // Width = Y axis, Length = X axis + var cols = (int)System.Math.Floor(plateSize.Length / cellL); + var rows = (int)System.Math.Floor(plateSize.Width / cellW); if (cols <= 0 || rows <= 0) return new List(); @@ -37,7 +37,7 @@ namespace OpenNest.Engine.Fill { for (var col = 0; col < cols; col++) { - var tileOffset = baseOffset + new Vector(col * cellWidth, row * cellHeight); + var tileOffset = baseOffset + new Vector(col * cellL, row * cellW); foreach (var part in cell) { diff --git a/OpenNest.Engine/Fill/RemnantFinder.cs b/OpenNest.Engine/Fill/RemnantFinder.cs index fabd193..8d230c4 100644 --- a/OpenNest.Engine/Fill/RemnantFinder.cs +++ b/OpenNest.Engine/Fill/RemnantFinder.cs @@ -304,10 +304,10 @@ namespace OpenNest.Engine.Fill // Edge extensions (priority 1). if (remnant.Right > envelope.Right + eps) - TryAdd(results, envelope.Right, remnant.Bottom, remnant.Right - envelope.Right, remnant.Length, 1, minDim); + TryAdd(results, envelope.Right, remnant.Bottom, remnant.Right - envelope.Right, remnant.Width, 1, minDim); if (remnant.Left < envelope.Left - eps) - TryAdd(results, remnant.Left, remnant.Bottom, envelope.Left - remnant.Left, remnant.Length, 1, minDim); + TryAdd(results, remnant.Left, remnant.Bottom, envelope.Left - remnant.Left, remnant.Width, 1, minDim); if (remnant.Top > envelope.Top + eps) TryAdd(results, innerLeft, envelope.Top, innerRight - innerLeft, remnant.Top - envelope.Top, 1, minDim); diff --git a/OpenNest.Engine/Fill/StripeFiller.cs b/OpenNest.Engine/Fill/StripeFiller.cs index 79f1a17..4150f4f 100644 --- a/OpenNest.Engine/Fill/StripeFiller.cs +++ b/OpenNest.Engine/Fill/StripeFiller.cs @@ -201,8 +201,8 @@ public class StripeFiller private static Box MakeStripeBox(Box workArea, double perpDim, NestDirection primaryAxis) { return primaryAxis == NestDirection.Horizontal - ? new Box(workArea.X, workArea.Y, workArea.Width, perpDim) - : new Box(workArea.X, workArea.Y, perpDim, workArea.Length); + ? new Box(workArea.X, workArea.Y, workArea.Length, perpDim) + : new Box(workArea.X, workArea.Y, perpDim, workArea.Width); } private List FillRemnant(List gridParts, NestDirection primaryAxis) @@ -224,7 +224,7 @@ public class StripeFiller var remnantLength = workArea.Top - remnantY; if (remnantLength < minDim) return null; - remnantBox = new Box(workArea.X, remnantY, workArea.Width, remnantLength); + remnantBox = new Box(workArea.X, remnantY, workArea.Length, remnantLength); } else { @@ -232,7 +232,7 @@ public class StripeFiller var remnantWidth = workArea.Right - remnantX; if (remnantWidth < minDim) return null; - remnantBox = new Box(remnantX, workArea.Y, remnantWidth, workArea.Length); + remnantBox = new Box(remnantX, workArea.Y, remnantWidth, workArea.Width); } Debug.WriteLine($"[StripeFiller] Remnant box: {remnantBox.Width:F2}x{remnantBox.Length:F2}"); @@ -324,7 +324,7 @@ public class StripeFiller { var box = FillHelpers.BuildRotatedPattern(patternParts, 0).BoundingBox; var span0 = GetDimension(box, axis); - var perpSpan0 = axis == NestDirection.Horizontal ? box.Length : box.Width; + var perpSpan0 = axis == NestDirection.Horizontal ? box.Width : box.Length; if (span0 <= perpSpan0) return 0; @@ -388,7 +388,7 @@ public class StripeFiller var rotated = FillHelpers.BuildRotatedPattern(patternParts, currentAngle); var pairSpan = GetDimension(rotated.BoundingBox, axis); var perpDim = axis == NestDirection.Horizontal - ? rotated.BoundingBox.Length : rotated.BoundingBox.Width; + ? rotated.BoundingBox.Width : rotated.BoundingBox.Length; if (pairSpan + spacing <= 0) break; @@ -472,13 +472,13 @@ public class StripeFiller { var rotated = FillHelpers.BuildRotatedPattern(patternParts, angle); return axis == NestDirection.Horizontal - ? rotated.BoundingBox.Width - : rotated.BoundingBox.Length; + ? rotated.BoundingBox.Length + : rotated.BoundingBox.Width; } private static double GetDimension(Box box, NestDirection axis) { - return axis == NestDirection.Horizontal ? box.Width : box.Length; + return axis == NestDirection.Horizontal ? box.Length : box.Width; } private static bool HasOverlappingParts(List parts) => diff --git a/OpenNest.Engine/HorizontalRemnantEngine.cs b/OpenNest.Engine/HorizontalRemnantEngine.cs index 06e7e13..16b31eb 100644 --- a/OpenNest.Engine/HorizontalRemnantEngine.cs +++ b/OpenNest.Engine/HorizontalRemnantEngine.cs @@ -38,7 +38,7 @@ namespace OpenNest var bb = item.Drawing.Program.BoundingBox(); var cos = System.Math.Abs(System.Math.Cos(angle)); var sin = System.Math.Abs(System.Math.Sin(angle)); - return bb.Length * cos + bb.Width * sin; + return bb.Width * cos + bb.Length * sin; } } } diff --git a/OpenNest.Engine/ML/FeatureExtractor.cs b/OpenNest.Engine/ML/FeatureExtractor.cs index 7103065..e795316 100644 --- a/OpenNest.Engine/ML/FeatureExtractor.cs +++ b/OpenNest.Engine/ML/FeatureExtractor.cs @@ -47,7 +47,7 @@ namespace OpenNest.Engine.ML { Area = drawing.Area, Convexity = drawing.Area / (hullArea > 0 ? hullArea : 1.0), - AspectRatio = bb.Width / (bb.Length > 0 ? bb.Length : 1.0), + AspectRatio = bb.Length / (bb.Width > 0 ? bb.Width : 1.0), BoundingBoxFill = drawing.Area / (bb.Area() > 0 ? bb.Area() : 1.0), VertexCount = polygon.Vertices.Count, Bitmask = GenerateBitmask(polygon, 32) @@ -72,8 +72,8 @@ namespace OpenNest.Engine.ML for (int x = 0; x < size; x++) { // Map grid coordinate (0..size) to bounding box coordinate - var px = bb.Left + (x + 0.5) * (bb.Width / size); - var py = bb.Bottom + (y + 0.5) * (bb.Length / size); + var px = bb.Left + (x + 0.5) * (bb.Length / size); + var py = bb.Bottom + (y + 0.5) * (bb.Width / size); if (polygon.ContainsPoint(new Vector(px, py))) { diff --git a/OpenNest.Engine/RectanglePacking/FillBestFit.cs b/OpenNest.Engine/RectanglePacking/FillBestFit.cs index dd73084..1917b85 100644 --- a/OpenNest.Engine/RectanglePacking/FillBestFit.cs +++ b/OpenNest.Engine/RectanglePacking/FillBestFit.cs @@ -29,11 +29,15 @@ namespace OpenNest.RectanglePacking Bin.Items.AddRange(bin1.Items); else Bin.Items.AddRange(bin2.Items); - } + } + public override void Fill(Item item, int maxCount) { - throw new NotImplementedException(); + Fill(item); + + if (Bin.Items.Count > maxCount) + Bin.Items.RemoveRange(maxCount, Bin.Items.Count - maxCount); } private Bin BestFitHorizontal(Item item) => BestFitAxis(item, horizontal: true); @@ -44,14 +48,18 @@ namespace OpenNest.RectanglePacking { var bin = Bin.Clone() as Bin; - var primarySize = horizontal ? item.Width : item.Length; - var secondarySize = horizontal ? item.Length : item.Width; - var binPrimary = horizontal ? bin.Width : Bin.Length; - var binSecondary = horizontal ? bin.Length : Bin.Width; + var primarySize = horizontal ? item.Length : item.Width; + var secondarySize = horizontal ? item.Width : item.Length; + var binPrimary = horizontal ? bin.Length : Bin.Width; + var binSecondary = horizontal ? bin.Width : Bin.Length; - if (!BestCombination.FindFrom2(primarySize, secondarySize, binPrimary, out var normalPrimary, out var rotatePrimary)) + var combo = BestCombination.FindFrom2(primarySize, secondarySize, binPrimary); + if (!combo.Found) return bin; + var normalPrimary = combo.Count1; + var rotatePrimary = combo.Count2; + var normalSecondary = (int)System.Math.Floor((binSecondary + Tolerance.Epsilon) / secondarySize); var rotateSecondary = (int)System.Math.Floor((binSecondary + Tolerance.Epsilon) / primarySize); @@ -67,9 +75,9 @@ namespace OpenNest.RectanglePacking bin.Items.AddRange(FillGrid(item, normalRows, normalCols, int.MaxValue)); if (horizontal) - item.Location.X += item.Width * normalPrimary; + item.Location.X += item.Length * normalPrimary; else - item.Location.Y += item.Length * normalPrimary; + item.Location.Y += item.Width * normalPrimary; item.Rotate(); diff --git a/OpenNest.Engine/RectanglePacking/FillEngine.cs b/OpenNest.Engine/RectanglePacking/FillEngine.cs index ac2ae46..857c44b 100644 --- a/OpenNest.Engine/RectanglePacking/FillEngine.cs +++ b/OpenNest.Engine/RectanglePacking/FillEngine.cs @@ -27,8 +27,8 @@ namespace OpenNest.RectanglePacking { for (var j = 0; j < innerCount; j++) { - var x = (columnMajor ? i : j) * item.Width + item.X; - var y = (columnMajor ? j : i) * item.Length + item.Y; + var x = (columnMajor ? i : j) * item.Length + item.X; + var y = (columnMajor ? j : i) * item.Width + item.Y; var clone = item.Clone() as Item; clone.Location = new Vector(x, y); diff --git a/OpenNest.Engine/RectanglePacking/FillNoRotation.cs b/OpenNest.Engine/RectanglePacking/FillNoRotation.cs index 3fe6443..1870be8 100644 --- a/OpenNest.Engine/RectanglePacking/FillNoRotation.cs +++ b/OpenNest.Engine/RectanglePacking/FillNoRotation.cs @@ -14,16 +14,16 @@ namespace OpenNest.RectanglePacking public override void Fill(Item item) { - var ycount = (int)System.Math.Floor((Bin.Length + Tolerance.Epsilon) / item.Length); - var xcount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width); + var ycount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width); + var xcount = (int)System.Math.Floor((Bin.Length + Tolerance.Epsilon) / item.Length); for (int i = 0; i < xcount; i++) { - var x = item.Width * i + Bin.X; + var x = item.Length * i + Bin.X; for (int j = 0; j < ycount; j++) { - var y = item.Length * j + Bin.Y; + var y = item.Width * j + Bin.Y; var addedItem = item.Clone() as Item; addedItem.Location = new Vector(x, y); @@ -35,8 +35,8 @@ namespace OpenNest.RectanglePacking public override void Fill(Item item, int maxCount) { - var ycount = (int)System.Math.Floor((Bin.Length + Tolerance.Epsilon) / item.Length); - var xcount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width); + var ycount = (int)System.Math.Floor((Bin.Width + Tolerance.Epsilon) / item.Width); + var xcount = (int)System.Math.Floor((Bin.Length + Tolerance.Epsilon) / item.Length); var count = ycount * xcount; if (count <= maxCount) diff --git a/OpenNest.Engine/RectanglePacking/FillSpiral.cs b/OpenNest.Engine/RectanglePacking/FillSpiral.cs new file mode 100644 index 0000000..855295c --- /dev/null +++ b/OpenNest.Engine/RectanglePacking/FillSpiral.cs @@ -0,0 +1,83 @@ +using OpenNest.Geometry; +using OpenNest.Math; + +namespace OpenNest.RectanglePacking +{ + internal class FillSpiral : FillEngine + { + public Box CenterRemnant { get; private set; } + + public FillSpiral(Bin bin) + : base(bin) + { + } + + public override void Fill(Item item) + { + Fill(item, int.MaxValue); + } + + public override void Fill(Item item, int maxCount) + { + if (item == null) return; + + // Width = Y axis, Length = X axis + var comboY = BestCombination.FindFrom2(item.Width, item.Length, Bin.Width); + var comboX = BestCombination.FindFrom2(item.Length, item.Width, Bin.Length); + + if (!comboY.Found || !comboX.Found) + return; + + var q14size = new Size( + item.Width * comboY.Count1, + item.Length * comboX.Count1); + var q23size = new Size( + item.Length * comboY.Count2, + item.Width * comboX.Count2); + + if ((q14size.Width > q23size.Width && q14size.Length > q23size.Length) || + (q23size.Width > q14size.Width && q23size.Length > q14size.Length)) + return; // cant do an efficient spiral fill + + // Q1: normal orientation at bin origin + item.Location = Bin.Location; + var q1 = FillGrid(item, comboY.Count1, comboX.Count1, maxCount); + Bin.Items.AddRange(q1); + + // Q2: rotated, above Q1 + item.Rotate(); + item.Location = new Vector(Bin.X, Bin.Y + q14size.Width); + var q2 = FillGrid(item, comboY.Count2, comboX.Count2, maxCount - Bin.Items.Count); + Bin.Items.AddRange(q2); + + // Q3: rotated, right of Q1 + item.Location = new Vector(Bin.X + q14size.Length, Bin.Y); + var q3 = FillGrid(item, comboY.Count2, comboX.Count2, maxCount - Bin.Items.Count); + Bin.Items.AddRange(q3); + + // Q4: normal orientation, diagonal from Q1 + item.Rotate(); + item.Location = new Vector( + Bin.X + q23size.Length, + Bin.Y + q23size.Width); + var q4 = FillGrid(item, comboY.Count1, comboX.Count1, maxCount); + Bin.Items.AddRange(q4); + + // Compute center remnant — the rectangular gap between the 4 quadrants + // Only valid when all 4 quadrants have items; otherwise the "center" + // overlaps an occupied quadrant and recursion never terminates. + var centerW = System.Math.Abs(q14size.Length - q23size.Length); + var centerH = System.Math.Abs(q14size.Width - q23size.Width); + + if (comboY.Count1 > 0 && comboY.Count2 > 0 && comboX.Count1 > 0 && comboX.Count2 > 0 + && centerW > Tolerance.Epsilon && centerH > Tolerance.Epsilon) + { + CenterRemnant = new Box( + Bin.X + System.Math.Min(q14size.Length, q23size.Length), + Bin.Y + System.Math.Min(q14size.Width, q23size.Width), + centerW, + centerH); + } + } + } +} diff --git a/OpenNest.Engine/RectanglePacking/Item.cs b/OpenNest.Engine/RectanglePacking/Item.cs index 5eccda9..d5ff03d 100644 --- a/OpenNest.Engine/RectanglePacking/Item.cs +++ b/OpenNest.Engine/RectanglePacking/Item.cs @@ -37,8 +37,8 @@ namespace OpenNest.RectanglePacking double minX = items[0].X; double minY = items[0].Y; - double maxX = items[0].X + items[0].Width; - double maxY = items[0].Y + items[0].Length; + double maxX = items[0].Right; + double maxY = items[0].Top; foreach (var box in items) { diff --git a/OpenNest.Engine/RectanglePacking/PackFirstFitDecreasing.cs b/OpenNest.Engine/RectanglePacking/PackFirstFitDecreasing.cs index 6c1a078..62cdbed 100644 --- a/OpenNest.Engine/RectanglePacking/PackFirstFitDecreasing.cs +++ b/OpenNest.Engine/RectanglePacking/PackFirstFitDecreasing.cs @@ -16,11 +16,11 @@ namespace OpenNest.RectanglePacking public override void Pack(List items) { - items = items.OrderBy(i => -i.Length).ToList(); + items = items.OrderBy(i => -i.Width).ToList(); foreach (var item in items) { - if (item.Length > Bin.Length) + if (item.Width > Bin.Width) continue; var level = FindLevel(item); @@ -36,10 +36,10 @@ namespace OpenNest.RectanglePacking { foreach (var level in levels) { - if (level.Height < item.Length) + if (level.Height < item.Width) continue; - if (level.RemainingWidth < item.Width) + if (level.RemainingLength < item.Length) continue; return level; @@ -58,12 +58,12 @@ namespace OpenNest.RectanglePacking var remaining = Bin.Top - y; - if (remaining < item.Length) + if (remaining < item.Width) return null; var level = new Level(Bin); level.Y = y; - level.Height = item.Length; + level.Height = item.Width; levels.Add(level); @@ -93,9 +93,9 @@ namespace OpenNest.RectanglePacking set { NextItemLocation.Y = value; } } - public double Width + public double LevelLength { - get { return Parent.Width; } + get { return Parent.Length; } } public double Height { get; set; } @@ -105,9 +105,9 @@ namespace OpenNest.RectanglePacking get { return Y + Height; } } - public double RemainingWidth + public double RemainingLength { - get { return X + Width - NextItemLocation.X; } + get { return X + LevelLength - NextItemLocation.X; } } public void AddItem(Item item) @@ -115,7 +115,7 @@ namespace OpenNest.RectanglePacking item.Location = NextItemLocation; Parent.Items.Add(item); - NextItemLocation = new Vector(NextItemLocation.X + item.Width, NextItemLocation.Y); + NextItemLocation = new Vector(NextItemLocation.X + item.Length, NextItemLocation.Y); } } } diff --git a/OpenNest.Engine/RectanglePacking/RectFill.cs b/OpenNest.Engine/RectanglePacking/RectFill.cs new file mode 100644 index 0000000..ef539eb --- /dev/null +++ b/OpenNest.Engine/RectanglePacking/RectFill.cs @@ -0,0 +1,44 @@ +using OpenNest.Geometry; + +namespace OpenNest.RectanglePacking +{ + internal static class RectFill + { + public static void FillBest(Bin bin, Item item, int maxCount = int.MaxValue) + { + var spiralBin = bin.Clone() as Bin; + var spiral = new FillSpiral(spiralBin); + spiral.Fill(item, maxCount); + + // Recursively fill the center remnant of the spiral + if (spiralBin.Items.Count > 0 && spiral.CenterRemnant != null) + { + var center = spiral.CenterRemnant; + var fitsNormal = item.Length <= center.Length && item.Width <= center.Width; + var fitsRotated = item.Width <= center.Length && item.Length <= center.Width; + + if (fitsNormal || fitsRotated) + { + var remaining = maxCount - spiralBin.Items.Count; + FillBest(center.Location, center.Size, spiralBin, item, remaining); + } + } + + var bestFitBin = bin.Clone() as Bin; + new FillBestFit(bestFitBin).Fill(item, maxCount); + + var winner = spiralBin.Items.Count >= bestFitBin.Items.Count ? spiralBin : bestFitBin; + bin.Items.AddRange(winner.Items); + } + + public static void FillBest(Vector location, Size size, Bin target, Item item, int maxCount) + { + if (size.Width <= 0 || size.Length <= 0 || maxCount <= 0) + return; + + var bin = new Bin { Location = location, Size = size }; + FillBest(bin, item, maxCount); + target.Items.AddRange(bin.Items); + } + } +} diff --git a/OpenNest.Engine/Strategies/RectBestFitStrategy.cs b/OpenNest.Engine/Strategies/RectBestFitStrategy.cs index d045b2c..b0856a1 100644 --- a/OpenNest.Engine/Strategies/RectBestFitStrategy.cs +++ b/OpenNest.Engine/Strategies/RectBestFitStrategy.cs @@ -14,8 +14,7 @@ namespace OpenNest.Engine.Strategies var binItem = BinConverter.ToItem(context.Item, context.Plate.PartSpacing); var bin = BinConverter.CreateBin(context.WorkArea, context.Plate.PartSpacing); - var engine = new FillBestFit(bin); - engine.Fill(binItem); + RectFill.FillBest(bin, binItem); return BinConverter.ToParts(bin, new List { context.Item }); } diff --git a/OpenNest.Engine/VerticalRemnantEngine.cs b/OpenNest.Engine/VerticalRemnantEngine.cs index b7f6791..510f1bb 100644 --- a/OpenNest.Engine/VerticalRemnantEngine.cs +++ b/OpenNest.Engine/VerticalRemnantEngine.cs @@ -36,7 +36,7 @@ namespace OpenNest var bb = item.Drawing.Program.BoundingBox(); var cos = System.Math.Abs(System.Math.Cos(angle)); var sin = System.Math.Abs(System.Math.Sin(angle)); - return bb.Width * cos + bb.Length * sin; + return bb.Length * cos + bb.Width * sin; } } } diff --git a/OpenNest.Tests/Engine/NestProgressTests.cs b/OpenNest.Tests/Engine/NestProgressTests.cs index e89a29e..f94a5af 100644 --- a/OpenNest.Tests/Engine/NestProgressTests.cs +++ b/OpenNest.Tests/Engine/NestProgressTests.cs @@ -49,7 +49,7 @@ public class NestProgressTests var parts = new List { TestHelpers.MakePartAt(0, 0, 5), - TestHelpers.MakePartAt(10, 0, 5), + TestHelpers.MakePartAt(0, 10, 5), }; var progress = new NestProgress { BestParts = parts }; Assert.Equal(15, progress.NestedWidth, precision: 4); @@ -61,7 +61,7 @@ public class NestProgressTests var parts = new List { TestHelpers.MakePartAt(0, 0, 5), - TestHelpers.MakePartAt(0, 10, 5), + TestHelpers.MakePartAt(10, 0, 5), }; var progress = new NestProgress { BestParts = parts }; Assert.Equal(15, progress.NestedLength, precision: 4); diff --git a/OpenNest.Tests/Fill/BestCombinationTests.cs b/OpenNest.Tests/Fill/BestCombinationTests.cs index c3cab28..54437d7 100644 --- a/OpenNest.Tests/Fill/BestCombinationTests.cs +++ b/OpenNest.Tests/Fill/BestCombinationTests.cs @@ -6,61 +6,61 @@ public class BestCombinationTests public void BothFit_FindsZeroRemnant() { // 100 = 0*30 + 5*20 (algorithm iterates from countLength1=0, finds zero remnant first) - var result = BestCombination.FindFrom2(30, 20, 100, out var c1, out var c2); + var result = BestCombination.FindFrom2(30, 20, 100); - Assert.True(result); - Assert.Equal(0.0, 100.0 - (c1 * 30.0 + c2 * 20.0), 5); + Assert.True(result.Found); + Assert.Equal(0.0, 100.0 - (result.Count1 * 30.0 + result.Count2 * 20.0), 5); } [Fact] public void OnlyLength1Fits_ReturnsMaxCount1() { - var result = BestCombination.FindFrom2(10, 200, 50, out var c1, out var c2); + var result = BestCombination.FindFrom2(10, 200, 50); - Assert.True(result); - Assert.Equal(5, c1); - Assert.Equal(0, c2); + Assert.True(result.Found); + Assert.Equal(5, result.Count1); + Assert.Equal(0, result.Count2); } [Fact] public void OnlyLength2Fits_ReturnsMaxCount2() { - var result = BestCombination.FindFrom2(200, 10, 50, out var c1, out var c2); + var result = BestCombination.FindFrom2(200, 10, 50); - Assert.True(result); - Assert.Equal(0, c1); - Assert.Equal(5, c2); + Assert.True(result.Found); + Assert.Equal(0, result.Count1); + Assert.Equal(5, result.Count2); } [Fact] public void NeitherFits_ReturnsFalse() { - var result = BestCombination.FindFrom2(100, 200, 50, out var c1, out var c2); + var result = BestCombination.FindFrom2(100, 200, 50); - Assert.False(result); - Assert.Equal(0, c1); - Assert.Equal(0, c2); + Assert.False(result.Found); + Assert.Equal(0, result.Count1); + Assert.Equal(0, result.Count2); } [Fact] public void Length1FillsExactly_ZeroRemnant() { - var result = BestCombination.FindFrom2(25, 10, 100, out var c1, out var c2); + var result = BestCombination.FindFrom2(25, 10, 100); - Assert.True(result); - Assert.Equal(0.0, 100.0 - (c1 * 25.0 + c2 * 10.0), 5); + Assert.True(result.Found); + Assert.Equal(0.0, 100.0 - (result.Count1 * 25.0 + result.Count2 * 10.0), 5); } [Fact] public void MixMinimizesRemnant() { // 7 and 3 into 20: best is 2*7 + 2*3 = 20 (zero remnant) - var result = BestCombination.FindFrom2(7, 3, 20, out var c1, out var c2); + var result = BestCombination.FindFrom2(7, 3, 20); - Assert.True(result); - Assert.Equal(2, c1); - Assert.Equal(2, c2); - Assert.True(c1 * 7 + c2 * 3 <= 20); + Assert.True(result.Found); + Assert.Equal(2, result.Count1); + Assert.Equal(2, result.Count2); + Assert.True(result.Count1 * 7 + result.Count2 * 3 <= 20); } [Fact] @@ -68,28 +68,28 @@ public class BestCombinationTests { // 6 and 5 into 17: // all length1: 2*6=12, remnant=5 -> actually 2*6+1*5=17 perfect - var result = BestCombination.FindFrom2(6, 5, 17, out var c1, out var c2); + var result = BestCombination.FindFrom2(6, 5, 17); - Assert.True(result); - Assert.Equal(0.0, 17.0 - (c1 * 6.0 + c2 * 5.0), 5); + Assert.True(result.Found); + Assert.Equal(0.0, 17.0 - (result.Count1 * 6.0 + result.Count2 * 5.0), 5); } [Fact] public void EqualLengths_FillsWithLength1() { - var result = BestCombination.FindFrom2(10, 10, 50, out var c1, out var c2); + var result = BestCombination.FindFrom2(10, 10, 50); - Assert.True(result); - Assert.Equal(5, c1 + c2); + Assert.True(result.Found); + Assert.Equal(5, result.Count1 + result.Count2); } [Fact] public void SmallLengths_LargeOverall() { - var result = BestCombination.FindFrom2(3, 7, 100, out var c1, out var c2); + var result = BestCombination.FindFrom2(3, 7, 100); - Assert.True(result); - var used = c1 * 3.0 + c2 * 7.0; + Assert.True(result.Found); + var used = result.Count1 * 3.0 + result.Count2 * 7.0; Assert.True(used <= 100); Assert.True(100 - used < 3); // remnant less than smallest piece } @@ -100,41 +100,41 @@ public class BestCombinationTests // length1=9, length2=5, overall=10: // length1 alone: 1*9=9 remnant=1 // length2 alone: 2*5=10 remnant=0 - var result = BestCombination.FindFrom2(9, 5, 10, out var c1, out var c2); + var result = BestCombination.FindFrom2(9, 5, 10); - Assert.True(result); - Assert.Equal(0, c1); - Assert.Equal(2, c2); + Assert.True(result.Found); + Assert.Equal(0, result.Count1); + Assert.Equal(2, result.Count2); } [Fact] public void FractionalLengths_WorkCorrectly() { - var result = BestCombination.FindFrom2(2.5, 3.5, 12, out var c1, out var c2); + var result = BestCombination.FindFrom2(2.5, 3.5, 12); - Assert.True(result); - var used = c1 * 2.5 + c2 * 3.5; + Assert.True(result.Found); + var used = result.Count1 * 2.5 + result.Count2 * 3.5; Assert.True(used <= 12.0 + 0.001); } [Fact] public void OverallExactlyOneOfEach() { - var result = BestCombination.FindFrom2(40, 60, 100, out var c1, out var c2); + var result = BestCombination.FindFrom2(40, 60, 100); - Assert.True(result); - Assert.Equal(1, c1); - Assert.Equal(1, c2); + Assert.True(result.Found); + Assert.Equal(1, result.Count1); + Assert.Equal(1, result.Count2); } [Fact] public void OverallSmallerThanEither_ReturnsFalse() { - var result = BestCombination.FindFrom2(10, 20, 5, out var c1, out var c2); + var result = BestCombination.FindFrom2(10, 20, 5); - Assert.False(result); - Assert.Equal(0, c1); - Assert.Equal(0, c2); + Assert.False(result.Found); + Assert.Equal(0, result.Count1); + Assert.Equal(0, result.Count2); } [Fact] @@ -142,9 +142,9 @@ public class BestCombinationTests { // 4 and 6 into 24: 0*4+4*6=24 or 3*4+2*6=24 or 6*4+0*6=24 // Algorithm iterates from 0 length1 upward, finds zero remnant and breaks - var result = BestCombination.FindFrom2(4, 6, 24, out var c1, out var c2); + var result = BestCombination.FindFrom2(4, 6, 24); - Assert.True(result); - Assert.Equal(0.0, 24.0 - (c1 * 4.0 + c2 * 6.0), 5); + Assert.True(result.Found); + Assert.Equal(0.0, 24.0 - (result.Count1 * 4.0 + result.Count2 * 6.0), 5); } } diff --git a/OpenNest.Tests/Fill/PatternTilerTests.cs b/OpenNest.Tests/Fill/PatternTilerTests.cs index 4a49d81..be91264 100644 --- a/OpenNest.Tests/Fill/PatternTilerTests.cs +++ b/OpenNest.Tests/Fill/PatternTilerTests.cs @@ -30,8 +30,8 @@ public class PatternTilerTests foreach (var part in result) { - Assert.True(part.BoundingBox.Right <= plateSize.Width + 0.001); - Assert.True(part.BoundingBox.Top <= plateSize.Length + 0.001); + Assert.True(part.BoundingBox.Right <= plateSize.Length + 0.001); + Assert.True(part.BoundingBox.Top <= plateSize.Width + 0.001); Assert.True(part.BoundingBox.Left >= -0.001); Assert.True(part.BoundingBox.Bottom >= -0.001); } @@ -87,8 +87,8 @@ public class PatternTilerTests var maxRight = result.Max(p => p.BoundingBox.Right); var maxTop = result.Max(p => p.BoundingBox.Top); - Assert.True(maxRight <= 50.001); - Assert.True(maxTop <= 10.001); + Assert.True(maxRight <= 10.001); + Assert.True(maxTop <= 50.001); } [Fact] diff --git a/OpenNest.Tests/Fill/RemnantFinderTests.cs b/OpenNest.Tests/Fill/RemnantFinderTests.cs index 48f2431..f667da6 100644 --- a/OpenNest.Tests/Fill/RemnantFinderTests.cs +++ b/OpenNest.Tests/Fill/RemnantFinderTests.cs @@ -108,8 +108,8 @@ public class RemnantFinderTests var remnants = finder.FindRemnants(); var gap = remnants.FirstOrDefault(r => - r.Width >= 19.9 && r.Width <= 20.1 && - r.Length >= 99.9); + r.Length >= 19.9 && r.Length <= 20.1 && + r.Width >= 99.9); Assert.NotNull(gap); } @@ -146,8 +146,8 @@ public class RemnantFinderTests // Should find the 80x100 strip on the left var left = remnants.FirstOrDefault(r => - r.Width >= 79.9 && r.Width <= 80.1 && - r.Length >= 99.9); + r.Length >= 79.9 && r.Length <= 80.1 && + r.Width >= 99.9); Assert.NotNull(left); } @@ -186,7 +186,7 @@ public class RemnantFinderTests var remnants = finder.FindRemnants(); var gap = remnants.FirstOrDefault(r => - r.Width >= 19.9 && r.Width <= 20.1); + r.Length >= 19.9 && r.Length <= 20.1); Assert.NotNull(gap); } @@ -202,7 +202,7 @@ public class RemnantFinderTests var remnants = finder.FindRemnants(); var gap = remnants.FirstOrDefault(r => - r.Width >= 19.9 && r.Width <= 20.1); + r.Length >= 19.9 && r.Length <= 20.1); Assert.NotNull(gap); } @@ -280,9 +280,9 @@ public class RemnantFinderTests finder.AddObstacle(new Box(0, 47, 21, 6)); var remnants = finder.FindRemnants(); - var above = remnants.FirstOrDefault(r => r.Bottom >= 53 - 0.1 && r.Width > 50); - var below = remnants.FirstOrDefault(r => r.Top <= 47 + 0.1 && r.Width > 50); - var right = remnants.FirstOrDefault(r => r.Left >= 21 - 0.1 && r.Length > 50); + var above = remnants.FirstOrDefault(r => r.Bottom >= 53 - 0.1 && r.Length > 50); + var below = remnants.FirstOrDefault(r => r.Top <= 47 + 0.1 && r.Length > 50); + var right = remnants.FirstOrDefault(r => r.Left >= 21 - 0.1 && r.Width > 50); Assert.NotNull(above); Assert.NotNull(below); @@ -312,10 +312,10 @@ public class RemnantFinderTests var topGap = tiered.FirstOrDefault(t => t.Box.Bottom > 50 && t.Box.Bottom < 55 && t.Box.Left < 1 && - t.Box.Width > 100 && - t.Box.Length > 5); + t.Box.Length > 100 && + t.Box.Width > 5); - Assert.True(topGap.Box.Width > 0, "Expected remnant above main grid"); + Assert.True(topGap.Box.Length > 0, "Expected remnant above main grid"); } [Fact] @@ -361,11 +361,11 @@ public class RemnantFinderTests // The gap at x < 106 from y=53.14 to y=59.8 should be found. Assert.True(remnants.Count > 0, "Should find gap above main grid"); - var topRemnant = remnants.FirstOrDefault(r => r.Length >= 5.375 && r.Width > 50); + var topRemnant = remnants.FirstOrDefault(r => r.Width >= 5.375 && r.Length > 50); Assert.NotNull(topRemnant); // Verify dimensions are close to the expected ~104 x 6.6 gap. - Assert.True(topRemnant.Width > 100, $"Expected width > 100, got {topRemnant.Width:F1}"); - Assert.True(topRemnant.Length > 6, $"Expected length > 6, got {topRemnant.Length:F1}"); + Assert.True(topRemnant.Length > 100, $"Expected length > 100, got {topRemnant.Length:F1}"); + Assert.True(topRemnant.Width > 6, $"Expected width > 6, got {topRemnant.Width:F1}"); } } diff --git a/OpenNest.Tests/Geometry/PolygonHelperTests.cs b/OpenNest.Tests/Geometry/PolygonHelperTests.cs index 232a0f6..2844f02 100644 --- a/OpenNest.Tests/Geometry/PolygonHelperTests.cs +++ b/OpenNest.Tests/Geometry/PolygonHelperTests.cs @@ -123,7 +123,7 @@ public class PolygonHelperTests var rotated = PolygonHelper.RotatePolygon(polygon, Angle.HalfPI); rotated.UpdateBounds(); - Assert.True(System.Math.Abs(rotated.BoundingBox.Width - 10) < 0.1); - Assert.True(System.Math.Abs(rotated.BoundingBox.Length - 20) < 0.1); + Assert.True(System.Math.Abs(rotated.BoundingBox.Length - 10) < 0.1); + Assert.True(System.Math.Abs(rotated.BoundingBox.Width - 20) < 0.1); } } diff --git a/OpenNest.Tests/Shapes/IsoscelesTriangleShapeTests.cs b/OpenNest.Tests/Shapes/IsoscelesTriangleShapeTests.cs index f4420a4..3eaea42 100644 --- a/OpenNest.Tests/Shapes/IsoscelesTriangleShapeTests.cs +++ b/OpenNest.Tests/Shapes/IsoscelesTriangleShapeTests.cs @@ -11,8 +11,8 @@ public class IsoscelesTriangleShapeTests var drawing = shape.GetDrawing(); var bbox = drawing.Program.BoundingBox(); - Assert.Equal(10, bbox.Width, 0.01); - Assert.Equal(8, bbox.Length, 0.01); + Assert.Equal(10, bbox.Length, 0.01); + Assert.Equal(8, bbox.Width, 0.01); } [Fact] diff --git a/OpenNest.Tests/Shapes/LShapeTests.cs b/OpenNest.Tests/Shapes/LShapeTests.cs index 8c4cd56..34616d4 100644 --- a/OpenNest.Tests/Shapes/LShapeTests.cs +++ b/OpenNest.Tests/Shapes/LShapeTests.cs @@ -11,8 +11,8 @@ public class LShapeTests var drawing = shape.GetDrawing(); var bbox = drawing.Program.BoundingBox(); - Assert.Equal(10, bbox.Width, 0.01); - Assert.Equal(20, bbox.Length, 0.01); + Assert.Equal(10, bbox.Length, 0.01); + Assert.Equal(20, bbox.Width, 0.01); } [Fact] diff --git a/OpenNest.Tests/Shapes/RectangleShapeTests.cs b/OpenNest.Tests/Shapes/RectangleShapeTests.cs index 1d9168a..62ec40c 100644 --- a/OpenNest.Tests/Shapes/RectangleShapeTests.cs +++ b/OpenNest.Tests/Shapes/RectangleShapeTests.cs @@ -11,8 +11,8 @@ public class RectangleShapeTests var drawing = shape.GetDrawing(); var bbox = drawing.Program.BoundingBox(); - Assert.Equal(10, bbox.Width, 0.01); - Assert.Equal(5, bbox.Length, 0.01); + Assert.Equal(10, bbox.Length, 0.01); + Assert.Equal(5, bbox.Width, 0.01); } [Fact] diff --git a/OpenNest.Tests/Shapes/RightTriangleShapeTests.cs b/OpenNest.Tests/Shapes/RightTriangleShapeTests.cs index e11e46a..e7193d5 100644 --- a/OpenNest.Tests/Shapes/RightTriangleShapeTests.cs +++ b/OpenNest.Tests/Shapes/RightTriangleShapeTests.cs @@ -11,8 +11,8 @@ public class RightTriangleShapeTests var drawing = shape.GetDrawing(); var bbox = drawing.Program.BoundingBox(); - Assert.Equal(12, bbox.Width, 0.01); - Assert.Equal(8, bbox.Length, 0.01); + Assert.Equal(12, bbox.Length, 0.01); + Assert.Equal(8, bbox.Width, 0.01); } [Fact] diff --git a/OpenNest.Tests/Shapes/RoundedRectangleShapeTests.cs b/OpenNest.Tests/Shapes/RoundedRectangleShapeTests.cs index 5b2b21b..1046b48 100644 --- a/OpenNest.Tests/Shapes/RoundedRectangleShapeTests.cs +++ b/OpenNest.Tests/Shapes/RoundedRectangleShapeTests.cs @@ -11,8 +11,8 @@ public class RoundedRectangleShapeTests var drawing = shape.GetDrawing(); var bbox = drawing.Program.BoundingBox(); - Assert.Equal(20, bbox.Width, 0.1); - Assert.Equal(10, bbox.Length, 0.1); + Assert.Equal(20, bbox.Length, 0.1); + Assert.Equal(10, bbox.Width, 0.1); } [Fact] diff --git a/OpenNest.Tests/Shapes/TShapeTests.cs b/OpenNest.Tests/Shapes/TShapeTests.cs index c7dd40c..982ec88 100644 --- a/OpenNest.Tests/Shapes/TShapeTests.cs +++ b/OpenNest.Tests/Shapes/TShapeTests.cs @@ -11,8 +11,8 @@ public class TShapeTests var drawing = shape.GetDrawing(); var bbox = drawing.Program.BoundingBox(); - Assert.Equal(12, bbox.Width, 0.01); - Assert.Equal(18, bbox.Length, 0.01); + Assert.Equal(12, bbox.Length, 0.01); + Assert.Equal(18, bbox.Width, 0.01); } [Fact] diff --git a/OpenNest.Tests/Shapes/TrapezoidShapeTests.cs b/OpenNest.Tests/Shapes/TrapezoidShapeTests.cs index 0efbe80..dee2f06 100644 --- a/OpenNest.Tests/Shapes/TrapezoidShapeTests.cs +++ b/OpenNest.Tests/Shapes/TrapezoidShapeTests.cs @@ -11,8 +11,8 @@ public class TrapezoidShapeTests var drawing = shape.GetDrawing(); var bbox = drawing.Program.BoundingBox(); - Assert.Equal(20, bbox.Width, 0.01); - Assert.Equal(8, bbox.Length, 0.01); + Assert.Equal(20, bbox.Length, 0.01); + Assert.Equal(8, bbox.Width, 0.01); } [Fact] diff --git a/OpenNest.Tests/Splitting/DrawingSplitterTests.cs b/OpenNest.Tests/Splitting/DrawingSplitterTests.cs index 8c61294..9b6704f 100644 --- a/OpenNest.Tests/Splitting/DrawingSplitterTests.cs +++ b/OpenNest.Tests/Splitting/DrawingSplitterTests.cs @@ -161,11 +161,11 @@ public class DrawingSplitterTests var bb2 = results[1].Program.BoundingBox(); // Piece lengths should sum to original length - Assert.Equal(100.0, bb1.Width + bb2.Width, 1); + Assert.Equal(100.0, bb1.Length + bb2.Length, 1); // Both pieces should have the same width as the original - Assert.Equal(100.0, bb1.Length, 1); - Assert.Equal(100.0, bb2.Length, 1); + Assert.Equal(100.0, bb1.Width, 1); + Assert.Equal(100.0, bb2.Width, 1); } [Fact] @@ -183,11 +183,11 @@ public class DrawingSplitterTests var bb2 = results[1].Program.BoundingBox(); // Piece widths should sum to original width - Assert.Equal(100.0, bb1.Length + bb2.Length, 1); + Assert.Equal(100.0, bb1.Width + bb2.Width, 1); // Both pieces should have the same length as the original - Assert.Equal(100.0, bb1.Width, 1); - Assert.Equal(100.0, bb2.Width, 1); + Assert.Equal(100.0, bb1.Length, 1); + Assert.Equal(100.0, bb2.Length, 1); } [Fact] @@ -287,8 +287,8 @@ public class DrawingSplitterTests var bb2 = results[1].Program.BoundingBox(); // Left piece should be 30 long, right piece should be 70 long - Assert.Equal(30.0, bb1.Width, 1); - Assert.Equal(70.0, bb2.Width, 1); + Assert.Equal(30.0, bb1.Length, 1); + Assert.Equal(70.0, bb2.Length, 1); } [Fact] diff --git a/OpenNest.Tests/Strategies/StripeFillerTests.cs b/OpenNest.Tests/Strategies/StripeFillerTests.cs index 7fd9b6e..3a471ca 100644 --- a/OpenNest.Tests/Strategies/StripeFillerTests.cs +++ b/OpenNest.Tests/Strategies/StripeFillerTests.cs @@ -37,8 +37,8 @@ public class StripeFillerTests Drawing drawing, double spacing) { var bb = drawing.Program.BoundingBox(); - var w = bb.Width; - var h = bb.Length; + var w = bb.Length; + var h = bb.Width; var candidate = new PairCandidate { @@ -85,7 +85,7 @@ public class StripeFillerTests pattern.Parts, 22.0, NestDirection.Horizontal); var rotated = FillHelpers.BuildRotatedPattern(pattern.Parts, angle); - var span = rotated.BoundingBox.Width; + var span = rotated.BoundingBox.Length; Assert.True(System.Math.Abs(span - 22.0) < 0.5, $"Expected span ~22, got {span:F2} at {OpenNest.Math.Angle.ToDegrees(angle):F1}°"); } diff --git a/OpenNest/Actions/ActionClone.cs b/OpenNest/Actions/ActionClone.cs index 463d36c..6ce0b18 100644 --- a/OpenNest/Actions/ActionClone.cs +++ b/OpenNest/Actions/ActionClone.cs @@ -198,9 +198,9 @@ namespace OpenNest.Actions Box cutoffBox; if (cutoff.Axis == CutOffAxis.Vertical) - cutoffBox = new Box(cutoff.Position.X, plateBounds.Y, 0, plateBounds.Length); + cutoffBox = new Box(cutoff.Position.X, plateBounds.Y, 0, plateBounds.Width); else - cutoffBox = new Box(plateBounds.X, cutoff.Position.Y, plateBounds.Width, 0); + cutoffBox = new Box(plateBounds.X, cutoff.Position.Y, plateBounds.Length, 0); boxes.Add(cutoffBox.Offset(plate.PartSpacing)); } diff --git a/OpenNest/Actions/ActionSelectArea.cs b/OpenNest/Actions/ActionSelectArea.cs index c86710f..36735b7 100644 --- a/OpenNest/Actions/ActionSelectArea.cs +++ b/OpenNest/Actions/ActionSelectArea.cs @@ -92,8 +92,8 @@ namespace OpenNest.Actions var location = plateView.PointWorldToGraph(SelectedArea.Location); var size = new SizeF( - plateView.LengthWorldToGui(SelectedArea.Width), - plateView.LengthWorldToGui(SelectedArea.Length)); + plateView.LengthWorldToGui(SelectedArea.Length), + plateView.LengthWorldToGui(SelectedArea.Width)); var rect = new System.Drawing.RectangleF(location.X, location.Y - size.Height, size.Width, size.Height); @@ -176,9 +176,9 @@ namespace OpenNest.Actions Box cutoffBox; if (cutoff.Axis == CutOffAxis.Vertical) - cutoffBox = new Box(cutoff.Position.X, plateBounds.Y, 0, plateBounds.Length); + cutoffBox = new Box(cutoff.Position.X, plateBounds.Y, 0, plateBounds.Width); else - cutoffBox = new Box(plateBounds.X, cutoff.Position.Y, plateBounds.Width, 0); + cutoffBox = new Box(plateBounds.X, cutoff.Position.Y, plateBounds.Length, 0); boxes.Add(cutoffBox.Offset(plateView.Plate.PartSpacing)); } diff --git a/OpenNest/Controls/DrawControl.cs b/OpenNest/Controls/DrawControl.cs index d8cf5d6..ba50526 100644 --- a/OpenNest/Controls/DrawControl.cs +++ b/OpenNest/Controls/DrawControl.cs @@ -206,7 +206,7 @@ namespace OpenNest.Controls public virtual void ZoomToArea(Box box, bool redraw = true) { - ZoomToArea(box.X, box.Y, box.Width, box.Length, redraw); + ZoomToArea(box.X, box.Y, box.Length, box.Width, redraw); } public virtual void ZoomToArea(double x, double y, double width, double height, bool redraw = true) diff --git a/OpenNest/Controls/PlateRenderer.cs b/OpenNest/Controls/PlateRenderer.cs index 74ea7c6..c13dd47 100644 --- a/OpenNest/Controls/PlateRenderer.cs +++ b/OpenNest/Controls/PlateRenderer.cs @@ -190,8 +190,8 @@ namespace OpenNest.Controls var rect = new RectangleF { Location = view.PointWorldToGraph(workArea.Location), - Width = view.LengthWorldToGui(workArea.Width), - Height = view.LengthWorldToGui(workArea.Length) + Width = view.LengthWorldToGui(workArea.Length), + Height = view.LengthWorldToGui(workArea.Width) }; rect.Y -= rect.Height; @@ -226,8 +226,8 @@ namespace OpenNest.Controls { var box = remnants[i]; var loc = view.PointWorldToGraph(box.Location); - var w = view.LengthWorldToGui(box.Width); - var h = view.LengthWorldToGui(box.Length); + var w = view.LengthWorldToGui(box.Length); + var h = view.LengthWorldToGui(box.Width); var rect = new RectangleF(loc.X, loc.Y - h, w, h); var priority = view.DebugRemnantPriorities != null && i < view.DebugRemnantPriorities.Count @@ -355,7 +355,7 @@ namespace OpenNest.Controls var location = part.Location; var pt1 = view.PointWorldToGraph(location); var pt2 = view.PointWorldToGraph(new Vector( - location.X + box.Width, location.Y + box.Length)); + location.X + box.Length, location.Y + box.Width)); using var warnPen = new Pen(Color.FromArgb(180, 255, 140, 0), 2f); g.DrawRectangle(warnPen, pt1.X, pt2.Y, System.Math.Abs(pt2.X - pt1.X), System.Math.Abs(pt2.Y - pt1.Y)); @@ -542,8 +542,8 @@ namespace OpenNest.Controls var rect = new RectangleF { Location = view.PointWorldToGraph(box.Location), - Width = view.LengthWorldToGui(box.Width), - Height = view.LengthWorldToGui(box.Length) + Width = view.LengthWorldToGui(box.Length), + Height = view.LengthWorldToGui(box.Width) }; g.DrawRectangle(view.ColorScheme.BoundingBoxPen, rect.X, rect.Y - rect.Height, rect.Width, rect.Height); diff --git a/OpenNest/Forms/EditNestInfoForm.cs b/OpenNest/Forms/EditNestInfoForm.cs index 235c0c2..63a5d03 100644 --- a/OpenNest/Forms/EditNestInfoForm.cs +++ b/OpenNest/Forms/EditNestInfoForm.cs @@ -173,13 +173,13 @@ namespace OpenNest.Forms return; } - if (LeftSpacing + RightSpacing >= size.Width) + if (LeftSpacing + RightSpacing >= size.Length) { applyButton.Enabled = false; return; } - if (TopSpacing + BottomSpacing >= size.Length) + if (TopSpacing + BottomSpacing >= size.Width) { applyButton.Enabled = false; return; diff --git a/OpenNest/Forms/EditPlateForm.cs b/OpenNest/Forms/EditPlateForm.cs index a2daf7d..e2dab60 100644 --- a/OpenNest/Forms/EditPlateForm.cs +++ b/OpenNest/Forms/EditPlateForm.cs @@ -131,13 +131,13 @@ namespace OpenNest.Forms return; } - if (LeftSpacing + RightSpacing >= size.Width) + if (LeftSpacing + RightSpacing >= size.Length) { applyButton.Enabled = false; return; } - if (TopSpacing + BottomSpacing >= size.Length) + if (TopSpacing + BottomSpacing >= size.Width) { applyButton.Enabled = false; return; diff --git a/OpenNest/Forms/OptionsForm.Designer.cs b/OpenNest/Forms/OptionsForm.Designer.cs index 5b69880..da16adf 100644 --- a/OpenNest/Forms/OptionsForm.Designer.cs +++ b/OpenNest/Forms/OptionsForm.Designer.cs @@ -42,6 +42,7 @@ this.saveButton = new System.Windows.Forms.Button(); this.cancelButton = new System.Windows.Forms.Button(); this.bottomPanel1 = new OpenNest.Controls.BottomPanel(); + this.strategyGrid = new System.Windows.Forms.DataGridView(); this.strategyGroupBox = new System.Windows.Forms.GroupBox(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.tableLayoutPanel1.SuspendLayout(); @@ -212,8 +213,24 @@ this.bottomPanel1.Size = new System.Drawing.Size(708, 50); this.bottomPanel1.TabIndex = 1; // + // strategyGrid + // + this.strategyGrid.AllowUserToAddRows = false; + this.strategyGrid.AllowUserToDeleteRows = false; + this.strategyGrid.AllowUserToResizeRows = false; + this.strategyGrid.BackgroundColor = System.Drawing.SystemColors.Window; + this.strategyGrid.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.strategyGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.strategyGrid.Dock = System.Windows.Forms.DockStyle.Fill; + this.strategyGrid.Location = new System.Drawing.Point(3, 18); + this.strategyGrid.Name = "strategyGrid"; + this.strategyGrid.RowHeadersVisible = false; + this.strategyGrid.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.strategyGrid.TabIndex = 0; + // // strategyGroupBox // + this.strategyGroupBox.Controls.Add(this.strategyGrid); this.strategyGroupBox.Location = new System.Drawing.Point(12, 178); this.strategyGroupBox.Name = "strategyGroupBox"; this.strategyGroupBox.Size = new System.Drawing.Size(684, 180); @@ -263,6 +280,7 @@ private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button button1; + private System.Windows.Forms.DataGridView strategyGrid; private System.Windows.Forms.GroupBox strategyGroupBox; } } \ No newline at end of file diff --git a/OpenNest/Forms/OptionsForm.cs b/OpenNest/Forms/OptionsForm.cs index 552db2a..067baad 100644 --- a/OpenNest/Forms/OptionsForm.cs +++ b/OpenNest/Forms/OptionsForm.cs @@ -1,4 +1,4 @@ -using OpenNest.Engine.Strategies; +using OpenNest.Engine.Strategies; using OpenNest.Properties; using System; using System.Collections.Generic; @@ -9,12 +9,10 @@ namespace OpenNest.Forms { public partial class OptionsForm : Form { - private readonly List _strategyCheckBoxes = new(); - public OptionsForm() { InitializeComponent(); - BuildStrategyCheckBoxes(); + BuildStrategyGrid(); } protected override void OnLoad(EventArgs e) @@ -23,23 +21,44 @@ namespace OpenNest.Forms LoadSettings(); } - private void BuildStrategyCheckBoxes() + private void BuildStrategyGrid() { - var strategies = FillStrategyRegistry.AllStrategies; - var y = 20; + strategyGrid.AutoGenerateColumns = false; - foreach (var strategy in strategies) + strategyGrid.Columns.Add(new DataGridViewCheckBoxColumn { - var cb = new CheckBox - { - Text = strategy.Name, - Tag = strategy.Name, - AutoSize = true, - Location = new System.Drawing.Point(10, y), - }; - strategyGroupBox.Controls.Add(cb); - _strategyCheckBoxes.Add(cb); - y += 24; + Name = "Enabled", + HeaderText = "", + Width = 30, + }); + + strategyGrid.Columns.Add(new DataGridViewTextBoxColumn + { + Name = "Name", + HeaderText = "Strategy", + ReadOnly = true, + AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, + }); + + strategyGrid.Columns.Add(new DataGridViewTextBoxColumn + { + Name = "Phase", + HeaderText = "Phase", + ReadOnly = true, + Width = 100, + }); + + strategyGrid.Columns.Add(new DataGridViewTextBoxColumn + { + Name = "Order", + HeaderText = "Order", + ReadOnly = true, + Width = 55, + }); + + foreach (var strategy in FillStrategyRegistry.AllStrategies) + { + strategyGrid.Rows.Add(true, strategy.Name, strategy.Phase, strategy.Order); } } @@ -51,8 +70,8 @@ namespace OpenNest.Forms numericUpDown2.Value = (decimal)Settings.Default.ImportSplinePrecision; var disabledNames = ParseDisabledStrategies(Settings.Default.DisabledStrategies); - foreach (var cb in _strategyCheckBoxes) - cb.Checked = !disabledNames.Contains((string)cb.Tag); + foreach (DataGridViewRow row in strategyGrid.Rows) + row.Cells["Enabled"].Value = !disabledNames.Contains((string)row.Cells["Name"].Value); } private void SaveSettings() @@ -62,9 +81,12 @@ namespace OpenNest.Forms Settings.Default.AutoSizePlateFactor = (double)numericUpDown1.Value; Settings.Default.ImportSplinePrecision = (int)numericUpDown2.Value; - var disabledNames = _strategyCheckBoxes - .Where(cb => !cb.Checked) - .Select(cb => (string)cb.Tag); + var disabledNames = new List(); + foreach (DataGridViewRow row in strategyGrid.Rows) + { + if (row.Cells["Enabled"].Value is false) + disabledNames.Add((string)row.Cells["Name"].Value); + } Settings.Default.DisabledStrategies = string.Join(",", disabledNames); Settings.Default.Save(); diff --git a/OpenNest/Forms/SimplifierViewerForm.cs b/OpenNest/Forms/SimplifierViewerForm.cs index fa15e54..5abcf09 100644 --- a/OpenNest/Forms/SimplifierViewerForm.cs +++ b/OpenNest/Forms/SimplifierViewerForm.cs @@ -112,8 +112,8 @@ public partial class SimplifierViewerForm : Form var padded = new Box( candidate.BoundingBox.X - tol * 2, candidate.BoundingBox.Y - tol * 2, - candidate.BoundingBox.Width + tol * 4, - candidate.BoundingBox.Length + tol * 4); + candidate.BoundingBox.Length + tol * 4, + candidate.BoundingBox.Width + tol * 4); entityView.ZoomToArea(padded); } diff --git a/OpenNest/Forms/SplitDrawingForm.cs b/OpenNest/Forms/SplitDrawingForm.cs index 756edfe..73eea76 100644 --- a/OpenNest/Forms/SplitDrawingForm.cs +++ b/OpenNest/Forms/SplitDrawingForm.cs @@ -78,7 +78,7 @@ public partial class SplitDrawingForm : Form var usable = plateW - 2 * spacing - overhang; if (usable > 0) { - var splits = (int)System.Math.Ceiling(_drawingBounds.Width / usable) - 1; + var splits = (int)System.Math.Ceiling(_drawingBounds.Length / usable) - 1; for (var i = 1; i <= splits; i++) _splitLines.Add(new SplitLine(_drawingBounds.X + usable * i, CutOffAxis.Vertical)); } @@ -88,7 +88,7 @@ public partial class SplitDrawingForm : Form var usable = plateH - 2 * spacing - overhang; if (usable > 0) { - var splits = (int)System.Math.Ceiling(_drawingBounds.Length / usable) - 1; + var splits = (int)System.Math.Ceiling(_drawingBounds.Width / usable) - 1; for (var i = 1; i <= splits; i++) _splitLines.Add(new SplitLine(_drawingBounds.Y + usable * i, CutOffAxis.Horizontal)); } diff --git a/OpenNest/LayoutPart.cs b/OpenNest/LayoutPart.cs index 2cb2e8f..e705fd4 100644 --- a/OpenNest/LayoutPart.cs +++ b/OpenNest/LayoutPart.cs @@ -128,7 +128,7 @@ namespace OpenNest if (shapes.Count == 0) { var bbox = BasePart.BaseDrawing.Program.BoundingBox(); - return new Vector(bbox.Location.X + bbox.Width / 2, bbox.Location.Y + bbox.Length / 2); + return new Vector(bbox.Location.X + bbox.Length / 2, bbox.Location.Y + bbox.Width / 2); } var profile = new ShapeProfile(nonRapid);