semibran / pack Goto Github PK
View Code? Open in Web Editor NEW:package: greedy rectangle packing algorithm
Home Page: https://semibran.github.io/pack
License: MIT License
:package: greedy rectangle packing algorithm
Home Page: https://semibran.github.io/pack
License: MIT License
Would be neat to have an interactive example on gh-pages
to demonstrate how the algorithm works:thinking:
The algorithm already minimizes whitespace, but I'm currently searching for a heuristic that prefers layouts that place whitespace closer to the bottom-right corner than leaving them strewn arbitrarily throughout the configuration.
An example of a "bad" configuration (generated automatically):
a "good" configuration (tweaked manually):
The second one is easily the more compact revision. Unfortunately, calculating a score based on whitespace "position" is a lot more difficult than it appears. I've tried sorting by a lot of different positional shenanigans with the boxes (note that this algorithm isn't strictly bound to a grid) but no satisfactory results have come up yet.
There are actually plenty of good box packing algorithms out there, but I made my own version without much regard for optimization since I had planned on using it for a spritesheet generator anyway. Surprisingly, I've found that arranging a mere six boxes creates upwards of 1000 permutations on average and already takes a few seconds to load. Seven boxes made Chromium lock up entirely in my own experience and required a system restart.
I haven't done benchmarks yet (which is another issue entirely), but I'm assuming there's a large performance bottleneck stemming from recursion and the subsequent mass object creation that's going on.
Basically, I'd love to create an imperative version of this algorithm or at least find some loopholes to keep memory usage to a bare minimum.
Vectors are currently modeled as arrays in the current implementation, adding an extra layer of versatility. The current algorithm should be expanded to cover any dimension.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.