Closed howdu closed 8 months ago
To add more info to this, the item list gets sorted so that the 2nd box gets checked first because it has a greater volume. It then tries several orientations for that box, except just lying it flat, and fails to fit the 1st box. If you bump the depth of the 1st item up to 15 it works fine.
Hi, thanks for the minimal testcase - makes it a lot easier to reproduce and debug.
This is one of those ones where I can easily make changes that makes this particular example pack better, but then others end up packing worse - I'll keep seeing if I can find the right heuristic.
Is this just an odd example that you've found, or this a typical scenario for what you're trying to pack with a large flat item that's almost (but not quite), the same dimensions as the box not being put at the bottom?
Thanks for looking into this @dvdoug - it's a great package and all other package combinations are working flawlessly.
The issue we're having is with a vinyl record box plus a DVD box set, and the reason for the outer box dimensions.
OK, I'll certainly keep this on the list. In the meantime, something that might work for you is using custom sorting - as this works when the vinyl is packed first, depending on your application you can probably enforce that using the mechanism at https://boxpacker.io/en/stable/sortation.html#overriding-the-default-algorithm
$sorter = new CustomItemSorter();
$itemList = new ItemList($sorter);
class CustomItemSorter extends DefaultItemSorter
{
public function compare(Item $itemA, Item $itemB): int
{
if ($itemA->isVinyl()) { // or check a category, or ->getDepth() < 15 or whatever works in your app to identify one
return -1;
}
if ($itemB->isVinyl()) {
return 1;
}
// fall back to regular rules
return parent::compare($itemA, $itemB);
}
}
These two items should be stacked on top of each other but it's unable to fit them. Strangle it works when you specify KeepFlat.
Logging