braienstorm / bin-packer
PHP的2D箱子打包
v1.0.3
2023-03-07 06:49 UTC
Requires
- php: ^7.2 || ^8.0
Requires (Dev)
- ext-imagick: *
Suggests
- ext-imagick: To use the visualizer
This package is auto-updated.
Last update: 2024-09-07 10:09:19 UTC
README
我为了一个金属切割公司制作的。此代码选择适合切割的原金属板。原始想法来源于Padam87的链接: https://github.com/Padam87/bin-packer PHP的2D箱子打包,支持旋转。
用法
基本
$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');