0.0.4 • Published 10 years ago

boxpacking v0.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

node-boxpacking v0.1.0

Build Status Built with Grunt

2D bin packing algorithm usefull for sprite-generators or texture atlas

Install

npm install boxpacking

Usage

var boxpacking = require('boxpacking');

var blocks = [
    { width: 100, height: 100 },
    { width: 50, height: 50 },
    { width: 50, height: 50 },
    { width: 50, height: 50 },
    { width: 50, height: 50 },
    { width: 50, height: 50 }
];

var pack = boxpacking(blocks);

This will return into "pack" variable an object which contains a list of blocks with coordinates.

Options:

maxWidth

Result max width.

maxHeight

Result max height.

Result:

{
    list: [
        { width: 100, height: 100, x: 0, y: 0 },
        { width: 50, height: 50, x: 100, y: 0 },
        { width: 50, height: 50, x: 100, y: 50 },
        { width: 50, height: 50, x: 0, y: 100 },
        { width: 50, height: 50, x: 50, y: 100 },
        { width: 50, height: 50, x: 100, y: 100 }
    ],
    excludedBlocks: [],
    width: 150,
    height: 150
}

list

An array of blocks

excludedBlocks

An array of blocks which excluded from result. It can happen when both maxWidth and maxHeight options are passed and algorithm couldn't fit some blocks.

width

Result width.

height

Result height.

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago