diff --git a/Packer.php b/Packer.php index b9438ca1..dbcdf4af 100644 --- a/Packer.php +++ b/Packer.php @@ -303,7 +303,7 @@ public function packIntoBox(Box $aBox, ItemList $aItems) { } } else { - if ($remainingWidth >= min($itemWidth, $itemLength) && $layerDepth > 0) { + if ($remainingWidth >= min($itemWidth, $itemLength) && $layerDepth > 0 && $layerWidth > 0 && $layerLength > 0) { $this->logger->log(LogLevel::DEBUG, "No more fit in lengthwise, resetting for new row"); $remainingLength += $layerLength; $remainingWidth -= $layerWidth; diff --git a/tests/PackerTest.php b/tests/PackerTest.php index 82791ca2..859d91da 100644 --- a/tests/PackerTest.php +++ b/tests/PackerTest.php @@ -373,6 +373,18 @@ public function testIssue13() { self::assertEquals(1, $packedBoxes->count()); } + public function testIssue14() { + $packer = new Packer(); + $packer->addBox(new TestBox('29x1x23Box', 29, 1, 23, 0, 29, 1, 23, 100)); + $packer->addItem(new TestItem('13x1x10Item', 13, 1, 10, 1)); + $packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1)); + $packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1)); + $packer->addItem(new TestItem('9x1x6Item', 9, 1, 6, 1)); + $packedBoxes = $packer->pack(); + + self::assertEquals(1, $packedBoxes->count()); + } + /** * @dataProvider getSamples