From 041630fdc173e28e863beee9eee3c830a1c4055b Mon Sep 17 00:00:00 2001 From: Doug Wright Date: Thu, 30 Jan 2020 00:56:15 +0000 Subject: [PATCH] Special case same object as a fast way to detect identical dimensions --- src/OrientatedItemFactory.php | 14 +++++++++----- src/VolumePacker.php | 3 +++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/OrientatedItemFactory.php b/src/OrientatedItemFactory.php index 4e19d3d6..9540961c 100644 --- a/src/OrientatedItemFactory.php +++ b/src/OrientatedItemFactory.php @@ -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 diff --git a/src/VolumePacker.php b/src/VolumePacker.php index a68e3464..f5ada315 100644 --- a/src/VolumePacker.php +++ b/src/VolumePacker.php @@ -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);