PHPackages                             latuconsinafr/3d-bin-packager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. latuconsinafr/3d-bin-packager

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

latuconsinafr/3d-bin-packager
=============================

PHP Library for 3D Bin Packing.

v1.0(4y ago)2869.7k↓58%15[5 issues](https://github.com/latuconsinafr/3d-bin-packager/issues)[2 PRs](https://github.com/latuconsinafr/3d-bin-packager/pulls)MITPHPPHP ^7.4 || ^8.0

Since Nov 29Pushed 2y ago2 watchersCompare

[ Source](https://github.com/latuconsinafr/3d-bin-packager)[ Packagist](https://packagist.org/packages/latuconsinafr/3d-bin-packager)[ RSS](/packages/latuconsinafr-3d-bin-packager/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

3D Bin Packager
===============

[](#3d-bin-packager)

[![build](https://github.com/latuconsinafr/3d-bin-packager/actions/workflows/ci-workflow.yml/badge.svg)](https://github.com/latuconsinafr/3d-bin-packager/actions/workflows/ci-workflow.yml/badge.svg)[![codecov](https://camo.githubusercontent.com/3ee6a9389893865285f52324c9250a138df5f006f329d6cc179823023024d935/68747470733a2f2f636f6465636f762e696f2f67682f6c617475636f6e73696e6166722f33642d62696e2d7061636b616765722f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d36543648593934564750)](https://codecov.io/gh/latuconsinafr/3d-bin-packager)

This package contains a PHP implementation to solve 3d bin packing problems based on [gedex](https://github.com/gedex/bp3d) implementation on Go and [enzoruiz](https://github.com/enzoruiz/3dbinpacking) implementation on Python with some modifications to make it more modular.

Installation
------------

[](#installation)

Install by adding the package as a [Composer](https://getcomposer.org)requirement:

```
$ composer require latuconsinafr/3d-bin-packager
```

Usage
-----

[](#usage)

There's an example inside the root project `example.php`. Just simply type the command `php example.php` in the project's root and it would display the time elapsed and corresponding results with the number of lower bounds and the list of the bins (support for json encode cause every class implements the `\JsonSerializable` interface).

First of all, you have to initialize the packager object:

```
$packager = new Packager(2, SortType::DESCENDING);
```

The packager constructor takes two parameters:

- Precision: The number of digits after the decimal point. It will be used for number of digits to round to.
- Sort type: With two types available `SortType::ASCENDING` and `SortType::DESCENDING`. This sort type will be used to sort the bins and the items volume inside the packager based on the chosen sort type (whether it is ascending or descending)

After you initialized the packager, you can start to add the bin(s) or the item(s) into the packager with these 4 following methods:

```
// To add the bin one by one
$packager->addBin(new Bin('your-bin-identifier', 4, 4.5, 5.221, 50));

// Or if you wish to add all the bins at once
$packager->addBins([
    new Bin('your-first-bin-identifier', 2.22, 5.4, 20, 100),
    new Bin('your-second-bin-identifier', 1, 2, 1.5, 10)
]);

// It would be the same for the item(s)
$packager->addItem(new Item('item-id-1', 2, 2, 2, 5));

$packager->addItems([
    new Item('item-id-2', 1, 4.225, 2, 5),
    new Item('item-id-3', 2, 5, 2, 2.525),
    new Item('item-id-4', 1, 3.5, 3, 10),
    new Item('item-id-5', 3.551, 2, 2, 12.5)
]);
```

Then to pack all the item(s) to all the bin(s):

```
$packager->withFirstFit()->pack()
```

To get the result and other details after the packing are listed below:

- To get all the bin(s) after the packing you can use either the `$packager->getBins()` or the `$packager->getIterableBins()` to return the `ArrayIterator` data type. You can see the id, length, height and etc for the bins inside the iterable and also all the fitted items inside the `fittedItems` property.
- Due to the first fit method, the packing process would try to fit as much items as possible to the first bin and if there's no more space inside the bin, all the remaining items would be listed inside the `unfittedItems` property and move to the next bin. You can also see the total fitted or unfitted volume and weight via `getTotalFittedVolume()`, `getTotalFittedWeight()`, etc.
- The identifier is used to make every single bin and item unique.
- You can also see the total of all bin(s) and item(s) from the Packager class with `getTotalBinsVolume()`, `getTotalBinsWeight()`, etc.
- You can get further detailed information about the fitted item inside the bin such as the current rotation type which is applied to fit the item into the bin via `getRotationType()` (you can see the `RotationCombinationType::class` for the rotation list).
- You can serialize the resulted bins to see something like this:

```
{
    "bin-id": {
        "id": "bin-id",
        "length": 8,
        "breadth": 5,
        "height": 8,
        "volume": 320,
        "weight": 100,
        "fittedItems": [
            {
                "id": "item-id",
                "length": 3.1,
                "breadth": 5,
                "height": 4,
                "volume": 62,
                "weight": 2,
                "rotationType": 0, // You can get the rotation type of any item inside the bin
                "position": { // You can also get the detailed position of any item inside the bin
                    "x-axis": 0,
                    "y-axis": 0,
                    "z-axis": 0
                }
            }
            ...
        ],
        "totalFittedVolume": 212.23,
        "totalFittedWeight": 65.83,
        ...
    }
}
```

- You can also get the corresponding position of any item inside the bin which is represented by the x-axis, y-axis and z-axis using `getPosition()`. In case you want to plot or use it for further analysis.
- You can check the phpdoc or the code for further information.

Credits
-------

[](#credits)

-
-

License
-------

[](#license)

This package is under [MIT](https://github.com/latuconsinafr/3d-bin-packager/blob/main/LICENSE) license.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community12

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1677d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0cd2ee3bf2bfbb8e32999a719b1b1a3810d8a101f2168f11d40a77d00ccd8ced?d=identicon)[latuconsinafr](/maintainers/latuconsinafr)

---

Top Contributors

[![latuconsinafr](https://avatars.githubusercontent.com/u/23124690?v=4)](https://github.com/latuconsinafr "latuconsinafr (20 commits)")

---

Tags

2d-bin-packing3d-bin-packingbin-packingbin-packing-problemphpphpbin packing2d-bin-packing3d-bin-packing

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/latuconsinafr-3d-bin-packager/health.svg)

```
[![Health](https://phpackages.com/badges/latuconsinafr-3d-bin-packager/health.svg)](https://phpackages.com/packages/latuconsinafr-3d-bin-packager)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21623.4k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
