From c815438ea2ed8f17560cc1b126a40d09b9364f2d Mon Sep 17 00:00:00 2001 From: psychopatt <66741203+psychopatt@users.noreply.github.com> Date: Thu, 9 Jun 2022 12:27:09 +0200 Subject: [PATCH] Fix wrong condition The condition of the `FindBox` inner loop is wrong and allows `x` go beyond `itemsToPack[y].Quantity` iterations as soon as `Quantity > 1`. As a result, the analyzed box may be one of another box "type", and will be analyzed again later by following iterations of outer loop. The empty item added in `Initialize` serves no purpose anymore since it just prevented OutOfRange exceptions caused by the wrong check discussed above. --- .../Algorithms/EB_AFIT.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CromulentBisgetti.ContainerPacking/Algorithms/EB_AFIT.cs b/src/CromulentBisgetti.ContainerPacking/Algorithms/EB_AFIT.cs index c10292c..38e7140 100644 --- a/src/CromulentBisgetti.ContainerPacking/Algorithms/EB_AFIT.cs +++ b/src/CromulentBisgetti.ContainerPacking/Algorithms/EB_AFIT.cs @@ -403,7 +403,7 @@ private void FindBox(decimal hmx, decimal hy, decimal hmy, decimal hz, decimal h for (y = 1; y <= itemsToPackCount; y = y + itemsToPack[y].Quantity) { - for (x = y; x < x + itemsToPack[y].Quantity - 1; x++) + for (x = y; x < y + itemsToPack[y].Quantity - 1; x++) { if (!itemsToPack[x].IsPacked) break; } @@ -549,8 +549,6 @@ private void Initialize(Container container, List items) itemsToPackCount += item.Quantity; } - itemsToPack.Add(new Item(0, 0, 0, 0, 0)); - totalContainerVolume = container.Length * container.Height * container.Width; totalItemVolume = 0.0M; @@ -1219,4 +1217,4 @@ private class ScrapPad #endregion Private Classes } -} \ No newline at end of file +}