jerry800416 / 3D-bin-packing

3D Bin Packing improvements based on https://github.com/enzoruiz/3dbinpacking
MIT License
158 stars 44 forks source link

ZeroDivisionError: float division by zero #6

Closed cnr91 closed 2 years ago

cnr91 commented 2 years ago

Hi Jerry,

I was having a problem from the original 3dbin py library. https://github.com/enzoruiz/3dbinpacking/issues/31 When I can't solve the problem. I wanted to use your library. But I'm having another problem with your library.

The problem occurs when the package weight is entered as a float value. Like this: lbs = 0.0345 packer.addItem(Item('test1', 'itemname','cube',(2, 5, 6), lbs , 1, 100, True,'red'))

  File "D:\anaconda3\lib\site-packages\py3dbp\main.py", line 482, in gravityCenter
    result.append(round(i / sum(r) * 100,2))
ZeroDivisionError: float division by zero

Actually, I will be using this code for packaging small products. Not for any container filling operation. My product dimensions are in inches and my weight is in lbs. Do you have a suggestion for me?

Thank you.

cnr91 commented 2 years ago

I solved it this way but I'm not sure what damage it could do to the code. main.py -> 481 line:

for i in r :
  try:
      result.append(round(i / sum(r) * 100,2))
  except:
      result.append(1)
jerry800416 commented 2 years ago

You can check the gravityCenter function in main.py file. The weight is round to the int, if the weight of each item is 0 after rounding, the calculation of the gravity distribution will result in an error. It's not recommended to modify the weight in main.py --> line 481, it will cause the weight distribution calculation to be wrong, maybe you can change the unit from pounds to grams.