Skip to content

Commit

Permalink
Remove special case benchmarking doesn't support being there
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Apr 12, 2020
1 parent e095ef2 commit 2d80ec1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
4 changes: 4 additions & 0 deletions src/OrientatedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public function isStable(): bool
*/
public function isSameDimensions(Item $item): bool
{
if ($item === $this->item) {
return true;
}

$itemDimensions = [$item->getWidth(), $item->getLength(), $item->getDepth()];
sort($itemDimensions);

Expand Down
39 changes: 17 additions & 22 deletions src/OrientatedItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,31 +158,26 @@ public function getPossibleOrientations(
$orientations = $orientationsDimensions = [];

//Special case items that are the same as what we just packed - keep orientation
if ($prevItem && $item === $prevItem->getItem() && $prevItem->getWidth() <= $widthLeft && $prevItem->getLength() <= $lengthLeft && $prevItem->getDepth() <= $depthLeft) {
$orientations[] = $prevItem; // reuse the existing object for a small speed boost
if ($prevItem && $prevItem->isSameDimensions($item)) {
$orientationsDimensions[] = [$prevItem->getWidth(), $prevItem->getLength(), $prevItem->getDepth()];
} else {
//Might be different a item but having same dimensions - apply same rule
if ($prevItem && $prevItem->isSameDimensions($item)) {
$orientationsDimensions[] = [$prevItem->getWidth(), $prevItem->getLength(), $prevItem->getDepth()];
} else {
//simple 2D rotation
$orientationsDimensions[] = [$item->getWidth(), $item->getLength(), $item->getDepth()];
$orientationsDimensions[] = [$item->getLength(), $item->getWidth(), $item->getDepth()];

//add 3D rotation if we're allowed
if (!$item->getKeepFlat()) {
$orientationsDimensions[] = [$item->getWidth(), $item->getDepth(), $item->getLength()];
$orientationsDimensions[] = [$item->getLength(), $item->getDepth(), $item->getWidth()];
$orientationsDimensions[] = [$item->getDepth(), $item->getWidth(), $item->getLength()];
$orientationsDimensions[] = [$item->getDepth(), $item->getLength(), $item->getWidth()];
}
//simple 2D rotation
$orientationsDimensions[] = [$item->getWidth(), $item->getLength(), $item->getDepth()];
$orientationsDimensions[] = [$item->getLength(), $item->getWidth(), $item->getDepth()];

//add 3D rotation if we're allowed
if (!$item->getKeepFlat()) {
$orientationsDimensions[] = [$item->getWidth(), $item->getDepth(), $item->getLength()];
$orientationsDimensions[] = [$item->getLength(), $item->getDepth(), $item->getWidth()];
$orientationsDimensions[] = [$item->getDepth(), $item->getWidth(), $item->getLength()];
$orientationsDimensions[] = [$item->getDepth(), $item->getLength(), $item->getWidth()];
}
}

//remove any that simply don't fit
foreach ($orientationsDimensions as $dimensions) {
if ($dimensions[0] <= $widthLeft && $dimensions[1] <= $lengthLeft && $dimensions[2] <= $depthLeft) {
$orientations[] = new OrientatedItem($item, $dimensions[0], $dimensions[1], $dimensions[2]);
}
//remove any that simply don't fit
foreach ($orientationsDimensions as $dimensions) {
if ($dimensions[0] <= $widthLeft && $dimensions[1] <= $lengthLeft && $dimensions[2] <= $depthLeft) {
$orientations[] = new OrientatedItem($item, $dimensions[0], $dimensions[1], $dimensions[2]);
}
}

Expand Down

0 comments on commit 2d80ec1

Please sign in to comment.