public function doVolumePacking(): PackedBoxList
    {
        $packedBoxes = new PackedBoxList();

        //Keep going until everything packed
        while ($this->items->count()) {
            $packedBoxesIteration = [];

            //Loop through boxes starting with smallest, see what happens
            foreach ($this->boxes as $box) {
                $volumePacker = new VolumePacker($box, clone $this->items);
                $volumePacker->setLogger($this->logger);
                $packedBox = $volumePacker->pack();
                if ($packedBox->getItems()->count()) {
                    $packedBoxesIteration[] = $packedBox;

                    //Have we found a single box that contains everything?
                    if ($packedBox->getItems()->count() === $this->items->count()) {
                        break;
                    }
                }
            }

            //Find best box of iteration, and remove packed items from unpacked list
            $bestBox = $this->findBestBoxFromIteration($packedBoxesIteration);

            /** @var PackedItem $packedItem */
            foreach ($bestBox->getItems() as $packedItem) {
                $this->items->remove($packedItem->getItem());
            }

            $packedBoxes->insert($bestBox);
        }

        return $packedBoxes;
    }
public function doVolumePacking(): PackedBoxList
    {
        $packedBoxes = new PackedBoxList();

        //Keep going until everything packed
        while ($this->items->count()) {
            $packedBoxesIteration = [];

            //Loop through boxes starting with smallest, see what happens
            foreach ($this->boxes as $box) {
                $volumePacker = new VolumePacker($box, clone $this->items);
                $volumePacker->setLogger($this->logger);
                $packedBox = $volumePacker->pack();
                if ($packedBox->getItems()->count()) {
                    $packedBoxesIteration[] = $packedBox;

                    //Have we found a single box that contains everything?
                    if ($packedBox->getItems()->count() === $this->items->count()) {
                        break;
                    }
                }
            }

            //Find best box of iteration, and remove packed items from unpacked list
            $bestBox = $this->findBestBoxFromIteration($packedBoxesIteration);

            /** @var PackedItem $packedItem */
            foreach ($bestBox->getItems() as $packedItem) {
                $this->items->remove($packedItem->getItem());
            }

            $packedBoxes->insert($bestBox);
        }

        return $packedBoxes;
    }
public function doVolumePacking ( ) : PackedBoxList { $ packedBoxes = new PackedBoxList ( ) ; //Keep going until everything packed while ( $ this -> items -> count ( ) ) { $ packedBoxesIteration = [ ] ; //Loop through boxes starting with smallest, see what happens foreach ( $ this -> boxes as $ box ) { $ volumePacker = new VolumePacker ( $ box , clone $ this -> items ) ; $ volumePacker -> setLogger ( $ this -> logger ) ; $ packedBox = $ volumePacker -> pack ( ) ; if ( $ packedBox -> getItems ( ) -> count ( ) ) { $ packedBoxesIteration [ ] = $ packedBox ; //Have we found a single box that contains everything? if ( $ packedBox -> getItems ( ) -> count ( ) === $ this -> items -> count ( ) ) { break ; } } } //Find best box of iteration, and remove packed items from unpacked list $ bestBox = $ this -> findBestBoxFromIteration ( $ packedBoxesIteration ) ; /** @var PackedItem $packedItem */ foreach ( $ bestBox -> getItems ( ) as $ packedItem ) { $ this -> items -> remove ( $ packedItem -> getItem ( ) ) ; } $ packedBoxes -> insert ( $ bestBox ) ; } return $ packedBoxes ; }
Pack items into boxes using the principle of largest volume item first.

@throws ItemTooLargeException

@return PackedBoxList
Pack items into boxes using the principle of largest volume item first .