potpack icon indicating copy to clipboard operation
potpack copied to clipboard

Boxes with small areas perform worse than larger boxes

Open DomenicoBruzzese opened this issue 5 months ago • 1 comments

When preparing box-areas for a custom uv-unwrapping algorithm, I end up with small boxes that combined together will fit a total area around 1 unit large, e.g.:

[
  { w: 0.05, h: 0.037 },
  { w: 0.015, h: 0.0087 },
  { w: 0.009, h: 0.013 },
  ...
]

when packing these boxes potpack will perform poorly, by laying the boxes mostly horizontally:

Image

However pre-processing my boxes such that they're scaled up by a factor of 100+, will improve results dramatically:

const boxScale = 200;
rects = rects.map(r => ({ w: r.w * boxScale, h: r.h * boxScale }));
const res = potpack(rects);
rects = rects.map(r => ({ w: r.w / boxScale, h: r.h / boxScale, x: r.x / boxScale, y: r.y / boxScale }));
Image

In case this is expected behavior, it would be nice if the documentation reflected this edge case since someone else might incorrectly assume that the algorithm doesn't work when in reality scaling up the boxes might fix the issue

DomenicoBruzzese avatar Sep 05 '25 15:09 DomenicoBruzzese

Yeah, I think potpack assumes an integer grid for sizes since we're laying them out on a pixel grid. Worth adding a note in the readme docs.

mourner avatar Sep 06 '25 10:09 mourner