Skip to content

Commit

Permalink
More deterministic sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Jan 26, 2020
1 parent f38e794 commit a2f523d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/OrientatedItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/InfalliblePackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit a2f523d

Please sign in to comment.