From f0f88cb66377d0ac69d91c4cf83aee7f5e3c586a Mon Sep 17 00:00:00 2001 From: Doug Wright Date: Sun, 26 Jan 2020 00:19:19 +0000 Subject: [PATCH] More deterministic sorting --- src/OrientatedItemFactory.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/OrientatedItemFactory.php b/src/OrientatedItemFactory.php index 1fe4f595..4e19d3d6 100644 --- a/src/OrientatedItemFactory.php +++ b/src/OrientatedItemFactory.php @@ -87,7 +87,11 @@ public function getBestOrientation( $orientationAMinGap = min($orientationAWidthLeft, $orientationALengthLeft); $orientationBMinGap = min($orientationBWidthLeft, $orientationBLengthLeft); - if ($orientationAMinGap === 0 && ($orientationBMinGap !== 0 || PHP_MAJOR_VERSION > 5)) { // prefer A if it leaves no gap + if ($orientationAMinGap === 0 && $orientationBMinGap === 0) { + return $a->getDepth() - $b->getDepth(); + } + + if ($orientationAMinGap === 0 && $orientationBMinGap !== 0) { // prefer A if it leaves no gap return -1; } if ($orientationBMinGap === 0) { // prefer B if it leaves no gap