SVGnest
SVGnest copied to clipboard
How to optimize for minimum height instead of width?
Hi, I noted in the docs and comments that this is tuned for CNC applications where you want to create a long sliver of unused material. We are working with a roll where it makes sense to optimize for minimum height. Is there a way to switch over the rule easily?
I don't have a great understanding of genetic algorithm fitness functions, but I've noted a couple of places in placementworker.js that seem like they could be relevant (the lines involving minwidth and one about weighing the width more in an area calculation). I've basically tried to flip those to height, and it seems to be a bit closer what I'm looking for. Am I on the right track or did I do something bonkers?
https://github.com/makenai/SVGnest/commit/838d575e3e6d9215d603cefcd379bdae516cfe4d
you might try deepnest: https://github.com/Jack000/Deepnest its got three options for layout optimization
@dorkmo Thanks for this suggestion. I gave it a shot and even though 'gravity' still says it optimizes for width, it does a really good job of packing toward the top of the bounding box for me by default! I'm still pretty curious about how to modify the fitness function, but now I have another example to look at.
Yes, @makenai . You're right. placementwork.js
contains the gravity part. You can change the code area = rectbounds.width*2 + rectbounds.height;
to area = rectbounds.width + rectbounds.height*2;
to change direction of optimization.
@kcb0126 Thank you for your tip! It works very well.