Jack000 / SVGnest

An open source vector nesting tool
MIT License
2.27k stars 378 forks source link

How to optimize for minimum height instead of width? #76

Open makenai opened 5 years ago

makenai commented 5 years ago

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

dorkmo commented 5 years ago

you might try deepnest: https://github.com/Jack000/Deepnest its got three options for layout optimization

makenai commented 5 years ago

@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.

kcb0126 commented 5 years ago

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.

tonyqus commented 3 years ago

@kcb0126 Thank you for your tip! It works very well.