tamasmeszaros / libnest2d

2D irregular bin packaging and nesting library written in modern C++
GNU Lesser General Public License v3.0
315 stars 104 forks source link

Irregular bins #10

Open samsonsite1 opened 4 years ago

samsonsite1 commented 4 years ago

Do you have any plans to support fitting shapes to irregular bins?

You briefly mentioned it here: https://github.com/tamasmeszaros/libnest2d/issues/7

But, you didn't say if you plan to improve it or expand upon it. I would also be interested in seeing something like this. Thanks.

tamasmeszaros commented 4 years ago

What I can do and surely will in the next few weeks, is make the most out of the current "brain" to handle irregular bins. What you can expect is that you can use a simple polygon as a bin and items will be inside of it -- the boundaries will be respected. But the result can be stupid, I probably won't fix that for a while. You can improve that however with a custom optimization kernel which you can pass as a function object to the nest() function.

samsonsite1 commented 4 years ago

Thanks for the reply.

It would be very interesting if we could pack shapes to a circle or n-sided poly bin. I didn't have anything complex in mind like a bin with exclusion zones, so simple polygon bins are fine by me.

tamasmeszaros commented 4 years ago

I think that this should be possible even with the current code. Go on and try to define a Circle as the bin shape and pass it to the nest function. The App PrusaSlicer for which this library was initially developed, supports circular print beds and it works. Not as polished as for the box shaped bed though.

samsonsite1 commented 4 years ago

Thanks, I tried switching the bin to a Circle, but the compiler can't find a matching overload function for it:

//size_t bins = nest(input, Box( s,s, {0,0} ) ); size_t bins = nest(input, Circle( {0,0}, s ) );

cannot convert from 'libnest2d::_Circle' to 'const libnest2d::Box' no instance of overloaded function "nest" matches the argument list

ItsMeTheBee commented 2 years ago

Hey all! What's the status on irregular nesting? If using a polygon as bin shape is supported, I'd appreciate it very much if you could post a code snippet.

EDIT: I managed to "activate" circular placement by modifying libnest2d.hpp. I added a using directive for an NfpPlacer that accepts Circle instead of Box and a defined new nest() function template using the new Placer. Probably not the best way to do it, but it works :D