deeplook / svglib

Read SVG files and convert them to other formats.
GNU Lesser General Public License v3.0
322 stars 79 forks source link

ZeroDivisionError, trying to get a path's length. #242

Closed ilovetogetspamed closed 4 years ago

ilovetogetspamed commented 4 years ago

macOS Mojave 10.14.6 (18G4032) Python 3.7.5 (v3.7.5:5c02a39a0b, Oct 14 2019, 18:49:57) [Clang 6.0 (clang-600.0.57)] on darwin

svgpathtools==1.3.3

{'id': 'path16', 'style': 'fill:none;stroke:#000000;stroke-width:0.34999999;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1', 'd': 'm 5162.8,3077.9 v 0'}
Traceback (most recent call last):
  File "/tmp/image_files_4/fill_svg.py", line 16, in <module>
    plength = paths[n].length()
  File "/Library/Python/3.7/lib/python/site-packages/svgpathtools/path.py", line 1870, in length
    self._calc_lengths(error=error, min_depth=min_depth)
  File "/Library/Python/3.7/lib/python/site-packages/svgpathtools/path.py", line 1847, in _calc_lengths
    self._lengths = [each/self._length for each in lengths]
  File "/Library/Python/3.7/lib/python/site-packages/svgpathtools/path.py", line 1847, in <listcomp>
    self._lengths = [each/self._length for each in lengths]
ZeroDivisionError: float division by zero

Process finished with exit code 1
# Read SVG into a list of path objects and list of dictionaries of attributes
from svgpathtools import svg2paths
paths, attributes = svg2paths('Panel Wall Scenes 9.svg')

# create svgpathtools Path objects from an SVG file
mypaths = dict()

for n in range(len(paths)):
    print(attributes[n])
    # Let's find its length
    plength = paths[n].length()
    pid = attributes[n]['id']
    # print(f"id: {pid} length = {length}")
    vid = {plength: pid}
    mypaths.update(vid)

    # Find height, width
    xmin, xmax, ymin, ymax = paths[n].bbox()
    pwidth = xmax - xmin
    pheight = ymax - ymin

    print(f"ID: {pid} length = {plength} width = {pwidth} height = {pheight}")

My code works fine with similar svg files. Thanks in advance.

claudep commented 4 years ago

I guess you reported your bug on the wrong module. This is svglib not https://github.com/mathandy/svgpathtools

ilovetogetspamed commented 4 years ago

Woops. Long day. Sorry!

On Apr 23, 2020, at 5:09 PM, Claude Paroz notifications@github.com wrote:

I guess you reported your bug on the wrong module. This is svglib not https://github.com/mathandy/svgpathtools https://github.com/mathandy/svgpathtools — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/deeplook/svglib/issues/242#issuecomment-618672383, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAY5THEMB5X325EK4J3DMY3ROCVAVANCNFSM4MPMTL7Q.