Skip to content

Commit

Permalink
add a test loading arcs with negative scale
Browse files Browse the repository at this point in the history
This test currently fails, fix in the following commit.

The test loads an svg with a group with a transform with "scale(1,-1)".
This situation can mess up arc sweeps, resulting in corrupted paths.
  • Loading branch information
SebKuzminsky committed May 5, 2023
1 parent 5c73056 commit 6abda09
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
19 changes: 19 additions & 0 deletions test/negative-scale.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion test/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
"""
from __future__ import division, absolute_import, print_function
import unittest
from svgpathtools import Document, SVG_NAMESPACE, parse_path
from svgpathtools import Document, SVG_NAMESPACE, parse_path, Line, Arc
from os.path import join, dirname
import numpy as np


# When an assert fails, show the full error message, don't truncate it.
unittest.util._MAX_LENGTH = 999999999


def get_desired_path(name, paths):
return next(p for p in paths
if p.element.get('{some://testuri}name') == name)
Expand Down Expand Up @@ -42,6 +46,22 @@ def check_line(self, tf, v_s_vals, v_e_relative_vals, name, paths):
self.check_values(tf.dot(v_s), actual.start)
self.check_values(tf.dot(v_e), actual.end)

def test_group_transform(self):
# The input svg has a group transform of "scale(1,-1)", which
# can mess with Arc sweeps.
doc = Document(join(dirname(__file__), 'negative-scale.svg'))
path = doc.paths()[0]
self.assertEqual(path[0], Line(start=-10j, end=-80j))
self.assertEqual(path[1], Arc(start=-80j, radius=(30+30j), rotation=0.0, large_arc=True, sweep=True, end=-140j))
self.assertEqual(path[2], Arc(start=-140j, radius=(20+20j), rotation=0.0, large_arc=False, sweep=False, end=-100j))
self.assertEqual(path[3], Line(start=-100j, end=(100-100j)))
self.assertEqual(path[4], Arc(start=(100-100j), radius=(20+20j), rotation=0.0, large_arc=True, sweep=False, end=(100-140j)))
self.assertEqual(path[5], Arc(start=(100-140j), radius=(30+30j), rotation=0.0, large_arc=False, sweep=True, end=(100-80j)))
self.assertEqual(path[6], Line(start=(100-80j), end=(100-10j)))
self.assertEqual(path[7], Arc(start=(100-10j), radius=(10+10j), rotation=0.0, large_arc=False, sweep=True, end=(90+0j)))
self.assertEqual(path[8], Line(start=(90+0j), end=(10+0j)))
self.assertEqual(path[9], Arc(start=(10+0j), radius=(10+10j), rotation=0.0, large_arc=False, sweep=True, end=-10j))

def test_group_flatten(self):
# Test the Document.paths() function against the
# groups.svg test file.
Expand Down

0 comments on commit 6abda09

Please sign in to comment.