earcut-python icon indicating copy to clipboard operation
earcut-python copied to clipboard

TypeError: unsupported operand type(s) for <<: 'float' and 'int'

Open RoboDonut opened this issue 4 years ago • 4 comments

awesome repo!!

I am getting the above error when running a fairly large and complex concave polygon with a hole ( full trace is below ).

updating lines 455 and 456 to force the result to an int seems to be sufficient x = int(32767 * (x - minX) // size) y = int(32767 * (y - minY) // size)

  File ".../scratch_python/env/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3343, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-c540e453c829>", line 1, in <module>
    runfile(.../scratches/scratch.py', wdir='.../scratches')
  File "/snap/pycharm-professional/230/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/snap/pycharm-professional/230/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File ".../scratches/scratch.py", line 48, in <module>
    main('.../alabama_smsa.geojson')
  File ".../scratches/scratch.py", line 39, in main
    triangles.extend(triangulate_poly(x['geometry']['coordinates']))
  File ".../scratches/scratch.py", line 14, in triangulate_poly
    earcut_indexes = earcut.earcut(flat_coords['vertices'],flat_coords['holes'],flat_coords['dimensions'])
  File ".../earcut/earcut.py", line 48, in earcut
    earcutLinked(outerNode, triangles, dim, minX, minY, size)
  File ".../earcut/earcut.py", line 106, in earcutLinked
    indexCurve(ear, minX, minY, size)
  File ".../earcut/earcut.py", line 369, in indexCurve
    p.z = zOrder(p.x, p.y, minX, minY, size)
  File ".../earcut/earcut.py", line 458, in zOrder
    x = (x | (x << 8)) & 0x00FF00FF
TypeError: unsupported operand type(s) for <<: 'float' and 'int'```

RoboDonut avatar Mar 16 '21 16:03 RoboDonut

Hi @RoboDonut, can you provide by any chance the data you've used when getting this error?

simplylu avatar May 18 '22 11:05 simplylu

Yep, had the same issue and using int(32767 * (x - minX) // size) resolved it. The // operator doesn't give an int when one of the operators is a float it seems.

harshapraneeth avatar May 29 '22 02:05 harshapraneeth

@js-on i think this was the file i was working with at the time alabama_smsa.zip

RoboDonut avatar May 31 '22 16:05 RoboDonut

Hey, is this poblem also in the Pypi released version? If yes, please checkout this issue - https://github.com/joshuaskelly/earcut-python/issues/1#issuecomment-1129801946

vojtatom avatar Jun 29 '22 07:06 vojtatom