From ff96a37d16c415a14f42908b8ff05e3855cbd233 Mon Sep 17 00:00:00 2001 From: "Michael X. Grey" Date: Fri, 25 May 2018 16:50:40 +0800 Subject: [PATCH] Add a test for elements that contain a 'transform' attribute --- test/groups.svg | 8 ++++++++ test/test_groups.py | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/test/groups.svg b/test/groups.svg index 804a6b8..1787617 100644 --- a/test/groups.svg +++ b/test/groups.svg @@ -146,6 +146,14 @@ stroke-width="3" test:name="path10"/> + + diff --git a/test/test_groups.py b/test/test_groups.py index 672e0fa..c3a1aef 100644 --- a/test/test_groups.py +++ b/test/test_groups.py @@ -42,10 +42,13 @@ class TestGroups(unittest.TestCase): def test_group_flatten(self): # Test the Document.flatten_all_paths() function against the groups.svg test file. + # There are 12 paths in that file, with various levels of being nested inside of group transforms. + # The check_line function is used to reduce the boilerplate, since all the tests are very similar. + # This test covers each of the different types of transforms that are specified by the SVG standard. doc = Document(join(dirname(__file__), 'groups.svg')) result = doc.flatten_all_paths() - self.assertEqual(11, len(result)) + self.assertEqual(12, len(result)) tf_matrix_group = np.matrix([[1.5, 0.0, -40.0], [0.0, 0.5, 20.0], [0.0, 0.0, 1.0]]) @@ -119,4 +122,14 @@ class TestGroups(unittest.TestCase): [183, 183], [40, 40], 'path10', result) - # TODO: Add a test where a path element has a transform attribute + # This last test is for handling transforms that are defined as attributes of a element. + a_11 = -40*np.pi/180.0 + tf_path11_R = np.matrix([[np.cos(a_11), -np.sin(a_11), 0], + [np.sin(a_11), np.cos(a_11), 0], + [0, 0, 1]]) + tf_path11_T = np.matrix([[1, 0, 100], [0, 1, 100], [0, 0, 1]]) + tf_path11 = tf_path11_T.dot(tf_path11_R).dot(np.linalg.inv(tf_path11_T)) + + self.check_line(tf_matrix_group.dot(tf_skew_y_group).dot(tf_path11), + [180, 20], [-70, 80], + 'path11', result)