Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can only concatenate tuple (not "complex") to tuple #228

Open
remibert opened this issue Oct 11, 2024 · 0 comments
Open

Can only concatenate tuple (not "complex") to tuple #228

remibert opened this issue Oct 11, 2024 · 0 comments

Comments

@remibert
Copy link

With some svg I have this error :
File "B:\berialdraw\scripts\svg2icn.py", line 288, in
icn.parse()
File "B:\berialdraw\scripts\svg2icn.py", line 15, in parse
new_paths = self.move_paths_to_origin(converted_paths, self.x, self.y)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "B:\berialdraw\scripts\svg2icn.py", line 209, in move_paths_to_origin
return [
^
File "B:\berialdraw\scripts\svg2icn.py", line 210, in
path.translated(complex(-x, -y))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "X:\Portable\python311\Lib\site-packages\svgpathtools\path.py", line 3119, in translated
return translate(self, z0)
^^^^^^^^^^^^^^^^^^^
File "X:\Portable\python311\Lib\site-packages\svgpathtools\path.py", line 234, in translate
return transform_segments_together(curve, transformation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "X:\Portable\python311\Lib\site-packages\svgpathtools\path.py", line 191, in transform_segments_together
transformed_segs = [transformation(seg) for seg in path]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "X:\Portable\python311\Lib\site-packages\svgpathtools\path.py", line 191, in
transformed_segs = [transformation(seg) for seg in path]
^^^^^^^^^^^^^^^^^^^
File "X:\Portable\python311\Lib\site-packages\svgpathtools\path.py", line 233, in
transformation = lambda seg: translate(seg, z0)
^^^^^^^^^^^^^^^^^^
File "X:\Portable\python311\Lib\site-packages\svgpathtools\path.py", line 236, in translate
return bpoints2bezier([bpt + z0 for bpt in curve.bpoints()])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "X:\Portable\python311\Lib\site-packages\svgpathtools\path.py", line 236, in
return bpoints2bezier([bpt + z0 for bpt in curve.bpoints()])
~~~~^~~~
TypeError: can only concatenate tuple (not "complex") to tuple

I fixed with this modification:
def translate(curve, z0):
"""Shifts the curve by the complex quantity z such that
translate(curve, z0).point(t) = curve.point(t) + z0"""
if isinstance(curve, Path):
transformation = lambda seg: translate(seg, z0)
return transform_segments_together(curve, transformation)
elif is_bezier_segment(curve):
lst = []
for bpt in curve.bpoints():
if type(bpt) == type((0,0)):
bpt = complex(*bpt)
lst.append(bpt + z0)
return bpoints2bezier(lst)
elif isinstance(curve, Arc):
new_start = curve.start + z0
new_end = curve.end + z0
return Arc(new_start, radius=curve.radius, rotation=curve.rotation,
large_arc=curve.large_arc, sweep=curve.sweep, end=new_end)
else:
raise TypeError("Input curve should be a Path, Line, "
"QuadraticBezier, CubicBezier, or Arc object.")

The svg file which produce this error :
icone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant