2

I've just come up against a TypeError I've not seen before and can't figure out why it's occurring. Googling for the error TypeError: 'Zero' object is not iterable returns no results. I've tested in python 2.7 and 3.5 and the error is the same in both cases.

Here's the MCVE:

from sympy.geometry.polygon import Polygon
import pyclipper as pc

start_list = [(0, 2), (2, 2), (2, 0), (0, 0)]
scaled = pc.scale_to_clipper(start_list)  # this works fine

as_poly = Polygon(*start_list)
new_list = [(pt.x, pt.y) for pt in as_poly.vertices]
assert new_list == start_list  # check that the lists are the same (this passes)

fail_to_scale = pc.scale_to_clipper(new_list)  # this fails

And the traceback:

Traceback (most recent call last):
  File "C:\Users\Jamie\<blah>\mcve.py", line 10, in <module>
    fails = pc.scale_to_clipper(new_list)
  File "pyclipper/pyclipper.pyx", line 544, in pyclipper.scale_to_clipper (pyclipper/pyclipper.cpp:3535)
  File "pyclipper/pyclipper.pyx", line 542, in pyclipper.scale_to_clipper.scale_value (pyclipper/pyclipper.cpp:3454)
  File "pyclipper/pyclipper.pyx", line 542, in pyclipper.scale_to_clipper.scale_value (pyclipper/pyclipper.cpp:3454)
  File "pyclipper/pyclipper.pyx", line 542, in pyclipper.scale_to_clipper.scale_value (pyclipper/pyclipper.cpp:3416)
TypeError: 'Zero' object is not iterable

Does anyone know what the source of and solution to this error could be?

Jamie Bull
  • 12,889
  • 15
  • 77
  • 116
  • Does the assertion pass or fail? Are there any more lines of codes between the assignment to `new_list` and `fail_to_scale`? Prolly `new_list` was modified – Moses Koledoye Aug 16 '16 at 07:21
  • The assertion passes, and that exact MCVE produces the error. There's no additional code needed to reproduce the problem. – Jamie Bull Aug 16 '16 at 07:45

1 Answers1

2

This has been fixed in PyClipper version 1.0.2, which is preferable to using the workaround described below

Ok, I've tracked the problem back to the values stored in Polygon. The issue is that the value 0 is stored by SymPy as sympy.Zero.

These sympy.Zero values are not accepted by polyclipper.scale_to_clipper() and so are raising the TypeError when checked.

To avoid the issue I can generate new_list casting pt.x and pt.y to float:

new_list = [(float(pt.x), float(pt.y)) for pt in as_poly.vertices]
Jamie Bull
  • 12,889
  • 15
  • 77
  • 116
  • As you have already figured out - the problem is `pyclipper` thinks `sym.Zero` is a collection. This is a bug in the library. While this is getting fixed conversion of `sym.Zero` to `int` or `float` (it gets converted to C++ double anyway ) seems like a valid solution. – greginvm Aug 16 '16 at 21:23
  • 1
    An update: a new version of pyclipper was released that fixes this problem. – greginvm Aug 17 '16 at 12:54