Awesome
2D rectangular bin packing algorithms for the Haxe bin-packing haxelib. Run the demo in your browser.
Based on the public domain C++ bin packers by Jukka Jylänki.
Features
- Several fast approximate bin packing algorithms.
- "Occupancy rate" measure to compare packing performance.
- Configurable packing heuristics.
Usage
Run the demo in your browser and refer to the example code.
Basic usage example:
// Initialize a bin packer
var binWidth:Int = 800;
var binHeight:Int = 400;
var useWasteMap:Bool = true;
var packer = new SkylinePacker(binWidth, binHeight, useWasteMap);
// Start packing rectangles
var rectWidth:Int = 20;
var rectHeight:Int = 40;
var heuristic:LevelChoiceHeuristic = LevelChoiceHeuristic.MinWasteFit;
var rect:Rect = packer.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 via 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:
Notes
- The algorithms in this haxelib are ported from public domain C++ code by Jukka Jylänki.
- For details about the algorithms, see Jukka's blog posts and paper.
- If you have any questions or suggestions then get in touch.