PHP code example of braienstorm / bin-packer

1. Go to this page and download the library: Download braienstorm/bin-packer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

braienstorm / bin-packer example snippets



$Boxes = [
    new Block(100, 100),
    new Block(300, 100),
];
$bin = new Bin(1500,3000);    
$bin->insertManyBlock($Boxes);



$unusedBoxes = $bestBin->getUnpackedBlocks()



    $node = $bin->getNode();
    getUsedBlock($node);

    function getUsedBlock(\Node $node)
    {
        if($node == null)
            return;
        if($node->isUsed())
        {
            print_r($node->getBlock());
            $this->getUsedBlock($node->getRight());
            $this->getUsedBlock($node->getDown());
        }
    }


    $sc = $bestBin->getStatistic();


Array
(
    [score] => 0.72624 // [used] / ([binWidth]*[binHeight])
    [used] => 2269500  // used arrea 
    [free] => 855500   // free arrea
    [binWidth] => 2500 
    [binHeight] => 1250
)


        $visualizer = new Visualizer();
        $image = $visualizer->visualize($bin);
        $image->setFormat('jpg');
        $image->writeImage('bin.jpg');