{"_id":"boxpack","_rev":"411061","name":"boxpack","description":"Bin packing algorithm for rectangles","dist-tags":{"latest":"0.1.0"},"maintainers":[{"name":"munro","email":"ryan@submersible.io"}],"time":{"modified":"2021-08-04T05:08:40.000Z","created":"2012-08-12T06:00:41.395Z","0.1.0":"2012-08-12T06:00:41.395Z"},"users":{},"author":{"name":"Ryan Munro"},"repository":{"type":"git","url":"https://github.com/munro/boxpack.git"},"versions":{"0.1.0":{"name":"boxpack","version":"0.1.0","description":"Bin packing algorithm for rectangles","main":"boxpack.js","scripts":{"test":"tap test.js"},"repository":{"type":"git","url":"https://github.com/munro/boxpack.git"},"keywords":["box","bin","pack","rect"],"author":{"name":"Ryan Munro"},"license":"BSD","dependencies":{},"devDependencies":{"tap":"~0.3.0"},"_id":"boxpack@0.1.0","dist":{"shasum":"080734832eab86cd9ee8260d2171a5145d072d18","size":4441,"noattachment":false,"key":"/boxpack/-/boxpack-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/boxpack/download/boxpack-0.1.0.tgz"},"maintainers":[{"name":"munro","email":"ryan@submersible.io"}],"directories":{},"publish_time":1344751241395,"_cnpm_publish_time":1344751241395,"_hasShrinkwrap":false}},"readme":"# Boxpack—Bin packing algorithm! [![Build Status](https://secure.travis-ci.org/munro/boxpack.png?branch=master)](http://travis-ci.org/munro/boxpack)\n\nBin packing algorithm!\n\n## Example\n\n```javascript\nvar bin = boxpack();\n\nvar boxes = bin.pack([\n    {width: 50, height: 100},\n    {width: 75, height: 75},\n    {width: 25, height: 25},\n    {width: 100, height: 100}\n]);\n\ndocument.getElementById('result').innerHTML = boxes.map(function (box) {\n    return '<div style=\"' +\n        'position:absolute;' +\n        'border:1px solid black;' +\n        'left:' + box.x + 'px;' +\n        'top:' + box.y + 'px;' +\n        /* subtract border from width & height */\n        'width:' + (box.width - 2) + 'px;' +\n        'height:' + (box.height - 2) + 'px\"></div>';\n}).join('');\n```\n\n## Data structures\n\n### {Rect} `{width: {Number}, height: {Number}}`\n\nDefines rectangles that we want to pack in a bin.\n\n### {Box} `{x: {Number}, y: {Number}, width: {Number}, height: {Number}}`\n\nDefines where a rectangle was packed in a bin.\n\n## Bin methods\n\n### var bin = boxpack({Object} options)\n\nCreates a new bin for packing rects into.\n\n### var result = bin.pack({width: 50, height: 100})\n\n`result` will return `false` if there was no room left to pack the `Rect`.\nOtherwise it will return `Box`\n\n## Weighting algorithms\n\n### boxpack.algo.dist\n\nSorts boxes based on their distance from (0, 0)\n\n### boxpack.algo.top\n\nSorts boxes based on their distance from the X-axis\n\n### boxpack.algo.left\n\nSorts boxes based on their distance from the Y-axis\n\n## Helper functions\n\n### boxpack.rectFit({Rect}, {Box}) -> {Boolean}\n### boxpack.boxFit({Box}, {Box}) -> {Boolean}\n### boxpack.intersect({Box}, {Box}) -> {Boolean}\n### boxpack.divideX({Box}, {Number}) -> {Array {Box}}\n### boxpack.divideY({Box}, {Number}) -> {Array {Box}}\n### boxpack.subtract({Box}, {Box}) -> {Array {Box}}\n\n## License\n\nMIT\n","_attachments":{},"license":"BSD"}