無法在pyclipper中擴展 - TypeError:'Zero'對象不可迭代

[英]Failure to scale in pyclipper - TypeError: 'Zero' object is not iterable


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.

我剛剛遇到了一個我以前從未見過的TypeError,無法弄清楚它為什么會發生。谷歌搜索錯誤TypeError:'零'對象不可迭代返回沒有結果。我已經在python 2.7和3.5中測試過,兩種情況下的錯誤都是一樣的。

Here's the MCVE:

這是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?

有誰知道這個錯誤的來源和解決方案是什么?

1 个解决方案

#1


2  

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

這已在PyClipper版本1.0.2中修復,這比使用下面描述的解決方法更好

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.

好的,我已將問題追溯到存儲在Polygon中的值。問題是值0由SymPy存儲為sympy.Zero。

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

polyclipper.scale_to_clipper()不接受這些sympy.Zero值,因此在選中時會引發TypeError。

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

為了避免這個問題,我可以生成new_list cast pt.x和pt.y到float:

new_list = [(float(pt.x), float(pt.y)) for pt in as_poly.vertices]

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/08/16/729ec4a5293b1e8c3b08044e6badd8ea.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com