From a2f523d1df6801466b2ecfaf5af735a12acb2362 Mon Sep 17 00:00:00 2001 From: Doug Wright Date: Sun, 26 Jan 2020 00:37:39 +0000 Subject: [PATCH] More deterministic sorting --- src/OrientatedItemFactory.php | 3 +++ tests/InfalliblePackerTest.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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); } }