padam87/bin-packer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

padam87/bin-packer

最新稳定版本:v0.1.2

Composer 安装命令:

composer require padam87/bin-packer

包简介

2D bin packing for PHP

README 文档

README

2D bin packing for PHP, with rotation and growth function

Usage

Basic

$bin = new Bin(1000, 1000);
$blocks = [
    new Block(100, 100),
    new Block(300, 100),
    new Block(175, 125),
    new Block(200, 75),
    new Block(200, 75),
];

$packer = new BinPacker();

$blocks = $packer->pack($bin, $blocks);

Determining the result (was a block packed?)

foreach ($blocks as $block) {
    if ($block->getNode() && $block->getNode()->isUsed()) {
        // packed
    }
}

Rotation

By default, all blocks are allowed to rotate. Rotation occures only if a fit is not found with the initial orientation.

You can disable rotation by passing false as the 3rd parameter to the block's constructor.

new Block(100, 100, false);

Identifying blocks

Sometimes it can be useful to set an identifier for the block. The optional 4th parameter of the constructor is the block ID.

new Block(100, 100, false, 'My id, can be anything.');

Bin growth

By allowing the bin to grow, you can fit all blocks, every time.

You can enable growth by passing true as the 3rd parameter to the bin's constructor.

$bin = new Bin(1000, 1000, true);

Visualizer

You can use the visualizer to create pictures of the packed bin.

$bin = new Bin(1000, 1000);
$blocks = [
    new Block(100, 100),
    new Block(300, 100),
    new Block(175, 125),
    new Block(200, 75),
    new Block(200, 75),
];

$packer = new BinPacker();

$blocks = $packer->pack($bin, $blocks);

$image = $visualizer->visualize($bin, $blocks);

This feature uses the Imagick extension, and returns an \Imagick class. You can use the result to save, or display the image.

$image->setFormat('jpg');
$image->writeImage('bin.jpg');

visualizer

GIF creator

WARNING The GIF creators performance is very slow. I would suggest only using it for debug purposes, or non real-time scenarios

$packer = new BinPacker();
$gifMaker = new GifMaker(new Visualizer());

$blocks = $packer->pack($bin, $blocks, $gifMaker);

$gif = $gifMaker->create();

$gif->writeImages('bin.gif', true);

visualizer

统计信息

  • 总下载量: 9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 23
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-23