Skip to content

Commit

Permalink
Special case same object as a fast way to detect identical dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Jan 30, 2020
1 parent f0f88cb commit 041630f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/OrientatedItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,15 @@ public function getPossibleOrientations(

$isSame = false;
if ($prevItem) {
$itemADimensions = [$item->getWidth(), $item->getLength(), $item->getDepth()];
$itemBDimensions = [$prevItem->getWidth(), $prevItem->getLength(), $prevItem->getDepth()];
sort($itemADimensions);
sort($itemBDimensions);
$isSame = ($itemADimensions === $itemBDimensions);
if ($item === $prevItem->getItem()) {
$isSame = true;
} else {
$itemADimensions = [$item->getWidth(), $item->getLength(), $item->getDepth()];
$itemBDimensions = [$prevItem->getWidth(), $prevItem->getLength(), $prevItem->getDepth()];
sort($itemADimensions);
sort($itemBDimensions);
$isSame = ($itemADimensions === $itemBDimensions);
}
}

//Special case items that are the same as what we just packed - keep orientation
Expand Down
3 changes: 3 additions & 0 deletions src/VolumePacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ protected function getCurrentPackedDepth()
*/
protected static function isSameDimensions(Item $itemA, Item $itemB)
{
if ($itemA === $itemB) {
return true;
}
$itemADimensions = [$itemA->getWidth(), $itemA->getLength(), $itemA->getDepth()];
$itemBDimensions = [$itemB->getWidth(), $itemB->getLength(), $itemB->getDepth()];
sort($itemADimensions);
Expand Down

0 comments on commit 041630f

Please sign in to comment.