dagmike/bin-packing

2D bin packing PHP implementation

Installs: 6 757

Dependents: 0

Suggesters: 0

Security: 0

Stars: 8

Watchers: 1

Forks: 7

Open Issues: 8

pkg:composer/dagmike/bin-packing

1.7.2 2021-02-27 14:19 UTC

This package is not auto-updated.

Last update: 2025-09-28 13:41:06 UTC


README

This repository is a port of the 2D bin packing algorithms found here: juj/RectangleBinPack into PHP.

Installation

You can install the package via composer:

composer require dagmike/bin-packing

Usage

use BinPacking\RectangleBinPack;
use BinPacking\Rectangle;

$bin = (new RectangleBinPack(1000, 1000))->init();

$packed = $bin->insert(new Rectangle(100, 100), "RectBestAreaFit");

if ($packed) {
    echo "Item ({$packed->getWidth()}x{$packed->getHeight()}) packed at position ({$packed->getX()}, {$packed->getY()})";
} else {
    echo "Unable to pack item";
}

Currently Implemented Algorithms

  • Maximum Rectangles
    • Bottom-Left - RectBottomLeft
    • Best Area Fit - RectBestAreaFit
    • Best Short Side Fit - RectBestShortSideFit
    • Best Long Side Fit - RectBestLongSideFit
    • Linear - RectLinear