protected function calculateAdditionalItemsPackedWithThisOrientation(
        OrientatedItem $prevItem,
        ItemList $nextItems,
        int $originalWidthLeft,
        int $originalLengthLeft,
        int $depthLeft,
        int $currentRowLengthBeforePacking
    ): int {
        $packedCount = 0;

        $currentRowLength = max($prevItem->getLength(), $currentRowLengthBeforePacking);

        $itemsToPack = $nextItems->topN(8); // cap lookahead as this gets recursive and slow

        $tempBox = new WorkingVolume($originalWidthLeft - $prevItem->getWidth(), $currentRowLength, $depthLeft, PHP_INT_MAX);
        $tempPacker = new VolumePacker($tempBox, clone $itemsToPack);
        $remainingRowPacked = $tempPacker->pack();
        /** @var PackedItem $packedItem */
        foreach ($remainingRowPacked->getItems() as $packedItem) {
            $itemsToPack->remove($packedItem->getItem());
        }

        $tempBox = new WorkingVolume($originalWidthLeft, $originalLengthLeft - $currentRowLength, $depthLeft, PHP_INT_MAX);
        $tempPacker = new VolumePacker($tempBox, clone $itemsToPack);
        $nextRowsPacked = $tempPacker->pack();
        /** @var PackedItem $packedItem */
        foreach ($nextRowsPacked->getItems() as $packedItem) {
            $itemsToPack->remove($packedItem->getItem());
        }

        $this->logger->debug('Lookahead with orientation', ['packedCount' => $packedCount, 'orientatedItem' => $prevItem]);

        return $nextItems->count() - $itemsToPack->count();
    }
protected function calculateAdditionalItemsPackedWithThisOrientation(
        OrientatedItem $prevItem,
        ItemList $nextItems,
        int $originalWidthLeft,
        int $originalLengthLeft,
        int $depthLeft,
        int $currentRowLengthBeforePacking
    ): int {
        $packedCount = 0;

        $currentRowLength = max($prevItem->getLength(), $currentRowLengthBeforePacking);

        $itemsToPack = $nextItems->topN(8); // cap lookahead as this gets recursive and slow

        $tempBox = new WorkingVolume($originalWidthLeft - $prevItem->getWidth(), $currentRowLength, $depthLeft, PHP_INT_MAX);
        $tempPacker = new VolumePacker($tempBox, clone $itemsToPack);
        $remainingRowPacked = $tempPacker->pack();
        /** @var PackedItem $packedItem */
        foreach ($remainingRowPacked->getItems() as $packedItem) {
            $itemsToPack->remove($packedItem->getItem());
        }

        $tempBox = new WorkingVolume($originalWidthLeft, $originalLengthLeft - $currentRowLength, $depthLeft, PHP_INT_MAX);
        $tempPacker = new VolumePacker($tempBox, clone $itemsToPack);
        $nextRowsPacked = $tempPacker->pack();
        /** @var PackedItem $packedItem */
        foreach ($nextRowsPacked->getItems() as $packedItem) {
            $itemsToPack->remove($packedItem->getItem());
        }

        $this->logger->debug('Lookahead with orientation', ['packedCount' => $packedCount, 'orientatedItem' => $prevItem]);

        return $nextItems->count() - $itemsToPack->count();
    }
protected function calculateAdditionalItemsPackedWithThisOrientation ( OrientatedItem $ prevItem , ItemList $ nextItems , int $ originalWidthLeft , int $ originalLengthLeft , int $ depthLeft , int $ currentRowLengthBeforePacking ) : int { $ packedCount = 0 ; $ currentRowLength = max ( $ prevItem -> getLength ( ) , $ currentRowLengthBeforePacking ) ; $ itemsToPack = $ nextItems -> topN ( 8 ) ; // cap lookahead as this gets recursive and slow $ tempBox = new WorkingVolume ( $ originalWidthLeft - $ prevItem -> getWidth ( ) , $ currentRowLength , $ depthLeft , PHP_INT_MAX ) ; $ tempPacker = new VolumePacker ( $ tempBox , clone $ itemsToPack ) ; $ remainingRowPacked = $ tempPacker -> pack ( ) ; /** @var PackedItem $packedItem */ foreach ( $ remainingRowPacked -> getItems ( ) as $ packedItem ) { $ itemsToPack -> remove ( $ packedItem -> getItem ( ) ) ; } $ tempBox = new WorkingVolume ( $ originalWidthLeft , $ originalLengthLeft - $ currentRowLength , $ depthLeft , PHP_INT_MAX ) ; $ tempPacker = new VolumePacker ( $ tempBox , clone $ itemsToPack ) ; $ nextRowsPacked = $ tempPacker -> pack ( ) ; /** @var PackedItem $packedItem */ foreach ( $ nextRowsPacked -> getItems ( ) as $ packedItem ) { $ itemsToPack -> remove ( $ packedItem -> getItem ( ) ) ; } $ this -> logger -> debug ( 'Lookahead with orientation' , [ 'packedCount' => $ packedCount , 'orientatedItem' => $ prevItem ] ) ; return $ nextItems -> count ( ) - $ itemsToPack -> count ( ) ; }
Approximation of a forward-looking packing.

Not an actual packing, that has additional logic regarding constraints and stackability, this focuses
purely on fit.

@param  OrientatedItem $prevItem
@param  ItemList       $nextItems
@param  int            $originalWidthLeft
@param  int            $originalLengthLeft
@param  int            $depthLeft
@param  int            $currentRowLengthBeforePacking
@return int
Approximation of a forward - looking packing .