npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bin-packing-3d

v1.0.0

Published

Solution for 3D bin packing problem

Downloads

151

Readme

3D bin packing

JavaScript solution for 3D bin packing problem.

Install

npm i bin-packing-3d

Basics

All interactions happen with 3 main object types:

Bin - space (rectangular cuboid) which is being filled with Items.

let myBin = new Bin(name, width, height, depth, max_weight);

Item - box (also a rectangular cuboid) which is being placed in Bin.

let myItem = new Item(name, width, height, depth, max_weight);

Packer - object through which packing is performed. Packer has three main methods:

let packer = Packer();       // Packer definition

packer.add_bin(myBin);       // Adding bin to packer
packer.add_item(myItem);     // Adding item to bin

packer.pack();               // Packing items to bins

pack(bigger_first, distribute_items) props:

  • bigger_first (boolean) - By default all the bins and items are sorted from the smallest to the biggest.
  • distribute_items (boolean)
    • true => From a list of bins and items, put the items in the bins that at least one item be in one bin that can be fitted. That is, distribute all the items in all the bins so that they can be contained.
    • false (default) => From a list of bins and items, try to put all the items in each bin and in the end it show per bin all the items that was fitted and the items that was not.

After packing:

packer.bins                 # Get all bins of packer
my_bin.items                # Get all fitted items in each bin
my_bin.unfitted_items       # Get all unfitted items in each bin

Example

const { Bin, Item, Packer} = require('bin-packing-3d');

let packer = new Packer();

packer.add_bin(new Bin('small-envelope', 11.5, 6.125, 0.25, 10));
packer.add_bin(new Bin('large-envelope', 15.0, 12.0, 0.75, 15));
packer.add_bin(new Bin('small-box', 8.625, 5.375, 1.625, 70.0));
packer.add_bin(new Bin('medium-box', 11.0, 8.5, 5.5, 70.0));
packer.add_bin(new Bin('medium-2-box', 13.625, 11.875, 3.375, 70.0));
packer.add_bin(new Bin('large-box', 12.0, 12.0, 5.5, 70.0));
packer.add_bin(new Bin('large-2-box', 23.6875, 11.75, 3.0, 70.0));

packer.add_item(new Item('50g [powder 1]', 3.9370, 1.9685, 1.9685, 1));
packer.add_item(new Item('50g [powder 2]', 3.9370, 1.9685, 1.9685, 2));
packer.add_item(new Item('50g [powder 3]', 3.9370, 1.9685, 1.9685, 3));
packer.add_item(new Item('250g [powder 4]', 7.8740, 3.9370, 1.9685, 4));
packer.add_item(new Item('250g [powder 5]', 7.8740, 3.9370, 1.9685, 5));
packer.add_item(new Item('250g [powder 6]', 7.8740, 3.9370, 1.9685, 6));
packer.add_item(new Item('250g [powder 7]', 7.8740, 3.9370, 1.9685, 7));
packer.add_item(new Item('250g [powder 8]', 7.8740, 3.9370, 1.9685, 8));
packer.add_item(new Item('250g [powder 9]', 7.8740, 3.9370, 1.9685, 9));

packer.pack();

for (let i = 0; i < packer.bins.length; i++) {
    console.log(":::::::::::", packer.bins[i]);

    console.log("***************************************************");
    console.log("***************************************************");
}

Credits

License

MIT