1. Go to this page and download the library: Download daika7ana/smallest-box 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/ */
daika7ana / smallest-box example snippets
use Daika7ana\SmallestBox\Item;
use Daika7ana\SmallestBox\SmallestBoxFinder;
$items = [
new Item(5.0, 3.0, 2.0),
new Item(3.0, 3.0, 3.0),
new Item(2.0, 2.0, 1.0),
];
$finder = new SmallestBoxFinder();
$box = $finder->find($items);
echo $box; // "5.00 x 5.00 x 3.00"
echo $box->volume(); // 75.0
// Default: guillotine (fast, ~65% efficiency for diverse items)
$finder = new SmallestBoxFinder();
// MaxRects (slower, ~100% efficiency for diverse items)
$finder = new SmallestBoxFinder(SmallestBoxFinder::ALGO_MAXRECTS);
// ExtremePoint (medium speed, ~75% efficiency for diverse items)
$finder = new SmallestBoxFinder(SmallestBoxFinder::ALGO_EXTREMEPOINT);
$finder = new SmallestBoxFinder();
// Sort items by height ascending (build layers from bottom up)
$finder->addSortOrder(function (Item $a, Item $b): int {
return $a->height() <=> $b->height();
});
// Pack widest items first
$finder->addPackOrder(function (Item $a, Item $b): int {
return $b->width() <=> $a->width();
});
$box = $finder->find($items);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.