feat: add part classification (large/medium/small) to MultiPlateNester

Introduces PartClass enum and Classify() static method that categorizes
parts as Large (exceeds half work area in either dimension), Medium
(area > 1/9 work area), or Small.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-06 13:52:27 -04:00
parent 89a4e6b981
commit 35e89600d0
2 changed files with 66 additions and 0 deletions

View File

@@ -1,8 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using OpenNest.Geometry;
namespace OpenNest
{
public enum PartClass
{
Large,
Medium,
Small,
}
public static class MultiPlateNester
{
public static List<NestItem> SortItems(List<NestItem> items, PartSortOrder sortOrder)
@@ -31,5 +39,22 @@ namespace OpenNest
return items.ToList();
}
}
public static PartClass Classify(Box partBounds, Box workArea)
{
var halfWidth = workArea.Width / 2.0;
var halfLength = workArea.Length / 2.0;
if (partBounds.Width > halfWidth || partBounds.Length > halfLength)
return PartClass.Large;
var workAreaArea = workArea.Width * workArea.Length;
var partArea = partBounds.Width * partBounds.Length;
if (partArea > workAreaArea / 9.0)
return PartClass.Medium;
return PartClass.Small;
}
}
}

View File

@@ -62,4 +62,45 @@ public class MultiPlateNesterTests
Assert.Equal("short-wide", sorted[1].Drawing.Name);
Assert.Equal("square", sorted[2].Drawing.Name);
}
// --- Task 4: Part Classification ---
[Fact]
public void Classify_LargePart_WhenWidthExceedsHalfWorkArea()
{
var workArea = new Box(0, 0, 96, 48);
var bb = new Box(0, 0, 50, 20); // width 50 > half of 96 = 48
var result = MultiPlateNester.Classify(bb, workArea);
Assert.Equal(PartClass.Large, result);
}
[Fact]
public void Classify_LargePart_WhenLengthExceedsHalfWorkArea()
{
var workArea = new Box(0, 0, 96, 48);
var bb = new Box(0, 0, 20, 30); // length 30 > half of 48 = 24
var result = MultiPlateNester.Classify(bb, workArea);
Assert.Equal(PartClass.Large, result);
}
[Fact]
public void Classify_MediumPart_NotLargeButAreaAboveThreshold()
{
var workArea = new Box(0, 0, 96, 48);
// workArea = 4608, 1/9 = 512. bb = 40*15 = 600 > 512
// 40 < 48 (half of 96), 15 < 24 (half of 48) — not Large
var bb = new Box(0, 0, 40, 15);
var result = MultiPlateNester.Classify(bb, workArea);
Assert.Equal(PartClass.Medium, result);
}
[Fact]
public void Classify_SmallPart()
{
var workArea = new Box(0, 0, 96, 48);
// workArea = 4608, 1/9 = 512. bb = 10*10 = 100 < 512
var bb = new Box(0, 0, 10, 10);
var result = MultiPlateNester.Classify(bb, workArea);
Assert.Equal(PartClass.Small, result);
}
}