mapbox / mapbox/potpack

Boxes with small areas perform worse than larger boxes

Open
#13 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
JavaScript
Stars
355
Forks
24
PR merge metrics
No merged PRs in 30d

Description

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.:

```javascript
[
{ 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:

```javascript
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported behavior through the potpack(rects) entry point with the small box values shown, then compare it with the same boxes scaled by 200 and scaled back afterward. Determine whether the difference is expected or a defect; done means either documenting the scaling workaround and edge case or providing a verified correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.