olragon/binpackingjs

Minimum bin size by volume

seanonthenet opened this issue · 3 comments

Hi there.

Is this able to return a minimum 3D bin size by volume given a set of supplied items?

Example use case: a custom box will be made up for the items for each shipment.

Thanks
Sean

There's not a built in method for this but the calculation should be pretty simple:

        let packer = new Packer();
        packer.addItem(new Item("Item 1", 100, 100, 100, 100));
        packer.addItem(new Item("Item 2", 100, 100, 100, 100));
        packer.addItem(new Item("Item 3", 100, 100, 100, 100));
        const totalVolume = packer.items.reduce( ( vol, item ) => vol + item.getVolume(), 0 );

Thanks very much.

For anyone else... to "unfactor precision" 🤷‍♂️ the result you can do this. There's probably a more elegant way. Sorry, I'm not a math guy.

let packer = new Packer();
let FACTOR = 5
packer.addItem(new Item("Item 1", 100, 100, 100, 100));
packer.addItem(new Item("Item 2", 100, 100, 100, 100));
packer.addItem(new Item("Item 3", 100, 100, 100, 100));
const totalVolume = packer.items.reduce( ( vol, item ) => vol + item.getVolume() / (10 ** FACTOR) ** 3 );

Is this solution though just returning the sum of the volumes of Items in a Packer?

If so it doesn't really find the minimum box size that could fit them all taking into account empty space, pivots etc.

Am I right?