{"id":18728750,"url":"https://github.com/rubyonworld/ruby-binpack","last_synced_at":"2025-11-12T05:30:17.840Z","repository":{"id":174008073,"uuid":"540253933","full_name":"RubyOnWorld/ruby-binpack","owner":"RubyOnWorld","description":"This is a gem adapted from a solution for 2-dimensional bin packing by Ilmari Heikkinen.","archived":false,"fork":false,"pushed_at":"2022-09-23T02:47:45.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-28T14:26:16.985Z","etag":null,"topics":["adapt","gem"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RubyOnWorld.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-23T02:47:29.000Z","updated_at":"2022-09-27T20:57:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"11ac8991-9396-4aa6-a715-3c339a49099f","html_url":"https://github.com/RubyOnWorld/ruby-binpack","commit_stats":null,"previous_names":["rubyonworld/ruby-binpack"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruby-binpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruby-binpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruby-binpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Fruby-binpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RubyOnWorld","download_url":"https://codeload.github.com/RubyOnWorld/ruby-binpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239599039,"owners_count":19665911,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adapt","gem"],"created_at":"2024-11-07T14:24:13.195Z","updated_at":"2025-11-12T05:30:17.769Z","avatar_url":"https://github.com/RubyOnWorld.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\nThis is a gem adapted from a solution for 2-dimensional bin packing by Ilmari Heikkinen. From the post:\n\n\u003e It's a greedy heuristic algorithm that tries to fit each box into the trunk, largest first.\n\u003e If no box fits, a new trunk is created.\n\u003e I'm representing trunks as 2D tables of squares (with one unit of hidden padding around), then fill it starting from top left.\n\u003e The fitterfirst finds a row with enough empty space to fit the box and then checks if the next box-height rows also contain the space.\n\u003e If they do, the box is drawn to the rows.\n\u003e Printing is easy because the trunk already is in printable format.\n\n## Usage\n    # Create an array of random items\n    items = []\n    12.times do |i|\n      items \u003c\u003c Binpack::Item.new(\"Associated object #{i+1}\", (rand(10)+2)/2.0, (rand(10)+2)/2.0)\n    end\n\n    # Pack the array of items into a bin where the default bin size is 16x10 with a padding of 1\n    bins = Binpack::Bin.pack(items, [], Binpack::Bin.new(16, 10, 1))\n\n  \nVisual output example:\n\n    puts bins.join(\"\\n\\n\")\n\n    22222_0000_11_cc\n    22222_0000_11_cc\n    22222_0000_11_cc\n    ___________11_cc\n    99_888_aaa____cc\n    99_888__________\n    99_____b_aaa____\n    99_0_7_b________\n    99_0_7_b_0______\n    ___0_7___0______\n    \nArray of items, their locations locations, and whether or not they had to be rotated 90º\n\n    puts bins[0].items.inspect\n    \n    [\n      [#\u003cBinpack::Item:0x007f84bb14c5c0 @obj=\"Associated object 12\", @width=5.0, @height=3.0, @rotated=false\u003e, 1, 1],\n      [#\u003cBinpack::Item:0x007f84bb031438 @obj=\"Associated object 1\", @width=4.5, @height=3.0, @rotated=false\u003e, 7, 1],\n      [#\u003cBinpack::Item:0x007f84bb14c6b0 @obj=\"Associated object 11\", @width=2.5, @height=4.5, @rotated=false\u003e, 12, 1],\n      [#\u003cBinpack::Item:0x007f84bb031000 @obj=\"Associated object 3\", @width=2.0, @height=5.0, @rotated=false\u003e, 15, 1],\n      [#\u003cBinpack::Item:0x007f84bb030dd0 @obj=\"Associated object 4\", @width=2.0, @height=5.0, @rotated=false\u003e, 1, 5],\n      [#\u003cBinpack::Item:0x007f84bb14c890 @obj=\"Associated object 9\", @width=3.5, @height=2.5, @rotated=false\u003e, 4, 5],\n      [#\u003cBinpack::Item:0x007f84bb14c980 @obj=\"Associated object 8\", @width=3.5, @height=1.5, @rotated=false\u003e, 8, 5],\n      [#\u003cBinpack::Item:0x007f84bb030b00 @obj=\"Associated object 5\", @width=1.5, @height=3.0, @rotated=false\u003e, 4, 8],\n      [#\u003cBinpack::Item:0x007f84bb0311e0 @obj=\"Associated object 2\", @width=1.0, @height=4.0, @rotated=false\u003e, 6, 8],\n      [#\u003cBinpack::Item:0x007f84bb14c7a0 @obj=\"Associated object 10\", @width=1.0, @height=3.5, @rotated=false\u003e, 8, 7],\n      [#\u003cBinpack::Item:0x007f84bb14cb60 @obj=\"Associated object 6\", @width=3.5, @height=1.0, @rotated=false\u003e, 10, 7],\n      [#\u003cBinpack::Item:0x007f84bb02a070 @obj=\"Associated object 7\", @width=1.0, @height=2.5, @rotated=true\u003e, 10, 9]\n    ]\n    \n## Notes\n\n1. The packing assumes a border of @padding. If you wish to put images on an 11\"x17\"\npiece of paper with a 1\" border, you will need to make the bin 16x10 with a padding of 1.\n2. When layout out your objects, be sure to note whether or not the item had to be rotated to fit.\n3. The algorithm uses string matching to determine placement so if higher precision than integral is required, you'll need to use a multiplier on everything.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fruby-binpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubyonworld%2Fruby-binpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Fruby-binpack/lists"}