Skip to content

Commit

Permalink
Remove premature optimisation that limits depths of each layer to tha…
Browse files Browse the repository at this point in the history
…t of the first packed item (fixes #13)
  • Loading branch information
dvdoug committed Aug 10, 2014
1 parent 0c97ff6 commit 569c0a6
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 @@ -250,7 +250,7 @@ public function packIntoBox(Box $aBox, ItemList $aItems) {

$itemToPack = $aItems->top();

if ($itemToPack->getDepth() > ($layerDepth ?: $remainingDepth) || $itemToPack->getWeight() > $remainingWeight) {
if ($itemToPack->getDepth() > $remainingDepth || $itemToPack->getWeight() > $remainingWeight) {
break;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/PackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ public function testIssue9() {
self::assertEquals(1, $packedBoxes->count());
}

public function testIssue13() {
$packer = new Packer();
$packer->addBox(new TestBox('Le petite box', 12, 12, 12, 10, 10, 10, 10, 1000));

$packer->addItem(new TestItem('Item 1', 5, 3, 2, 2));
$packer->addItem(new TestItem('Item 2', 5, 3, 2, 2));
$packer->addItem(new TestItem('Item 3', 3, 3, 3, 3));
$packedBoxes = $packer->pack();

self::assertEquals(1, $packedBoxes->count());
}


/**
* @dataProvider getSamples
Expand Down

0 comments on commit 569c0a6

Please sign in to comment.