Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.assertTrue(np.array_equal(expected_tf_rotation, tf_rotation))
# Try a test with no offset specified
self.assertTrue(np.array_equal(
construct_rotation_tf(50, 0, 0),
svgpathtools.parser.parse_transform('rotate(50)')
))
expected_tf_skewx = np.identity(3)
expected_tf_skewx[0, 1] = np.tan(40.0 * np.pi/180.0)
tf_skewx = svgpathtools.parser.parse_transform('skewX(40)')
self.assertTrue(np.array_equal(expected_tf_skewx, tf_skewx))
expected_tf_skewy = np.identity(3)
expected_tf_skewy[1, 0] = np.tan(30.0 * np.pi / 180.0)
tf_skewy = svgpathtools.parser.parse_transform('skewY(30)')
self.assertTrue(np.array_equal(expected_tf_skewy, tf_skewy))
self.assertTrue(np.array_equal(
tf_rotation.dot(tf_translate).dot(tf_skewx).dot(tf_scale),
svgpathtools.parser.parse_transform(
"""rotate(-10 50 100)
translate(-36 45.5)
tf_scale = svgpathtools.parser.parse_transform('scale(10 0.5)')
self.assertTrue(np.array_equal(expected_tf_scale, tf_scale))
tf_rotation = svgpathtools.parser.parse_transform('rotate(-10 50 100)')
expected_tf_rotation = construct_rotation_tf(-10, 50, 100)
self.assertTrue(np.array_equal(expected_tf_rotation, tf_rotation))
# Try a test with no offset specified
self.assertTrue(np.array_equal(
construct_rotation_tf(50, 0, 0),
svgpathtools.parser.parse_transform('rotate(50)')
))
expected_tf_skewx = np.identity(3)
expected_tf_skewx[0, 1] = np.tan(40.0 * np.pi/180.0)
tf_skewx = svgpathtools.parser.parse_transform('skewX(40)')
self.assertTrue(np.array_equal(expected_tf_skewx, tf_skewx))
expected_tf_skewy = np.identity(3)
expected_tf_skewy[1, 0] = np.tan(30.0 * np.pi / 180.0)
tf_skewy = svgpathtools.parser.parse_transform('skewY(30)')
self.assertTrue(np.array_equal(expected_tf_skewy, tf_skewy))
self.assertTrue(np.array_equal(
tf_rotation.dot(tf_translate).dot(tf_skewx).dot(tf_scale),
svgpathtools.parser.parse_transform(
"""rotate(-10 50 100)
translate(-36 45.5)
svgpathtools.parser.parse_transform('translate(-36)')
))
# Now specify y
expected_tf_translate[1, 2] = 45.5
tf_translate = svgpathtools.parser.parse_transform(
'translate(-36 45.5)')
self.assertTrue(np.array_equal(expected_tf_translate, tf_translate))
# Try a test with no y specified
expected_tf_scale = np.identity(3)
expected_tf_scale[0, 0] = 10
expected_tf_scale[1, 1] = 10
self.assertTrue(np.array_equal(
expected_tf_scale,
svgpathtools.parser.parse_transform('scale(10)')
))
# Now specify y
expected_tf_scale[1, 1] = 0.5
tf_scale = svgpathtools.parser.parse_transform('scale(10 0.5)')
self.assertTrue(np.array_equal(expected_tf_scale, tf_scale))
tf_rotation = svgpathtools.parser.parse_transform('rotate(-10 50 100)')
expected_tf_rotation = construct_rotation_tf(-10, 50, 100)
self.assertTrue(np.array_equal(expected_tf_rotation, tf_rotation))
# Try a test with no offset specified
self.assertTrue(np.array_equal(
construct_rotation_tf(50, 0, 0),
svgpathtools.parser.parse_transform('rotate(50)')
))
tf_translate = svgpathtools.parser.parse_transform(
'translate(-36 45.5)')
self.assertTrue(np.array_equal(expected_tf_translate, tf_translate))
# Try a test with no y specified
expected_tf_scale = np.identity(3)
expected_tf_scale[0, 0] = 10
expected_tf_scale[1, 1] = 10
self.assertTrue(np.array_equal(
expected_tf_scale,
svgpathtools.parser.parse_transform('scale(10)')
))
# Now specify y
expected_tf_scale[1, 1] = 0.5
tf_scale = svgpathtools.parser.parse_transform('scale(10 0.5)')
self.assertTrue(np.array_equal(expected_tf_scale, tf_scale))
tf_rotation = svgpathtools.parser.parse_transform('rotate(-10 50 100)')
expected_tf_rotation = construct_rotation_tf(-10, 50, 100)
self.assertTrue(np.array_equal(expected_tf_rotation, tf_rotation))
# Try a test with no offset specified
self.assertTrue(np.array_equal(
construct_rotation_tf(50, 0, 0),
svgpathtools.parser.parse_transform('rotate(50)')
))
expected_tf_skewx = np.identity(3)
expected_tf_skewx[0, 1] = np.tan(40.0 * np.pi/180.0)
tf_skewx = svgpathtools.parser.parse_transform('skewX(40)')
self.assertTrue(np.array_equal(expected_tf_skewx, tf_skewx))
def test_transform(self):
tf_matrix = svgpathtools.parser.parse_transform(
'matrix(1.0 2.0 3.0 4.0 5.0 6.0)')
expected_tf_matrix = np.identity(3)
expected_tf_matrix[0:2, 0:3] = np.array([[1.0, 3.0, 5.0],
[2.0, 4.0, 6.0]])
self.assertTrue(np.array_equal(expected_tf_matrix, tf_matrix))
# Try a test with no y specified
expected_tf_translate = np.identity(3)
expected_tf_translate[0, 2] = -36
self.assertTrue(np.array_equal(
expected_tf_translate,
svgpathtools.parser.parse_transform('translate(-36)')
))
# Now specify y
expected_tf_translate[1, 2] = 45.5
expected_tf_matrix = np.identity(3)
expected_tf_matrix[0:2, 0:3] = np.array([[1.0, 3.0, 5.0],
[2.0, 4.0, 6.0]])
self.assertTrue(np.array_equal(expected_tf_matrix, tf_matrix))
# Try a test with no y specified
expected_tf_translate = np.identity(3)
expected_tf_translate[0, 2] = -36
self.assertTrue(np.array_equal(
expected_tf_translate,
svgpathtools.parser.parse_transform('translate(-36)')
))
# Now specify y
expected_tf_translate[1, 2] = 45.5
tf_translate = svgpathtools.parser.parse_transform(
'translate(-36 45.5)')
self.assertTrue(np.array_equal(expected_tf_translate, tf_translate))
# Try a test with no y specified
expected_tf_scale = np.identity(3)
expected_tf_scale[0, 0] = 10
expected_tf_scale[1, 1] = 10
self.assertTrue(np.array_equal(
expected_tf_scale,
svgpathtools.parser.parse_transform('scale(10)')
))
# Now specify y
expected_tf_scale[1, 1] = 0.5
tf_scale = svgpathtools.parser.parse_transform('scale(10 0.5)')
self.assertTrue(np.array_equal(expected_tf_scale, tf_scale))
FlattenedPath = collections.namedtuple('FlattenedPath',
['path', 'element', 'transform'])
paths = []
while stack:
top = stack.pop()
# For each element type that we know how to convert into path
# data, parse the element after confirming that the path_filter
# accepts it.
for key, converter in path_conversions.items():
for path_elem in filter(path_filter, top.group.iterfind(
'svg:'+key, SVG_NAMESPACE)):
path_tf = top.transform.dot(
parse_transform(path_elem.get('transform')))
path = transform(parse_path(converter(path_elem)), path_tf)
paths.append(FlattenedPath(path, path_elem, path_tf))
stack.extend(get_relevant_children(top.group, top.transform))
return paths
def new_stack_element(element, last_tf):
return StackElement(element, last_tf.dot(
parse_transform(element.get('transform'))))