Replace public mutable collection fields/properties with private backing fields and expose them as IReadOnlyList. Add proper methods for mutation (AddItem, AddItems, RemoveItem, SortItems). Changes: - Bin.Items: Now private with AddItem/AddItems/RemoveItem/SortItems - Result.ItemsNotUsed: Now readonly with Add methods - Result.Bins: Now readonly with Add methods - Updated all engine classes to use new encapsulated APIs This improves encapsulation and prevents external code from bypassing business logic by directly manipulating collections. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace SawCut.Nesting
|
|
{
|
|
public class MultiBinEngine : IEngine
|
|
{
|
|
public List<MultiBin> Bins { get; set; }
|
|
|
|
public double Spacing { get; set; }
|
|
|
|
public Result Pack(List<BinItem> items)
|
|
{
|
|
var bins = Bins
|
|
.Where(b => b.Length > 0)
|
|
.OrderBy(b => b.Priority)
|
|
.ThenBy(b => b.Length)
|
|
.ToList();
|
|
|
|
var result = new Result();
|
|
var remainingItems = new List<BinItem>(items);
|
|
|
|
foreach (var bin in bins)
|
|
{
|
|
var e = new AdvancedFitEngine();
|
|
e.MaxBinCount = bin.Quantity;
|
|
e.StockLength = bin.Length;
|
|
e.Spacing = Spacing;
|
|
var r = e.Pack(remainingItems);
|
|
|
|
result.AddBins(r.Bins);
|
|
remainingItems = r.ItemsNotUsed.ToList();
|
|
}
|
|
|
|
result.AddItemsNotUsed(remainingItems);
|
|
|
|
return result;
|
|
}
|
|
}
|
|
} |