Skip to content

Bug: 2D Bin packing fails to place all boxes vertically when there's sufficient space #42

@FaureAlexis

Description

@FaureAlexis

Description

When trying to pack identical boxes vertically (where width prevents horizontal placement), the algorithm fails to place all boxes despite having sufficient vertical space.

Reproduction

const { Bin, Box, Packer, heuristics } = require('binpackingjs').BP2D;

const boxes = Array(10).fill().map((_, i) => new Box(8604, 17470));
const bin = new Bin(12992, 251568, new heuristics.BestShortSideFit());
const packer = new Packer([bin]);
const pack = packer.pack(boxes);
console.log(`Packed ${pack.length} of ${boxes.length} boxes`);

Expected Behavior

  • All 10 boxes should be packed vertically since:
    • Bin width (12992) > Box width (8604)
    • Total height needed (17470 × 10 = 174700) < Bin height (251568)
    • Boxes can only stack vertically as 2 boxes won't fit horizontally (8604 × 2 > 12992)

Actual Behavior

  • Only 3 boxes are packed
  • Algorithm stops at y=34940 (exactly 2 boxes height)
  • Remaining 7 boxes are left unpacked despite having sufficient vertical space

Environment

  • binpackingjs version: latest (3.0.2)
  • Node.js version used 18.15 & 20.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions