Skip to content

Commit

Permalink
Put 3D rotation behind a flag so that other improvements can be shipped
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Jan 7, 2017
1 parent 9603375 commit 9d7981c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 6 additions & 1 deletion VolumePacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class VolumePacker implements LoggerAwareInterface
{
use LoggerAwareTrait;

/**
* 3D rotation of items is a WIP and should not be used in production environments
*/
const ALWAYS_SHIP_FLAT = true;

/**
* Box to pack items into
* @var Box
Expand Down Expand Up @@ -254,7 +259,7 @@ protected function findPossibleOrientations(Item $item, OrientatedItem $prevItem
$orientations[] = new OrientatedItem($item, $item->getLength(), $item->getWidth(), $item->getDepth());

//add 3D rotation if we're allowed
if (!$item->getKeepFlat()) {
if (self::ALWAYS_SHIP_FLAT === false && !$item->getKeepFlat()) {
$orientations[] = new OrientatedItem($item, $item->getWidth(), $item->getDepth(), $item->getLength());
$orientations[] = new OrientatedItem($item, $item->getLength(), $item->getDepth(), $item->getWidth());
$orientations[] = new OrientatedItem($item, $item->getDepth(), $item->getWidth(), $item->getLength());
Expand Down
15 changes: 10 additions & 5 deletions tests/VolumePackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,16 @@ public function testPackSingleItemFitsBetterRotated()

public function testIssue20()
{
$packer = new Packer();
$packer->addBox(new TestBox('Le grande box', 100, 100, 300, 1, 100,100, 300, 1500));
$packer->addItem(new TestItem('Item 1', 150, 50, 50, 20, false));
$packedBoxes = $packer->pack();
if (VolumePacker::ALWAYS_SHIP_FLAT === false) {

self::assertEquals(1, $packedBoxes->count());
$packer = new Packer();
$packer->addBox(new TestBox('Le grande box', 100, 100, 300, 1, 100,100, 300, 1500));
$packer->addItem(new TestItem('Item 1', 150, 50, 50, 20, false));
$packedBoxes = $packer->pack();

self::assertEquals(1, $packedBoxes->count());
} else {
$this->markTestSkipped('3D rotation not enabled');
}
}
}

0 comments on commit 9d7981c

Please sign in to comment.