renamed Document.flatten_all_paths to flattened_paths

pull/114/head
Andy Port 2020-06-23 20:53:54 -07:00
parent d673176347
commit 445899b2eb
2 changed files with 8 additions and 9 deletions

View File

@ -15,7 +15,7 @@ Example:
>> from svgpathtools import * >> from svgpathtools import *
>> doc = Document('my_file.html') >> doc = Document('my_file.html')
>> for path in doc.flatten_all_paths(): >> for path in doc.flattened_paths():
>> # Do something with the transformed Path object. >> # Do something with the transformed Path object.
>> foo(path) >> foo(path)
>> # Inspect the raw SVG element, e.g. change its attributes >> # Inspect the raw SVG element, e.g. change its attributes
@ -196,7 +196,7 @@ def flatten_group(group_to_flatten, root, recursive=True,
for group in route: for group in route:
# Add each group from the root to the parent of the desired group # Add each group from the root to the parent of the desired group
# to the list of groups that we should traverse. This makes sure # to the list of groups that we should traverse. This makes sure
# that flatten_all_paths will not stop before reaching the desired # that flattened_paths will not stop before reaching the desired
# group. # group.
desired_groups.add(id(group)) desired_groups.add(id(group))
for key in path_conversions.keys(): for key in path_conversions.keys():
@ -249,11 +249,10 @@ class Document:
self.root = self.tree.getroot() self.root = self.tree.getroot()
def flatten_all_paths(self, group_filter=lambda x: True, def flattened_paths(self, group_filter=lambda x: True,
path_filter=lambda x: True, path_filter=lambda x: True, path_conversions=CONVERSIONS):
path_conversions=CONVERSIONS):
"""Forward the tree of this document into the more general """Forward the tree of this document into the more general
flatten_all_paths function and return the result.""" flattened_paths function and return the result."""
return flatten_all_paths(self.tree.getroot(), group_filter, return flatten_all_paths(self.tree.getroot(), group_filter,
path_filter, path_conversions) path_filter, path_conversions)

View File

@ -26,7 +26,7 @@ class TestGroups(unittest.TestCase):
# end point relative to the start point # end point relative to the start point
# * name is the path name (value of the test:name attribute in # * name is the path name (value of the test:name attribute in
# the SVG document) # the SVG document)
# * paths is the output of doc.flatten_all_paths() # * paths is the output of doc.flattened_paths()
v_s_vals.append(1.0) v_s_vals.append(1.0)
v_e_relative_vals.append(0.0) v_e_relative_vals.append(0.0)
v_s = np.array(v_s_vals) v_s = np.array(v_s_vals)
@ -38,7 +38,7 @@ class TestGroups(unittest.TestCase):
self.check_values(tf.dot(v_e), actual.path.end) self.check_values(tf.dot(v_e), actual.path.end)
def test_group_flatten(self): def test_group_flatten(self):
# Test the Document.flatten_all_paths() function against the # Test the Document.flattened_paths() function against the
# groups.svg test file. # groups.svg test file.
# There are 12 paths in that file, with various levels of being # There are 12 paths in that file, with various levels of being
# nested inside of group transforms. # nested inside of group transforms.
@ -48,7 +48,7 @@ class TestGroups(unittest.TestCase):
# that are specified by the SVG standard. # that are specified by the SVG standard.
doc = Document(join(dirname(__file__), 'groups.svg')) doc = Document(join(dirname(__file__), 'groups.svg'))
result = doc.flatten_all_paths() result = doc.flattened_paths()
self.assertEqual(12, len(result)) self.assertEqual(12, len(result))
tf_matrix_group = np.array([[1.5, 0.0, -40.0], tf_matrix_group = np.array([[1.5, 0.0, -40.0],