bin-packing 1.0.1

2D rectangle bin packing algorithms

Released 2016-01-01.

To install, run:

haxelib install bin-packing 1.0.1

See using Haxelib in Haxelib documentation for more information.

Current version1.0.1
StatisticsInstalled 29 times
Tags cross, game, haxe, tool, utility

Project logo

2D rectangular bin packing algorithms for the Haxe bin-packing haxelib. Try the demo out in your browser.

Based on the public domain C++ bin packing implementations by Jukka Jylänki.


  • Several fast approximate bin packing algorithms.
  • "Occupancy rate" measure to compare packing performance.
  • Configurable packing heuristics.


Try the demo in your browser, or refer to the example code.

Basic usage example:

// Initialize one of the bin packers
var binWidth:Int = 800;
var binHeight:Int = 400;
var useWasteMap:Bool = true;
var packer = new SkylinePack(binWidth, binHeight, useWasteMap);

// Start packing rectangles
var rectWidth:Int = 20;
var rectHeight:Int = 40;
var heuristic:LevelChoiceHeuristic = LevelChoiceHeuristic.MinWasteFit;
var rect:Rect = skylinePack.insert(rectWidth, rectHeight, heuristic);

if(rect == null) {
	trace("Failed to pack rect");
} else {
	trace("Inserted rect at: " + Std.string(rect.x) + "," + Std.string(rect.y));


Get the Haxe library code here or through haxelib.

Include it in your `.hxml`

-lib bin-packing

Or add it to your `Project.xml`:

<haxelib name="bin-packing" />


Screenshots of the demo:




  • The algorithms in this haxelib were ported from a public domain C++ implementations by Jukka Jylänki.
  • For details about the algorithms, see Jukka's blog posts and paper.
  • The haxelib supports every Haxe target, but has not been thoroughly tested or optimized for performance, especially on native targets.
  • If you have any questions or suggestions then get in touch.