From 90d770e10cc2166600dfb4a687a51c8b34df5779 Mon Sep 17 00:00:00 2001 From: AJ Date: Mon, 15 Nov 2021 09:10:20 -0500 Subject: [PATCH] Fixed utilization greater than 100 percent --- CutList/Forms/ResultsForm.cs | 2 ++ SawCut/Bin.cs | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CutList/Forms/ResultsForm.cs b/CutList/Forms/ResultsForm.cs index 184f01d..8c6c68f 100644 --- a/CutList/Forms/ResultsForm.cs +++ b/CutList/Forms/ResultsForm.cs @@ -63,6 +63,8 @@ namespace CutList.Forms foreach (var bin in Bins) { + var idString = id++.ToString(); + var binDescription = $"{idString}. {bin.ToString()}"; writer.WriteLine(id++.ToString() + ". " + bin.ToString()); var groups = bin.Items.GroupBy(i => $"{i.Name} {i.Length}"); diff --git a/SawCut/Bin.cs b/SawCut/Bin.cs index 964b1c3..5b92404 100644 --- a/SawCut/Bin.cs +++ b/SawCut/Bin.cs @@ -22,6 +22,11 @@ namespace SawCut { get { + var usedLength = Math.Round(Items.Sum(i => i.Length) + Spacing * Items.Count, 8); + + if (usedLength > Length && (usedLength - Length) <= Spacing) + return Length; + return Math.Round(Items.Sum(i => i.Length) + Spacing * Items.Count, 8); } } @@ -31,9 +36,13 @@ namespace SawCut get { return Math.Round(Length - UsedLength, 8); } } + /// + /// Returns a ratio of UsedLength to TotalLength + /// 1.0 = 100% utilization + /// public double Utilization { - get { return UsedLength / Length; } + get { return UsedLength / Length; } } public override string ToString()