Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement IRectanglePacker interface and various packing algorithms #5994

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

EVAST9919
Copy link
Contributor

A step towards resolving #5986.
TextureAtlas has been reworked to support new IRectanglePacker interface, so switching the algorithm is a one line change. For now it's using the same algo as previously since I'm not sure about performance concerns (probably benchmarking needed).

Also adds a nice test scene to play around with:
Снимок экрана (13)

@peppy
Copy link
Sponsor Member

peppy commented Sep 15, 2023

If performance is a perceived concern, I'd recommend adding benchmarks. They should be very simple to create, since we already have all the tooling in place.

@EVAST9919
Copy link
Contributor Author

EVAST9919 commented Sep 17, 2023

So I've added some benchmarks in which I'm creating and populating bins with 20 rectangles of various sizes. As you can see the difference is quite big. Basically we are trading performance for potential capacity (as expected, probably).
From these we can assume that Guillotine is a good middle ground, although it can peroform worse than Shelf (currently used in TextureAtlas on master) in some cases fitness-wise and practially it's trash when in comes to adding a big rectangle after many small ones because it's best use-case is when upcoming rectangles are sorted beforehand. However with the underlying structure we can easily track big chunks of previously wasted space (as per issue) and removing a rectangle is as simple as adding the new empty space to already existing list, which is a desired behavior.
Also note that my implementation probably isn't perfect and can potentially be improved.

Method Mean Error StdDev Gen0 Allocated
PopulateShelf 914.7 ns 1.48 ns 1.38 ns 0.0191 40 B
PopulateShelfRemainder 1,039.4 ns 2.06 ns 1.92 ns 0.0381 80 B
PopulateGuillotine 11,709.0 ns 29.93 ns 28.00 ns 0.5341 1128 B
PopulateMaximal 337,441.9 ns 1,453.73 ns 1,359.82 ns 0.9766 2176 B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants