bernhard-42 / jupyter-cadquery

An extension to render cadquery objects in JupyterLab via pythreejs
Apache License 2.0
321 stars 44 forks source link

Global vector "Reverse()" method misused in tessellator.py #97

Open tdeyster opened 1 year ago

tdeyster commented 1 year ago

I ran into a bug when plotting a complex shape in in line 169 of tesselator.py

 flat.extend(n_buf.Reverse().Coord() if internal else n_buf.Coord())

"AttributeError: 'NoneType' object has no attribute 'Coord'"

Upon closer inspection I see that the .Reverse() method reverses the array in place and doesn't return it.

from OCP.gp import gp_Vec

n_buf = gp_Vec()
print("Is None?", n_buf.Reverse() is None)

prints out: "Is None? True"

For the next release I would recommend the following fix to replace line 169 in tessellator.py:

# flat.extend(n_buf.Reverse().Coord() if internal else n_buf.Coord()) # old line 169; error here: n_buf.Reverse() is None
if internal: n_buf.Reverse()# TDE Added 5/16/23
flat.extend(n_buf.Coord()) #TDE Added 5/16/23
bernhard-42 commented 1 year ago

Thanks @tdeyster for raising it. You're right Reverse returns None, only Reversed returns the reversed copy (https://dev.opencascade.org/doc/refman/html/classgp___vec.html#a12bc5a113c23663f11b1f0bd578ac13d)