chevyray / crunch-rs Goto Github PK
View Code? Open in Web Editor NEWA packer for cramming lots of rectangles into a larger one, designed primarily with sprite packing in mind. Written in Rust.
A packer for cramming lots of rectangles into a larger one, designed primarily with sprite packing in mind. Written in Rust.
Algorithms that pack arbitrary shapes are useful for a variety of applications. For example, a manufacturer can pack parts to be cut from a sheet of material so as to minimize the amount of material wasted. In the most general setting the problem has no known solution. Particular cases, like the one this crate solves, can be shown to be NP-complete. But as with many NP-complete problems, there are approximating algorithms that do pretty well in practice.
It would be nice to have a crate that can pack arbitrary shapes. Such a crate, if it were generic, would have many potential uses.
I can't figure out how to add images to atlas
Most types benefit from a Debug implementation, and it looks like only Rect
supports it in this crate right now.
Specifically, the lack of the Debug trait for PackedItem
means that you can't .unwrap()
or .expect()
the result of Packer::pack
.
I think you should be able to add #[derive(Debug)]
to all of {Item
, PackedItem
, PackedItems
, Packer
, and Rotation
}. It looks like maybe you were avoiding it on the generic types but the derive macro should handle the generic type correctly for this crate's purposes.
Would it be possible to somehow remove the T: Clone
restriction for items? I would think that this should improve performance (especially if the T has some complex data), and possibly streamline the code itself?
It might be possible to do with if the PackedItem<T>
would hold references to T, using Packer
for lifetime. Another option (but i'm not certain it will work), is for fn pack()
to take the ownership of the self.items_to_pack
(replacing it with an empty vec), but that seem to conflict with fn pack_into_po2()
which can call pack()
multiple times. Lastly, perhaps the packed structure could just store a vector of usize
, referencing the indexes of self.items_to_pack
.
One thing to note - I believe it would be possible to optimize this only if all public API would become consuming, e.g. pack(self, ...)
instead of pack(&mut self, ...)
(and same for pack_into_po2
)
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.