Skip to content

Commit

Permalink
Don't infinite loop - that's bad (fixes #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Aug 13, 2014
1 parent 1d86816 commit 8417542
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Packer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions tests/PackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8417542

Please sign in to comment.