for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Box packing (3D bin packing, knapsack problem).
*
* @author Doug Wright
*/
declare(strict_types=1);
namespace DVDoug\BoxPacker;
class DefaultPackedBoxSorter implements PackedBoxSorter
{
public function compare(PackedBox $boxA, PackedBox $boxB): int
$choice = $boxB->items->count() <=> $boxA->items->count();
if ($choice === 0) {
$choice = $boxB->getVolumeUtilisation() <=> $boxA->getVolumeUtilisation();
}
$choice = $boxB->getUsedVolume() <=> $boxA->getUsedVolume();
return $choice;