diff --git a/src/OrientatedItemFactory.php b/src/OrientatedItemFactory.php index e3e9a868..2f1a7492 100644 --- a/src/OrientatedItemFactory.php +++ b/src/OrientatedItemFactory.php @@ -80,6 +80,9 @@ public function getBestOrientation( $orientationAMinGap = min($orientationAWidthLeft, $orientationALengthLeft); $orientationBMinGap = min($orientationBWidthLeft, $orientationBLengthLeft); + if ($orientationAMinGap === 0 && $orientationBMinGap === 0) { + return $a->getDepth() <=> $b->getDepth(); + } if ($orientationAMinGap === 0) { // prefer A if it leaves no gap return -1; } diff --git a/tests/InfalliblePackerTest.php b/tests/InfalliblePackerTest.php index 7c0b426c..d3c4e7dd 100644 --- a/tests/InfalliblePackerTest.php +++ b/tests/InfalliblePackerTest.php @@ -452,6 +452,6 @@ public function testIssue182B(): void /** @var PackedBox[] $packedBoxes */ $packedBoxes = iterator_to_array($packer->pack(), false); - self::assertCount(42, $packedBoxes); + self::assertCount(41, $packedBoxes); } }