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.

Maintainersamcodes
Websitehttp://samcodes.co.uk/code/
Current version1.0.1
StatisticsInstalled 20 times
LicenseMIT
Tags cross, game, haxe, tool, utility

README.md

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.

Features

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

Usage

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));
}

Install

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

Screenshots of the demo:

Screenshot

Screenshot

Notes

  • 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.