Skip to content

Commit

Permalink
Merge pull request #199 from mathandy/issue-198
Browse files Browse the repository at this point in the history
Issue 198
  • Loading branch information
mathandy authored Apr 1, 2023
2 parents 9c69e45 + 4f5d8f3 commit 5c73056
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion svgpathtools/svg_to_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def ellipse2pathd(ellipse):
d += 'a' + str(rx) + ',' + str(ry) + ' 0 1,0 ' + str(2 * rx) + ',0'
d += 'a' + str(rx) + ',' + str(ry) + ' 0 1,0 ' + str(-2 * rx) + ',0'

return d
return d + 'z'


def polyline2pathd(polyline, is_polygon=False):
Expand Down
27 changes: 27 additions & 0 deletions test/test_svg2paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
from svgpathtools import Path, Line, Arc, svg2paths, svgstr2paths
from io import StringIO
from io import open # overrides build-in open for compatibility with python2
import os
from os.path import join, dirname
from sys import version_info
import tempfile
import shutil

from svgpathtools.svg_to_paths import rect2pathd

Expand Down Expand Up @@ -57,6 +60,26 @@ def test_svg2paths_ellipses(self):
self.assertTrue(path_circle==path_circle_correct)
self.assertTrue(path_circle.isclosed())

# test for issue #198 (circles not being closed)
svg = u"""<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" width="40mm" height="40mm"
viewBox="0 0 40 40" version="1.1">
<g id="layer">
<circle id="c1" cx="20.000" cy="20.000" r="11.000" />
<circle id="c2" cx="20.000" cy="20.000" r="5.15" />
</g>
</svg>"""
tmpdir = tempfile.mkdtemp()
svgfile = os.path.join(tmpdir, 'test.svg')
with open(svgfile, 'w') as f:
f.write(svg)
paths, _ = svg2paths(svgfile)
self.assertEqual(len(paths), 2)
self.assertTrue(paths[0].isclosed())
self.assertTrue(paths[1].isclosed())
shutil.rmtree(tmpdir)

def test_rect2pathd(self):
non_rounded = {"x":"10", "y":"10", "width":"100","height":"100"}
self.assertEqual(rect2pathd(non_rounded), 'M10.0 10.0 L 110.0 10.0 L 110.0 110.0 L 10.0 110.0 z')
Expand Down Expand Up @@ -107,3 +130,7 @@ def test_from_string(self):
paths, _ = svgstr2paths(file_content)

self.assertEqual(len(paths), 2)


if __name__ == '__main__':
unittest.main()

0 comments on commit 5c73056

Please sign in to comment.